【问题标题】:Codepipeline S3 Bucket access denied in CodebuildCodebuild 中的 Codepipeline S3 存储桶访问被拒绝
【发布时间】:2020-12-31 00:28:05
【问题描述】:

背景:

我正在测试一个 Codepipeline,其中一个包含 Github 源的源阶段和一个包含 Codebuild 项目的测试阶段。 Github 源通过 Codestar 连接进行身份验证。

问题:

当通过管道触发 Codebuild 项目时,项目将被拒绝访问关联的 Codepipeline S3 工件存储桶。这是构建的日志:

AccessDenied: Access Denied
    status code: 403, request id: 123, host id: 1234
for primary source and source version arn:aws:s3:::my-bucket/foo/master/foo123

以下是与问题相关的 Codebuild 服务角色政策声明:

        {
            "Sid": "CodePipelineArtifactBucketAccess",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:ListObjects",
                "s3:ListBucket",
                "s3:GetObjectVersion",
                "s3:GetObject",
                "s3:GetBucketLocation"
            ],
            "Resource": "arn:aws:s3:::my-bucket/*"
        }

尝试:

1.

将上述策略中的资源属性从arn:aws:s3:::my-bucket/* 更改为arn:aws:s3:::my-bucket*。 (同样Access Denied错误)

2.

检查关联的工件存储桶的权限。目前,它设置为阻止所有公共访问,并且没有附加存储桶策略。存储桶的 ACL 设置为允许存储桶所有者(我)具有读/写访问权限。 (同样Access Denied 错误)

3.

鉴于这是一个测试管道,我尝试为 Codebuild 服务角色和 Codepipeline 服务角色提供对所有资源的完全 S3 访问权限。 (同样Access Denied 错误)

【问题讨论】:

  • 是否有拒绝访问的存储桶策略?
  • 不,没有拒绝访问的策略。该问题实际上与 CMK 策略的权限有关

标签: amazon-web-services amazon-iam aws-codepipeline


【解决方案1】:

将 Codebuild 角色 ARN 添加到 CMK 策略使用/授予相关权限就可以了。我想我盲目地假设 Codebuild 服务角色将继承 Codepipeline 的角色,这将使 Codebuild 项目能够解密与 Codepipeline 工件存储桶关联的 CMK。以下是我在 CMK 政策中更改的相关声明:

        {
            "Sid": "GrantPermissions",
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::111111111111:role/codebuild-role",
                    "arn:aws:iam::111111111111:role/codepipeline-role"
                ]
            },
            "Action": [
                "kms:RevokeGrant",
                "kms:ListGrants",
                "kms:CreateGrant"
            ],
            "Resource": "*",
            "Condition": {
                "Bool": {
                    "kms:GrantIsForAWSResource": "true"
                }
            }
        },
        {
            "Sid": "UsagePermissions",
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::111111111111:role/codebuild-role",
                    "arn:aws:iam::111111111111:role/codepipeline-role"
                ]
            },
            "Action": [
                "kms:ReEncrypt*",
                "kms:GenerateDataKey*",
                "kms:Encrypt",
                "kms:DescribeKey",
                "kms:Decrypt"
            ],
            "Resource": "*"
        }

【讨论】:

    猜你喜欢
    • 2019-02-03
    • 2018-01-10
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    相关资源
    最近更新 更多