AWS Cloudformation - CodeCommit - 拒绝推送到 Master
所以情况是这样的: 我有一个 Cloudformation,它创建 CodeCommit 存储库,其中包含一些额外的资源,以便其他 DevOps 流程正常工作。
我收到了阻止用户推送到特定分支的要求,在本例中为 master,我找到了执行此操作的策略。来源:https://docs.aws。 amazon.com/codecommit/latest/userguide/how-to-conditional-branch.html
因此,我编写了一个角色和策略,内容如下:
Resources:
CodeCommitRepository:
Type: AWS::CodeCommit::Repository
Properties:
RepositoryName: !Sub '${ProjectCode}-${ProjectName}-${ComponentName}'
RepositoryDescription: !Ref CodeCommitRepositoryDescription
Tags:
- Key: fdr:general:project-code
Value: !Ref ProjectCode
- Key: fdr:general:project-name
Value: !Ref ProjectName
DenyPushRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub '${ProjectCode}-${ProjectName}-${ComponentName}-DenyPush-Role'
ManagedPolicyArns:
- !Ref DenyPushToMasterPolicy
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- codecommit.amazonaws.com
DenyPushToMasterPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: !Sub '${ProjectCode}-${ProjectName}-${ComponentName}-DenyPush-Policy'
Description: Policy to deny push to master
PolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- codecommit:GitPush
- codecommit:PutFile
- codecommit:DeleteBranch
- codecommit:MergePullRequestByFastForward
Effect: Deny
Resource: !GetAtt CodeCommitRepository.Arn
Condition:
StringEqualsIfExists:
codecommit:References:
- refs/heads/master
'Null':
codecommit:References: 'false'
据我了解,我不会说太多,通过创建角色与策略和 sts:AssumeRole 我认为使用该存储库的任何用户都会承担该角色,从而拒绝他们推送到 master 的能力,但事实并非如此。
我想我们可能会让事情变得过于复杂,我们应该将该策略直接应用于 IAM 上的所有用户,但我们的想法是让它做得非常精细。我做错了什么或者有可能吗?
此致
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DenyPushRole
不适合任何用户。您将其指定为仅适用于codecommit.amazonaws.com
,这是不正确。用户不会自动承担任何角色。他们必须使用 明确假设您的
DenyPushRole
="nofollow noreferrer">AssumeRole API 调用。您的用户还必须拥有sts:AssumeRole
权限。因此,您的角色,一般形式应该是:
一旦角色存在,并且用户有
sts:AssumeRole
来承担它,他们将使用AssumeRole
命令来实际执行承担这个角色。这将提供新的临时 AWS 凭证来执行该角色指定的任何操作。在您的情况下,角色仅否认,因此他们无论如何都无法执行任何操作。您需要向角色添加一些allow
语句,以便您的用户能够真正执行某些操作,而不仅仅是deny
。DenyPushRole
is not for any users. You specified it to be only forcodecommit.amazonaws.com
which is incorrect.Users do not automatically assume any roles. They have to explicitly assume your
DenyPushRole
using AssumeRole API call. Your users must also have permission tosts:AssumeRole
.Thus your role, in a general form, should be:
Once the role exist, and the users have
sts:AssumeRole
to assume it, they will use theAssumeRole
command to actually assume the role. This will give then new, temporary AWS credentials to perform any actions specified by the role. In your case, the role only denies, so they will not be able to do anything anyway. You would need to add someallow
statements to the role for your uses to be actually able to do something, not onlydeny
.