本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用標籤型存取控制
Amazon ECR CreateRepository API 動作可讓您在建立儲存庫時指定標籤。如需詳細資訊,請參閱在 Amazon ECR 中標記私有儲存庫。
若要讓使用者在建立時標記儲存庫,他們必須具備建立資源之動作 (如 ecr:CreateRepository
) 的使用許可。若標籤於資源建立動作指定,Amazon 會針對 ecr:CreateRepository
動作執行其他授權,以確認使用者具備建立標籤的許可。
您可以透過 IAM 政策來使用標籤型存取控制,範例如下。
以下政策只允許使用者將儲存庫建立或標記為 key=environment,value=dev
。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowCreateTaggedRepository", "Effect": "Allow", "Action": [ "ecr:CreateRepository" ], "Resource": "*", "Condition": { "StringEquals": { "aws:RequestTag/environment": "dev" } } }, { "Sid": "AllowTagRepository", "Effect": "Allow", "Action": [ "ecr:TagResource" ], "Resource": "*", "Condition": { "StringEquals": { "aws:RequestTag/environment": "dev" } } } ] }
下列政策可允許使用者從所有儲存庫提取映像,除非它們已標記為 key=environment,value=prod
。
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": [ "ecr:BatchGetImage", "ecr:GetDownloadUrlForLayer" ], "Resource": "*" }, { "Effect": "Deny", "Action": [ "ecr:BatchGetImage", "ecr:GetDownloadUrlForLayer" ], "Resource": "*", "Condition": { "StringEquals": { "ecr:ResourceTag/environment": "prod" } } } ] }