Authentication and access control for Amazon CodeCommit - Amazon CodeCommit
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 (PDF).

Authentication and access control for Amazon CodeCommit

Access to Amazon CodeCommit requires credentials. Those credentials must have permissions to access Amazon resources, such as CodeCommit repositories, and your IAM user, which you use to manage your Git credentials or the SSH public key that you use for making Git connections. The following sections provide details on how you can use Amazon Identity and Access Management (IAM) and CodeCommit to help secure access to your resources:


Because CodeCommit repositories are Git-based and support the basic functionality of Git, including Git credentials, we recommend that you use an IAM user when working with CodeCommit. You can access CodeCommit with other identity types, but the other identity types are subject to limitations, as described below.

Identity types:

  • IAM user – An IAM user is an identity within your Amazon Web Services account that has specific custom permissions. For example, an IAM user can have permissions to create and manage Git credentials for accessing CodeCommit repositories. This is the recommended user type for working with CodeCommit. You can use an IAM user name and password to sign in to secure Amazon webpages like the Amazon Web Services Management Console, Amazon Discussion Forums, or the Amazon Web Services Support Center.

    You can generate Git credentials or associate SSH public keys with your IAM user, or you can install and configure git-remote-codecommit. These are the easiest ways to set up Git to work with your CodeCommit repositories. With Git credentials, you generate a static user name and password in IAM. You then use these credentials for HTTPS connections with Git and any third-party tool that supports Git user name and password authentication. With SSH connections, you create public and private key files on your local machine that Git and CodeCommit use for SSH authentication. You associate the public key with your IAM user, and you store the private key on your local machine. git-remote-codecommit extends Git itself, and does not require setting up Git credentials for the user.

    In addition, you can generate access keys for each user. Use access keys when you access Amazon services programmatically, either through one of the Amazon SDKs or by using the Amazon Command Line Interface (Amazon CLI). The SDK and CLI tools use the access keys to cryptographically sign your requests. If you don’t use the Amazon tools, you must sign the requests yourself. CodeCommit supports Signature Version 4, a protocol for authenticating inbound API requests. For more information about authenticating requests, see Signature Version 4 Signing Process in the Amazon Web Services General Reference.

  • Amazon Web Services account root user – When you sign up for Amazon, you provide an email address and password that is associated with your Amazon Web Services account. These are your root credentials, and they provide complete access to all of your Amazon resources. Some CodeCommit features are not available for root account users. In addition, the only way to use Git with your root account is to either install and configure git-remote-codecommit (recommended) or to configure the Amazon credential helper, which is included with the Amazon CLI. You cannot use Git credentials or SSH public-private key pairs with your root account user. For these reasons, we do not recommend using your root account user when interacting with CodeCommit.


    For security reasons, we recommend that you use the root credentials only to create an administrator user, which is an IAM user with full permissions to your Amazon account. Then, you can use this administrator user to create other IAM users and roles with limited permissions. For more information, see IAM Best Practices and Creating an Admin User and Group in the IAM User Guide.

  • IAM Identity Center and users in IAM Identity Center – Amazon IAM Identity Center expands the capabilities of Amazon Identity and Access Management to provide a central place that brings together administration of users and their access to Amazon Web Services accounts and cloud applications. While recommended as a best practice for most users working with Amazon, IAM Identity Center does not currently provide mechanisms for Git credentials or SSH key pairs. These users can install and configure git-remote-codecommit to locally clone CodeCommit repositories, but not all integrated development environments (IDEs) support cloning, pushing, or pulling with git-remote-codecommit.

    As a best practice, require human users, including users that require administrator access, to use federation with an identity provider to access Amazon Web Services by using temporary credentials.

    A federated identity is a user from your enterprise user directory, a web identity provider, the Amazon Directory Service, or any user that accesses Amazon Web Services by using credentials provided through an identity source. When federated identities access Amazon Web Services accounts, they assume roles, and the roles provide temporary credentials.

  • IAM role – Like an IAM user, an IAM role is an IAM identity that you can create in your account to grant specific permissions.

    An IAM role is an identity within your Amazon Web Services account that has specific permissions. It is similar to an IAM user, but is not associated with a specific person. You can temporarily assume an IAM role in the Amazon Web Services Management Console by switching roles. You can assume a role by calling an Amazon CLI or Amazon API operation or by using a custom URL. For more information about methods for using roles, see Using IAM roles in the IAM User Guide.

    IAM roles with temporary credentials are useful in the following situations:

    • Federated user access – To assign permissions to a federated identity, you create a role and define permissions for the role. When a federated identity authenticates, the identity is associated with the role and is granted the permissions that are defined by the role. For information about roles for federation, see Creating a role for a third-party Identity Provider in the IAM User Guide.

    • Temporary IAM user permissions – An IAM user or role can assume an IAM role to temporarily take on different permissions for a specific task.

    • Cross-account access – You can use an IAM role to allow someone (a trusted principal) in a different account to access resources in your account. Roles are the primary way to grant cross-account access. However, with some Amazon Web Services, you can attach a policy directly to a resource (instead of using a role as a proxy). To learn the difference between roles and resource-based policies for cross-account access, see Cross account resource access in IAM in the IAM User Guide.

    • Cross-service access – Some Amazon Web Services use features in other Amazon Web Services. For example, when you make a call in a service, it's common for that service to run applications in Amazon EC2 or store objects in Amazon S3. A service might do this using the calling principal's permissions, using a service role, or using a service-linked role.

      • Forward access sessions (FAS) – When you use an IAM user or role to perform actions in Amazon, you are considered a principal. When you use some services, you might perform an action that then initiates another action in a different service. FAS uses the permissions of the principal calling an Amazon Web Service, combined with the requesting Amazon Web Service to make requests to downstream services. FAS requests are only made when a service receives a request that requires interactions with other Amazon Web Services or resources to complete. In this case, you must have permissions to perform both actions. For policy details when making FAS requests, see Forward access sessions.

      • Service role – A service role is an IAM role that a service assumes to perform actions on your behalf. An IAM administrator can create, modify, and delete a service role from within IAM. For more information, see Creating a role to delegate permissions to an Amazon Web Service in the IAM User Guide.

      • Service-linked role – A service-linked role is a type of service role that is linked to an Amazon Web Service. The service can assume the role to perform an action on your behalf. Service-linked roles appear in your Amazon Web Services account and are owned by the service. An IAM administrator can view, but not edit the permissions for service-linked roles.

    • Applications running on Amazon EC2 – You can use an IAM role to manage temporary credentials for applications that are running on an EC2 instance and making Amazon CLI or Amazon API requests. This is preferable to storing access keys within the EC2 instance. To assign an Amazon role to an EC2 instance and make it available to all of its applications, you create an instance profile that is attached to the instance. An instance profile contains the role and enables programs that are running on the EC2 instance to get temporary credentials. For more information, see Using an IAM role to grant permissions to applications running on Amazon EC2 instances in the IAM User Guide.

    To learn whether to use IAM roles or IAM users, see When to create an IAM role (instead of a user) in the IAM User Guide.


    You cannot use Git credentials or SSH public-private key pairs with federated users. In addition, user preferences are not available for federated users. For information about how to set up connections using federated access, see Setup steps for HTTPS connections to Amazon CodeCommit with git-remote-codecommit.

Access control

You can have valid credentials to authenticate your requests, but unless you have permissions you cannot create or access CodeCommit resources. For example, you must have permissions to view repositories, push code, create and manage Git credentials, and so on.

The following sections describe how to manage permissions for CodeCommit. We recommend that you read the overview first.

Overview of managing access permissions to your CodeCommit resources

Every Amazon resource is owned by an Amazon Web Services account. Permissions to create or access a resource are governed by permissions policies. An account administrator can attach permissions policies to IAM identities (that is, users, groups, and roles). Some services, such as Amazon Lambda, also support attaching permissions policies to resources.


An account administrator (or administrator user) is a user with administrator privileges. For more information, see IAM Best Practices in the IAM User Guide.

When granting permissions, you decide who gets the permissions, the resources they get permissions for, and the specific actions that you want to allow on those resources.

CodeCommit resources and operations

In CodeCommit, the primary resource is a repository. Each resource has a unique Amazon Resource Names (ARN) associated with it. In a policy, you use an Amazon Resource Name (ARN) to identify the resource that the policy applies to. For more information about ARNs, see Amazon Resource Names (ARN) and Amazon Service Namespaces in the Amazon Web Services General Reference. CodeCommit does not currently support other resource types, which are referred to as subresources.

The following table describes how to specify CodeCommit resources.

Resource Type ARN Format


All CodeCommit repositories


All CodeCommit repositories owned by the specified account in the specified Amazon Web Services Region



Most Amazon services treat a colon (:) or a forward slash (/) in ARNs as the same character. However, CodeCommit requires an exact match in resource patterns and rules. When creating event patterns, be sure to use the correct ARN characters so that they match the ARN syntax in the resource.

For example, you can indicate a specific repository (MyDemoRepo) in your statement using its ARN as follows:

"Resource": "arn:aws:codecommit:us-west-2:111111111111:MyDemoRepo"

To specify all repositories that belong to a specific account, use the wildcard character (*) as follows:

"Resource": "arn:aws:codecommit:us-west-2:111111111111:*"

To specify all resources, or if a specific API action does not support ARNs, use the wildcard character (*) in the Resource element as follows:

"Resource": "*"

You can also use the wildcard character(*) to specify all resources that match part of a repository name. For example, the following ARN specifies any CodeCommit repository that begins with the name MyDemo and that is registered to the Amazon Web Services account 111111111111 in the us-east-2 Amazon Web Services Region:


For a list of available operations that work with the CodeCommit resources, see CodeCommit permissions reference.

Understanding resource ownership

The Amazon Web Services account owns the resources that are created in the account, regardless of who created them. Specifically, the resource owner is the Amazon Web Services account of the principal entity (that is, the root account, an IAM user, or an IAM role) that authenticates the resource creation request. The following examples illustrate how this works:

  • If you create an IAM user in your Amazon Web Services account and grant permissions to create CodeCommit resources to that user, the user can create CodeCommit resources. However, your Amazon Web Services account, to which the user belongs, owns the CodeCommit resources.

  • If you use the root account credentials of your Amazon Web Services account to create a rule, your Amazon Web Services account is the owner of the CodeCommit resource.

  • If you create an IAM role in your Amazon Web Services account with permissions to create CodeCommit resources, anyone who can assume the role can create CodeCommit resources. Your Amazon Web Services account, to which the role belongs, owns the CodeCommit resources.

Managing access to resources

To manage access to Amazon resources, you use permissions policies. A permissions policy describes who has access to what. The following section explains the options for creating permissions policies.


This section discusses using IAM in the context of CodeCommit. It doesn't provide detailed information about the IAM service. For more information about IAM, see What Is IAM? in the IAM User Guide. For information about IAM policy syntax and descriptions, see IAM Policy Reference in the IAM User Guide.

Permissions policies that are attached to an IAM identity are referred to as identity-based policies (IAM policies). Permissions policies that are attached to a resource are referred to as resource-based policies. Currently, CodeCommit supports only identity-based policies (IAM policies).

Identity-based policies (IAM policies)

To manage access to Amazon resources, you attach permissions policies to IAM identities. In CodeCommit, you use identity-based policies to control access to repositories. For example, you can do the following:

  • Attach a permissions policy to a user or a group in your account – To grant a user permissions to view CodeCommit resources in the CodeCommit console, attach an identity-based permissions policy to a user or group that the user belongs to.

  • Attach a permissions policy to a role (to grant cross-account permissions) – Delegation, such as when you want to grant cross-account access, involves setting up a trust between the account that owns the resource (the trusting account), and the account that contains the users who need to access the resource (the trusted account). A permissions policy grants the user of a role the needed permissions to carry out the intended tasks on the resource. A trust policy specifies which trusted accounts are allowed to grant its users permissions to assume the role. For more information, see IAM Terms and Concepts.

    To grant cross-account permissions, attach an identity-based permissions policy to an IAM role. For example, the administrator in Account A can create a role to grant cross-account permissions to another Amazon Web Services account (for example, Account B) or an Amazon service as follows:

    1. Account A administrator creates an IAM role and attaches a permissions policy to the role that grants permissions on resources in Account A.

    2. Account A administrator attaches a trust policy to the role identifying Account B as the principal who can assume the role.

    3. Account B administrator can then delegate permissions to assume the role to any users in Account B. Doing this allows users in Account B to create or access resources in Account A. If you want to grant an Amazon service permission to assume the role, the principal in the trust policy can also be an Amazon service principal. For more information, see Delegation in IAM Terms and Concepts.

    For more information about using IAM to delegate permissions, see Access Management in the IAM User Guide.

The following example policy allows a user to create a branch in a repository named MyDemoRepo:

{ "Version": "2012-10-17", "Statement" : [ { "Effect" : "Allow", "Action" : [ "codecommit:CreateBranch" ], "Resource" : "arn:aws:codecommit:us-east-2:111111111111:MyDemoRepo" } ] }

To restrict the calls and resources that users in your account have access to, create specific IAM policies, and then attach those policies to IAM users. For more information about how to create IAM roles and to explore example IAM policy statements for CodeCommit, see Customer managed identity policy examples.

Resource-based policies

Some services, such as Amazon S3, also support resource-based permissions policies. For example, you can attach a resource-based policy to an S3 bucket to manage access permissions to that bucket. CodeCommit doesn't support resource-based policies, but you can use tags to identify resources, which you can then use in IAM policies. For an example of a tag-based policy, see Identity-based policies (IAM policies).

Resource scoping in CodeCommit

In CodeCommit, you can scope identity-based policies and permissions to resources, as described in CodeCommit resources and operations. However, you cannot scope the ListRepositories permission to a resource. Instead, you must scope it to all resources (using the wildcard *). Otherwise, the action fails.

All other CodeCommit permissions can be scoped to resources.

Specifying policy elements: resources, actions, effects, and principals

You can create policies to allow or deny users access to resources, or allow or deny users to take specific actions on those resources. CodeCommit defines a set of public API operations that define how users work with the service, whether that is through the CodeCommit console, the SDKs, the Amazon CLI, or by directly calling those APIs. To grant permissions for these API operations, CodeCommit defines a set of actions that you can specify in a policy.

Some API operations can require permissions for more than one action. For more information about resources and API operations, see CodeCommit resources and operations and CodeCommit permissions reference.

The following are the basic elements of a policy:

  • Resource – To identify the resource that the policy applies to, you use an Amazon Resource Name (ARN). For more information, see CodeCommit resources and operations.

  • Action – To identify resource operations that you want to allow or deny, you use action keywords. For example, depending on the specified Effect, the codecommit:GetBranch permission either allows or denies the user to perform the GetBranch operation, which gets details about a branch in a CodeCommit repository.

  • Effect – You specify the effect, either allow or deny, that takes place when the user requests the specific action. If you don't explicitly grant access to (allow) a resource, access is implicitly denied. You can also explicitly deny access to a resource to make sure that a user cannot access it, even if a different policy grants access.

  • Principal – In identity-based policies (IAM policies), the only type of policies that CodeCommit supports, the user that the policy is attached to is the implicit principal.

To learn more about IAM policy syntax, see IAM Policy Reference in the IAM User Guide.

For a table showing all of the CodeCommit API actions and the resources that they apply to, see CodeCommit permissions reference.

Specifying conditions in a policy

When you grant permissions, you use the access policy language for IAM to specify the conditions under which a policy should take effect. For example, you might want a policy to be applied only after a specific date. For more information about specifying conditions in a policy language, see Condition and Policy Grammar in the IAM User Guide.

To express conditions, you use predefined condition keys. There are no condition keys specific to CodeCommit. However, there are Amazon-wide condition keys that you can use as appropriate. For a complete list of Amazon-wide keys, see Available Keys for Conditions in the IAM User Guide.