Private registry authentication for tasks - Amazon Elastic Container Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Private registry authentication for tasks

Private registry authentication for tasks using Amazon Secrets Manager enables you to store your credentials securely and then reference them in your task definition. This provides a way to reference container images that exist in private registries outside of Amazon that require authentication in your task definitions. This feature is supported by tasks hosted on Fargate, Amazon EC2 instances, and external instances using Amazon ECS Anywhere.


If your task definition references an image that's stored in Amazon ECR, this topic doesn't apply. For more information, see Using Amazon ECR Images with Amazon ECS in the Amazon Elastic Container Registry User Guide.

For tasks hosted on Amazon EC2 instances, this feature requires version 1.19.0 or later of the container agent. However, we recommend using the latest container agent version. For information about how to check your agent version and update to the latest version, see Updating the Amazon ECS container agent.

For tasks hosted on Fargate, this feature requires platform version 1.2.0 or later. For information, see Amazon Fargate platform versions.

Within your container definition, specify the repositoryCredentials object with the details of the secret that you created. The secret you reference can be from a different Amazon Web Services Region or a different account than the task using it.


When using the Amazon ECS API, Amazon CLI, or Amazon SDK, if the secret exists in the same Amazon Web Services Region as the task that you're launching then you can use either the full ARN or name of the secret. If the secret exists in a different account, the full ARN of the secret must be specified. When using the Amazon Web Services Management Console, the full ARN of the secret must be specified always.

The following is a snippet of a task definition that shows the required parameters:

"containerDefinitions": [ { "image": "private-repo/private-image", "repositoryCredentials": { "credentialsParameter": "arn:aws:secretsmanager:region:aws_account_id:secret:secret_name" } } ]

Another method of enabling private registry authentication uses Amazon ECS container agent environment variables to authenticate to private registries. This method is only supported for tasks hosted on Amazon EC2 instances. For more information, see Private registry authentication for container instances.

Required IAM permissions for private registry authentication

The Amazon ECS task execution role is required to use this feature. This allows the container agent to pull the container image. For more information, see Amazon ECS task execution IAM role.

To provide access to the secrets that you create, add the following permissions as an inline policy to the task execution role. For more information, see Adding and Removing IAM Policies.

  • secretsmanager:GetSecretValue

  • kms:Decrypt—Required only if your key uses a custom KMS key and not the default key. The Amazon Resource Name (ARN) for your custom key must be added as a resource.

The following is an example inline policy that adds the permissions.

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "kms:Decrypt", "ssm:GetParameters", "secretsmanager:GetSecretValue" ], "Resource": [ "arn:aws:secretsmanager:<region>:<aws_account_id>:secret:secret_name", "arn:aws:kms:<region>:<aws_account_id>:key/key_id" ] } ] }

Enabling private registry authentication

To create a basic secret

Use Amazon Secrets Manager to create a secret for your private registry credentials.

  1. Open the Amazon Secrets Manager console at

  2. Choose Store a new secret.

  3. For Select secret type, choose Other type of secrets.

  4. Select Plaintext and enter your private registry credentials using the following format:

    { "username" : "privateRegistryUsername", "password" : "privateRegistryPassword" }
  5. Choose Next.

  6. For Secret name, enter an optional path and name, such as production/MyAwesomeAppSecret or development/TestSecret, and choose Next. You can optionally add a description to help you remember the purpose of this secret later.

    The secret name must be ASCII letters, digits, or any of the following characters: /_+=.@-.

  7. (Optional) At this point, you can configure rotation for your secret. For this procedure, leave it at Disable automatic rotation and choose Next.

    For instructions on how to configure rotation on new or existing secrets, see Rotating Your Amazon Secrets Manager Secrets.

  8. Review your settings, and then choose Store secret to save everything that you entered as a new secret in Secrets Manager.

To create a task definition that uses private registry authentication

  1. Open the Amazon ECS console at

  2. In the navigation pane, choose Task Definitions.

  3. On the task definitions page, choose Create new task definition.

  4. On the Select launch type compatibility page, choose the launch type for your tasks and then Next step.


    This step only applies to Regions that support Amazon ECS using Amazon Fargate. For more information, see Amazon ECS on Amazon Fargate.

  5. For task definition Name, enter a name for your task definition. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed.

  6. For Task execution role, either select your existing task execution role or choose Create new role. This role authorizes Amazon ECS to pull private images for your task. For more information, see Required IAM permissions for private registry authentication.


    If the Task execution role field doesn't appear, choose Configure via JSON and add the executionRoleArn field to specify your task execution role. The following shows the syntax:

    "executionRoleArn": "arn:aws:iam::aws_account_id:role/ecsTaskExecutionRole"
  7. For each container to create in your task definition, complete the following steps:

    1. In the Container Definitions section, choose Add container.

    2. For Container name, type a name for your container. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed.

    3. For Image, type the image name or path to your private image. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed.

    4. Select the Private repository authentication option.

    5. For Secrets manager ARN, enter the full Amazon Resource Name (ARN) of the secret that you created earlier. The value must be between 20 and 2048 characters.

    6. Fill out the remaining required fields and any optional fields to use in your container definitions. More container definition parameters are available in the Advanced container configuration menu. For more information, see Task definition parameters.

    7. Choose Add.

  8. When your containers are added, choose Create.