amazon-web-services - 连接到 S3 存储桶时如何保护 AWS 中的凭证

标签 amazon-web-services amazon-s3 key credentials

抱歉,如果这个问题太简单了。我不久前开始学习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.

IAM Roles for Amazon EC2

同样,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 Lambda Permissions

如果您的程序不打算在AWS环境中执行,那么您可以使用AWS SDK来编程以访问AWS服务。例如,Node SDK 将通过以下方式查找凭据:

  1. 通过服务客户端构造函数显式设置的凭据
  2. 环境变量
  3. 共享凭据文件

您肯定会尝试避免第一个方法,以便可以将凭据作为其他方法之一传递。

Setting Credentials in Node.js

Working with AWS Credentials : Java

关于amazon-web-services - 连接到 S3 存储桶时如何保护 AWS 中的凭证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59042169/

相关文章:

java - Map<String, String>,如何同时打印 "key string"和 "value string"

amazon-web-services - 如何在 Elastic Beanstalk 上自定义 docker run 命令?

laravel - 无法使用 laravel 5.7 在 s3 存储桶中上传文件 - 参数 1 传递给 League\Flysystem\AwsS3v3\AwsS3Adapter :

node.js - 如何使用 Knox 将文件从 NodeJS 流式传输到 Amazon S3?

amazon-web-services - Cloudfront s3 分发中的有序缓存导致访问被拒绝 (403)

javascript - 如何获取 var 中的字符串作为 javascript/node 中的 obj 键?

ruby-on-rails - 使用 AWS Cloudfront 异步加载 Google map

amazon-web-services - 我需要备份 AWS EBS 数据吗?

python - 亚马逊广告 API ItemSearch : Get more than 10 pages/100 results?

python - 如果字典的键位于卡住集中,则检索值