抱歉,如果这个问题太简单了。我不久前开始学习AWS:
据我所知,AWS允许创建IAM角色并授予所需的权限,例如访问S3存储桶。
如果我需要访问 S3 存储桶来检索所需的数据,我可能可以使用 ssh/winscp 来完成。
问题是如果我需要在程序中创建连接怎么办?如何防止 key 和 key secret 在程序中显示为纯文本?这样做的最佳实践是什么?
非常感谢。
最佳答案
Question is what about if I need to create a connection in a program? how do I protect the key and key secret from showing as plain text in a program? What is the best practice of doing that?
这取决于您的程序将在哪里执行。
如果您的程序在 AWS 环境(例如 EC2 实例或 Lambda)中运行,那么您可以使用推荐的 IAM 角色。 IAM 角色提供 AWS 服务对服务的访问。这是官方文档以了解更多信息:
We designed IAM roles so that your applications can securely make API requests from your instances, without requiring you to manage the security credentials that the applications use. Instead of creating and distributing your AWS credentials, you can delegate permission to make API requests using IAM roles.
同样,AWS Lambda 也有执行角色的概念。分配给 lambda 的角色消除了在代码中使用凭证来访问其他 AWS 服务的需要。
A Lambda function also has a policy, called an execution role, that grants it permission to access AWS services and resources.
如果您的程序不打算在AWS环境中执行,那么您可以使用AWS SDK来编程以访问AWS服务。例如,Node SDK 将通过以下方式查找凭据:
- 通过服务客户端构造函数显式设置的凭据
- 环境变量
- 共享凭据文件
您肯定会尝试避免第一个方法,以便可以将凭据作为其他方法之一传递。
关于amazon-web-services - 连接到 S3 存储桶时如何保护 AWS 中的凭证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59042169/