How Amazon Elastic Container Registry works with IAM
Before you use IAM to manage access to Amazon ECR, you should understand what IAM features are available to use with Amazon ECR. To get a high-level view of how Amazon ECR and other Amazon services work with IAM, see Amazon Services That Work with IAM in the IAM User Guide.
Topics
Amazon ECR Identity-based policies
With IAM identity-based policies, you can specify allowed or denied actions and resources as well as the conditions under which actions are allowed or denied. Amazon ECR supports specific actions, resources, and condition keys. To learn about all of the elements that you use in a JSON policy, see IAM JSON Policy Elements Reference in the IAM User Guide.
Actions
Administrators can use Amazon JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions.
The Action
element of a JSON policy describes the
actions that you can use to allow or deny access in a policy. Policy
actions usually have the same name as the associated Amazon API operation. There are some exceptions, such as permission-only
actions that don't have a matching API operation. There are also some operations that require multiple actions in a policy.
These additional actions are called dependent actions.
Include actions in a policy to grant permissions to perform the associated operation.
Policy actions in Amazon ECR use the following prefix before the action:
ecr:
. For example, to grant someone permission to create an
Amazon ECR repository with the Amazon ECR CreateRepository
API operation, you
include the ecr:CreateRepository
action in their policy. Policy
statements must include either an Action
or NotAction
element. Amazon ECR defines its own set of actions that describe tasks that you can
perform with this service.
To specify multiple actions in a single statement, separate them with commas as follows:
"Action": [ "ecr:action1", "ecr:action2"
You can specify multiple actions using wildcards (*). For example, to specify
all actions that begin with the word Describe
, include the
following action:
"Action": "ecr:Describe*"
To see a list of Amazon ECR actions, see Actions, Resources, and Condition Keys for Amazon Elastic Container Registry in the IAM User Guide.
Resources
Administrators can use Amazon JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions.
The Resource
JSON policy element specifies the object or objects to which the action applies. Statements must include either a
Resource
or a NotResource
element. As a best practice, specify a resource using its Amazon Resource Name (ARN). You can do this for actions that support a
specific resource type, known as resource-level permissions.
For actions that don't support resource-level permissions, such as listing operations, use a wildcard (*) to indicate that the statement applies to all resources.
"Resource": "*"
An Amazon ECR repository resource has the following ARN:
arn:${Partition}:ecr:${Region}:${Account}:repository/${Repository-name}
For more information about the format of ARNs, see Amazon Resource Names (ARNs) and Amazon Service Namespaces
For example, to specify the my-repo
repository in the
us-east-1
Region in your statement, use the following
ARN:
"Resource": "arn:aws:ecr:
us-east-1
:123456789012
:repository/my-repo"
To specify all repositories that belong to a specific account, use the wildcard (*):
"Resource": "arn:aws:ecr:
us-east-1
:123456789012
:repository/*"
To specify multiple resources in a single statement, separate the ARNs with commas.
"Resource": [ "resource1", "resource2"
To see a list of Amazon ECR resource types and their ARNs, see Resources Defined by Amazon Elastic Container Registry in the IAM User Guide. To learn with which actions you can specify the ARN of each resource, see Actions Defined by Amazon Elastic Container Registry.
Condition keys
Administrators can use Amazon JSON policies to specify who has access to what. That is, which principal can perform actions on what resources, and under what conditions.
The Condition
element (or Condition
block) lets you specify conditions in which a
statement is in effect. The Condition
element is optional. You can create
conditional expressions that use condition
operators, such as equals or less than, to match the condition in the
policy with values in the request.
If you specify multiple Condition
elements in a statement, or
multiple keys in a single Condition
element, Amazon evaluates them using
a logical AND
operation. If you specify multiple values for a single
condition key, Amazon evaluates the condition using a logical OR
operation. All of the conditions must be met before the statement's permissions are
granted.
You can also use placeholder variables when you specify conditions. For example, you can grant an IAM user permission to access a resource only if it is tagged with their IAM user name. For more information, see IAM policy elements: variables and tags in the IAM User Guide.
Amazon supports global condition keys and service-specific condition keys. To see all Amazon global condition keys, see Amazon global condition context keys in the IAM User Guide.
Amazon ECR defines its own set of condition keys and also supports using some global condition keys. To see all Amazon global condition keys, see Amazon Global Condition Context Keys in the IAM User Guide.
Most Amazon ECR actions support the aws:ResourceTag
and
ecr:ResourceTag
condition keys. For more information, see Using Tag-Based Access Control.
To see a list of Amazon ECR condition keys, see Condition Keys Defined by Amazon Elastic Container Registry in the IAM User Guide. To learn with which actions and resources you can use a condition key, see Actions Defined by Amazon Elastic Container Registry.
Examples
To view examples of Amazon ECR identity-based policies, see Amazon Elastic Container Registry Identity-based policy examples.
Amazon ECR resource-based policies
Resource-based policies are JSON policy documents that specify what actions a specified principal can perform on an Amazon ECR resource and under what conditions. Amazon ECR supports resource-based permissions policies for Amazon ECR repositories. Resource-based policies let you grant usage permission to other accounts on a per-resource basis. You can also use a resource-based policy to allow an Amazon service to access your Amazon ECR repositories.
To enable cross-account access, you can specify an entire account or IAM entities in another account as the principal in a resource-based policy. Adding a cross-account principal to a resource-based policy is only half of establishing the trust relationship. When the principal and the resource are in different Amazon accounts, you must also grant the principal entity permission to access the resource. Grant permission by attaching an identity-based policy to the entity. However, if a resource-based policy grants access to a principal in the same account, no additional identity-based policy is required. For more information, see How IAM Roles Differ from Resource-based Policies in the IAM User Guide.
The Amazon ECR service supports only one type of resource-based policy called a repository policy, which is attached to a repository. This policy defines which principal entities (accounts, users, roles, and federated users) can perform actions on the repository. To learn how to attach a resource-based policy to a repository, see Private repository policies in Amazon ECR.
Note
In an Amazon ECR repository policy, the policy element Sid
supports
additional characters and spacing not supported in IAM policies.
Examples
To view examples of Amazon ECR resource-based policies, see Private repository policy examples in Amazon ECR,
Authorization based on Amazon ECR tags
You can attach tags to Amazon ECR resources or pass tags in a request to Amazon ECR. To
control access based on tags, you provide tag information in the condition
element of a policy using the
ecr:ResourceTag/
,
key-name
aws:RequestTag/
, or
key-name
aws:TagKeys
condition keys. For more information about tagging
Amazon ECR resources, see Tagging a private repository in Amazon ECR.
To view an example identity-based policy for limiting access to a resource based on the tags on that resource, see Using Tag-Based Access Control.
Amazon ECR IAM roles
An IAM role is an entity within your Amazon account that has specific permissions.
Using Temporary Credentials with Amazon ECR
You can use temporary credentials to sign in with federation, assume an IAM role, or to assume a cross-account role. You obtain temporary security credentials by calling Amazon STS API operations such as AssumeRole or GetFederationToken.
Amazon ECR supports using temporary credentials.
Service-linked roles
Service-linked roles allow Amazon services to access resources in other services to complete an action on your behalf. Service-linked roles appear in your IAM account and are owned by the service. An IAM administrator can view but not edit the permissions for service-linked roles.
Amazon ECR supports service-linked roles. For more information, see Using service-linked roles for Amazon ECR.