如何解决如何从CloudFormation模板中的同一AWS角色承担AWS角色?
我正在使用IAM角色进行粘合工作以进行一些数据处理,要完成此任务,我需要承担执行粘合角色的角色。
例如,在以下cloudformation模板中,IAM::Policy
有权从Dynamo数据库表中进行查询并从s3存储桶中获取对象。
AWstemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
glueAccesspolicy:
Type: AWS::IAM::Policy
Properties:
Roles:
- !Ref glueRole
PolicyName: glue_access_policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: 's3:getobject'
Resource:
- 's3_bucket_arn'
- Effect: Allow
Action:
- 'dynamodb:DescribeTable'
- 'dynamodb:Query'
Resource:
- 'dynamo_table_arn'
glueRole:
Type: 'AWS::IAM::Role'
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSglueServiceRole
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: 'Allow'
Principal:
Service:
- 'glue.amazonaws.com'
Action:
- 'sts:AssumeRole'
现在,此question说明了一个示例,该角色假定角色B由角色A转换角色。
所以,我有一个问题, glueRole
承担glueRole
是否可能或有效?
解决方法
由于角色本身没有限制,docs声明以下内容
授予用户担任角色权限的策略必须包含对以下内容具有“允许”作用的语句:
- sts:AssumeRole动作
- 资源元素中角色的Amazon资源名称(ARN)
直接将此策略添加到CloudFormation模板上的AWS::IAM::Policy
资源中即可。
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
GlueAccessPolicy:
Type: AWS::IAM::Policy
Properties:
Roles:
- !Ref GlueRole
PolicyName: glue_access_policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: 'sts:AssumeRole'
Resource: !GetAtt GlueRole.Arn
GlueRole:
Type: 'AWS::IAM::Role'
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: 'Allow'
Principal:
Service:
- 'glue.amazonaws.com'
Action:
- 'sts:AssumeRole'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。