gpt4 book ai didi

amazon-web-services - 在 AWS 中担任角色时 RoleSessionName 的用例是什么以及它如何影响性能

转载 作者:行者123 更新时间:2023-12-04 00:58:01 29 4
gpt4 key购买 nike

我有一个场景,我想从 AWS 中的其他账户访问一个账户的资源(跨账户访问)。我想在作为 lambda 函数和 EC2 上长时间运行的代码实现的代码 (NodeJs) 中实现这种访问。

阅读如何在线执行此操作,我知道我需要由 aws.STS 生成的临时凭据| , 像这样:

const AWS = require('aws-sdk');

const sts = new AWS.STS();
const stsResults = await sts.assumeRole({
RoleArn: 'arn:aws:iam::111111111111:role/role_name',
RoleSessionName: 'STRING_VALUE',
}).promise();

const dynamodb = new AWS.DynamoDB({
region: 'us-east-1',
accessKeyId: stsResults.Credentials.AccessKeyId,
secretAccessKey:stsResults.Credentials.SecretAccessKey,
sessionToken: stsResults.Credentials.SessionToken
});

这是执行此操作所需的最低限度。

我的问题是关于 RoleSessionName属性,这是一个必需的属性。我很难理解它的作用以及我应该如何使用它。这是什么 the AWS documentation不得不说:

RoleSessionName — (String) An identifier for the assumed role session.

Use the role session name to uniquely identify a session when the same role is assumed by different principals or for different reasons. In cross-account scenarios, the role session name is visible to, and can be logged by the account that owns the role. The role session name is also used in the ARN of the assumed role principal. This means that subsequent cross-account API requests that use the temporary security credentials will expose the role session name to the external account in their AWS CloudTrail logs.

The regex used to validate this parameter is a string of characters consisting of upper- and lower-case alphanumeric characters with no spaces. You can also include underscores or any of the following characters: =,.@-



就我个人而言,我并不担心安全性,因为两个帐户都归同一家公司所有,拥有多个帐户的唯一原因是在逻辑上分离资源。我想知道的是这个属性对 assumeRole性能的影响函数调用。我应该使用相同的 RoleSessionName对于我所有的 lambda 函数?这会导致在内部使用缓存吗?每次创建新 session 时是否应该创建一个随机 ID?

最佳答案

根据您引用的文档:

Use the role session name to uniquely identify a session when the same role is assumed by different principals or for different reasons.



假设您有一个 IAM 角色并且它由程序承担。这将返回一组可用于访问 AWS 服务的临时凭证。

在审计跟踪中,角色所做的任何事情都将被跟踪为角色所做的事情(而不是承担角色的实体)。这使得很难追溯这些 API 调用的来源,因为角色可能由“不同的主体或出于不同的原因”承担。例如,多个程序可能使用该角色。

为了帮助追踪此类请求的“来源”, RoleSessionName提供用于识别特定假设。它可以帮助您确定哪个应用程序正在使用凭据。

关于amazon-web-services - 在 AWS 中担任角色时 RoleSessionName 的用例是什么以及它如何影响性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60795503/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com