简体   繁体   English

AWS Glue 与 SecretManager 用于数据库凭证

[英]AWS Glue with SecretManager for database credentials

I am having a AWS Glue Python script which I am using for connecting to an Aurora Mysql database.我有一个用于连接 Aurora Mysql 数据库的 AWS Glue Python 脚本。 For this, I tried to use AWS SecretManager so that I do not have to hardcode the database credentials in the script.为此,我尝试使用 AWS SecretManager,这样我就不必在脚本中硬编码数据库凭证。

While I am able to successfully use secretmanager and use it in my AWS Glue script to connect to RDS, I see that the credentials are not secret, and if I print the contents of a variable holding the database credentials, I am able to see the passwords, username, etc. in the cloudwatch logs.虽然我能够成功使用 secretmanager 并在我的 AWS Glue 脚本中使用它来连接到 RDS,但我看到凭证不是秘密的,如果我打印包含数据库凭证的变量的内容,我可以看到cloudwatch 日志中的密码、用户名等。

Please find herewith the code snippet:请在此处找到代码片段:

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

get_secret_value_response = client.get_secret_value(
        SecretId="RDS_Dev_Cluster"
)

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

db_username = secret.get('username')
db_password = secret.get('password')
db_url = secret.get('host')

print db_username
print db_password
print db_url

Is there any way we can encrypt the username/password credentials.有什么方法可以加密用户名/密码凭据。 Can we use AWS KMS?我们可以使用 AWS KMS 吗? I haven't tried KMS in this, but would like to get suggestions before using another AWS service.我没有在这方面尝试过 KMS,但想在使用其他 AWS 服务之前获得建议。 If not, how can we mask the database credentials besides secretmanager.如果没有,除了secretmanager,我们如何屏蔽数据库凭证。

Thanks谢谢

The AWS docs states that AWS Secret Manager always stores the keys encrypted it normally deals with the decryption transparently. AWS 文档指出 AWS Secret Manager 始终存储加密的密钥,它通常透明地处理解密。 When you specify the KMS key that AWS Secret Manager should use.当您指定 AWS Secret Manager 应使用的 KMS 密钥时。 transparently decrypts and returns them to you in plaintext 透明地解密并以明文形式返回给您

So basically you are seeing the decrypted result just minus the call you would have to make the the KMS API to decrypt.所以基本上你看到的解密结果只是减去你必须让 KMS API 解密的调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM