背景:
我试图授予帐户B中的ECS任务访问权限,以便从帐户A中的DynamoDB表中提取数据。
理论上,这可以通过以下方式工作:(1)在帐户A中创建一个角色,允许帐户B假设(具有配对的外部ID),然后(2)授予该角色对所需的DynamoDB表的访问权限。
问题:
当ECS中运行的进程承担ECS角色(帐户B)时,它会创建该角色的唯一实例,该角色显然不能成为帐户中主体语句的目标。如果我尝试授予对底层角色的访问权限,这显然不会产生任何影响。
我是否可以强制ECS使用原始角色,我可以授予它作为主体,而不是一个临时集合,显然不能承担其他角色?
我能想到的唯一解决办法是创建一个具有编程API凭据的新用户,将这些create切换到ECS任务,然后让ECS任务用属于AWS密钥对的角色覆盖它自己的角色。不过,据我所知,这无疑是反模式的,而且也暴露了这些凭据被破坏的风险。
有没有办法做到这一点,而不求助于手动创建的用户和手动传递的AWS?
更多信息:
我可以授予这个主体arn:aws:sts::AcctB****:assumed-role/myrole/45716b8c-40c8-4ca7-b346-1ff4ee94eb53
.
An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:sts::AcctB****:assumed-role/myrole/45716b8c-40c8-4ca7-b346-1ff4ee94eb53 is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::AcctA****:role/ExternalRole
的
An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:sts::AcctB****:assumed-role/myrole/45716b8c-40c8-4ca7-b346-1ff4ee94eb53 is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::AcctA****:role/ExternalRole
发布于 2020-10-14 02:36:15
我也遇到了同样的情况,并找到了一种安全的方法来以编程方式承担ECS任务中的角色。
sts_client = boto3.client('sts')
identity = sts_client.get_caller_identity()
print(identity) # identity in account A
response = sts_client.assume_role(RoleArn=assume_role_arn, RoleSessionName=session_name)
session = boto3.Session(aws_access_key_id=response['Credentials']['AccessKeyId'],
aws_secret_access_key=response['Credentials']['SecretAccessKey'],
aws_session_token=response['Credentials']['SessionToken'])
其想法是连接到帐户A,从帐户B中承担角色,在一个会话中使用临时凭据,然后从该会话中插入您需要的任何客户端。
external_client = session.client('sts')
identity = external_client.get_caller_identity()
print(identity) # identity in account B
这比创建IAM用户和在帐户间共享凭据更安全,因为身份验证是在内部完成的。
在这里,您可以找到关于它如何工作的更多信息https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sts.html。
发布于 2021-03-12 01:58:22
在这里链接以下主题:How to assume an AWS role from another AWS role?
TL;博士
确实要确保在其中一个策略中没有错误、名称错误或外部id。
ECS需要承担您的任务角色,就像您试图在Account B中承担角色一样。即使是ECS也试图在assumed-role/...
中承担帐户B的角色,当授予role/...
主体时,它也会按预期工作。
https://stackoverflow.com/questions/63694971
复制相似问题