AWS CodeCommit
User Guide (API Version 2015-04-13)

Overview of Managing Access Permissions to Your CodeCommit Resources

Every AWS resource is owned by an AWS 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 AWS Lambda, also support attaching permissions policies to resources.

Note

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 AWS 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
Repository

arn:aws:codecommit:region:account-id:repository-name

All CodeCommit repositories

arn:aws:codecommit:*

All CodeCommit repositories owned by the specified account in the specified region

arn:aws:codecommit:region:account-id:*

Note

Most AWS 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 AWS account 111111111111 in the us-east-2 AWS Region:

arn:aws:codecommit:us-east-2:111111111111:MyDemo*

For a list of available operations that work with the CodeCommit resources, see CodeCommit Permissions Reference.

Understanding Resource Ownership

The AWS account owns the resources that are created in the account, regardless of who created them. Specifically, the resource owner is the AWS 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 AWS account and grant permissions to create CodeCommit resources to that user, the user can create CodeCommit resources. However, your AWS account, to which the user belongs, owns the CodeCommit resources.

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

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

Managing Access to Resources

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

Note

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 AWS 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 AWS 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 AWS account (for example, Account B) or an AWS 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 AWS service permission to assume the role, the principal in the trust policy can also be an AWS 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 Overview of Managing Access Permissions to Your CodeCommit Resources.

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.

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 AWS 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 AWS 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 AWS-wide condition keys that you can use as appropriate. For a complete list of AWS-wide keys, see Available Keys for Conditions in the IAM User Guide.