Trouble updating IAM to allow AWS Glue to the AWS Secrets Manager

倖福魔咒の 提交于 2020-07-10 09:56:07

问题


I am working on a project that requires that an AWS Glue Python script access the AWS Secrets Manager.

I tried giving Glue permissions to do this via IAM, but I don't see how; I can see the permissions strings showing that Lambda has access but I don't see a way to edit them.

I tried creating a new role that had the right permissions but when I went to attach it seemed to have disappeared ...

My fallback workaround is to grab the secret via a tiny Lambda and xfer it via S3 to Glue ... but this should be doable directly. Any help you can give is very welcome!


回答1:


You may need to add SecretsManagerReadWrite policy to the IAM Role that is associated with the AWS Glue. Please check, we are using secrets manager in our AWS Glue.

After adding the policy to the AWS Glue associated IAM Role, please add the following code snippet to read the credentials from the secret manager:

# Getting DB credentials from Secrets Manager
client = boto3.client("secretsmanager", region_name="us-west-2")

get_secret_value_response = client.get_secret_value(
        SecretId="mysecrets-info"   <--name as configured in secrets manager
)

secret = get_secret_value_response['SecretString']
secret = json.loads(secret)

uname = secret.get('username')
pwd = secret.get('password')
url = secret.get('host')

By the way you need to be an AWS admin user, to modify the IAM role. If you are a power user, please reach out the admin team for adding the policy to the IAM.




回答2:


The SecretsManagerReadWrite policy does not give permissions only to Lambda. I think you may be looking at the second statement which grants the Role permissions to create Lambdas (used to create Lambdas to rotate secrets).

Looking at the Glue blog post for setting up ETL jobs, they also say you should only need to add the SecretsManagerReadWrite policy to the Glue role. However, they also say that this is just for testing and you should use a policy that grants only the necessary permissions needed (e.g. use an inline policy that grants secretsmanager:GetSecretValue with Resource being the secret in question).

You don't actually say what error message you are seeing. That might be helpful in figuring out what is going wrong.



来源:https://stackoverflow.com/questions/61720927/trouble-updating-iam-to-allow-aws-glue-to-the-aws-secrets-manager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!