当用户需要使用自定义OSS bucket时,需要为账号添加RAM角色,并为该RAM角色授予对OSS bucket操作的权限,然后容器镜像服务才能正常访问该OSS bucket。

步骤一:创建RAM角色

容器镜像服务访问自定义OSS bucket时,需要为阿里云账号创建的角色名为AliyunContainerRegistryCustomizedOSSBucketRole。

  1. 云账号登录RAM控制台
  2. 在左侧导航栏,单击RAM角色管理
  3. 单击创建RAM角色
  4. 选择可信实体类型为阿里云账号,单击下一步
  5. 输入角色名称备注
  6. 选择云账号为当前云账号,单击完成
    说明 若选择其他云账号,需要填写其他云账号的ID。

步骤二:配置RAM角色的权限策略

配置该RAM角色的策略,使其拥有对指定的OSS bucket资源读取容器镜像仓库信息的权限,RAM角色的权限策略名为AliyunContainerRegistryCustomizedOSSBucketRolePolicy。当需要获取多个自定义OSS bucket信息时,可向Resource中添加多个OSS bucket值。

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "oss:GetObject",
                "oss:PutObject",
                "oss:DeleteObject",
                "oss:ListParts",
                "oss:AbortMultipartUpload",
                "oss:InitiateMultipartUpload",
                "oss:CompleteMultipartUpload",
                "oss:DeleteMultipleObjects",
                "oss:ListMultipartUploads",
                "oss:ListObjects"
            ],
            "Resource": [
                "acs:oss:*:*:<your_bucket_name>",
                "acs:oss:*:*:<your_bucket_name>/*"
            ],
            "Effect": "Allow",
            "Condition": {

            }
        },
        {
            "Action": [
                "oss:PutBucket",
                "oss:GetBucket",
                "oss:GetBucketLocation",
                "oss:PutBucketEncryption",
                "oss:GetBucketEncryption",
                "oss:PutBucketAcl",
                "oss:GetBucketAcl",
                "oss:PutBucketLogging",
                "oss:GetBucketReferer",
                "oss:PutBucketReferer",
                "oss:GetBucketLogging"
            ],
            "Resource": [
                "acs:oss:*:*:<your_bucket_name>",
                "acs:oss:*:*:<your_bucket_name>/*"
            ],
            "Effect": "Allow",
            "Condition": {

            }
        },
        {
            "Effect": "Allow",
            "Action": "oss:ListBuckets",
            "Resource": [
                "acs:oss:*:*:*",
                "acs:oss:*:*:*/*"
            ],
            "Condition": {

            }
        },
        {
            "Action": [
                "vpc:DescribeVpcs"
            ],
            "Resource": "acs:vpc:*:*:vpc/*",
            "Effect": "Allow",
            "Condition": {

            }
        },
        {
            "Action": [
                "cms:QueryMetricLast",
                "cms:QueryMetricList"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

步骤三:配置RAM角色的信任策略

为该RAM角色的信任策略中添加容器镜像服务,使容器镜像服务可以访问用户自定义的OSS bucket。

{
    "Statement": [
        {
            "Action": "sts:AssumeRole",
            "Effect": "Allow",
            "Principal": {
                "Service":
                "cr.aliyuncs.com"
            }
        }
    ],
    "Version": "1"
}