Skip to main content
This lesson explains IAM policies and cross-service permissions for artifacts stored in Amazon S3 and AWS CodeArtifact, plus the service roles used by CodePipeline, CodeBuild, and CodeDeploy. Many build and deployment failures are caused by permissions problems; understanding the permission layers and where to check will significantly reduce troubleshooting time.

Overview

Artifacts in CI/CD pipelines pass through several AWS services. Access to those artifacts can be controlled at multiple layers: Cross-account access typically requires both the caller’s IAM permissions and the target resource’s resource-based policy to grant access. When KMS-encrypted artifacts are involved, the KMS key policy is an additional gate that must permit decryption or data key generation.

S3 and CodePipeline artifacts

CodePipeline stores pipeline artifacts in S3 during execution. For single-account pipelines, explicit bucket policies are sometimes optional if IAM permissions are sufficient. For cross-account pipelines you usually need a bucket policy granting access to the other account’s pipeline or build role for the specific bucket and prefix used for artifacts. Block Public Access settings block public exposure but do not replace explicit cross-account permissions — bucket policies remain the correct mechanism for granting access between accounts.
A screenshot of the Amazon S3 console showing a bucket's Permissions overview and Block public access (bucket settings) sections, with a green banner indicating the Block Public Access settings were successfully edited. The left sidebar shows S3 navigation items like Buckets and Access management.
A typical S3 bucket policy that allows a cross-account pipeline role to list the bucket and read/write objects under a prefix (replace placeholder values with real ARNs):
Tips:
  • Limit the object Resource to the specific prefix used for artifacts where possible (e.g., arn:aws:s3:::example-artifacts-bucket/pipelines/*) to follow least-privilege.
  • If using KMS encryption on S3 objects, ensure the KMS key policy allows the pipeline/build roles to call kms:Decrypt, kms:GenerateDataKey, etc.

CodeDeploy and service roles

If you do not see deployments, verify the relevant service role exists and that the pipeline has iam:PassRole permission to pass a service role to CodeDeploy/CodeBuild/other services. Service roles allow these services to act on your behalf.
A screenshot of the AWS Console showing the CodeDeploy "Deployment history" page with the message "No results — There are no results to display." The left sidebar shows Developer Tools navigation items like CodeCommit, CodeArtifact, CodeBuild and CodeDeploy.

Creating a pipeline and selecting a service role

When creating a pipeline you can select an existing service role or let the console create one. If you use an existing role, inspect its trust policy and attached permission policies to confirm the role can perform required operations (S3, CodeBuild, CodeDeploy, CodeArtifact, etc.).
A screenshot of the AWS CodePipeline "Create new pipeline" settings page showing a pipeline named "test," the execution mode set to "Queued," and the "Existing service role" option selected with a Role ARN dropdown open.

Inspecting the pipeline role

The pipeline role must:
  • Be assumable by CodePipeline (proper trust relationship).
  • Include permissions required by pipeline stages:
    • S3: read/write artifacts
    • CodeBuild: codebuild:StartBuild, codebuild:BatchGetBuilds (and related actions)
    • CodeDeploy: codedeploy:* actions needed for deployment
    • CodeStar Connections or other services if the pipeline integrates external sources
A screenshot of the AWS Identity and Access Management (IAM) Roles console showing the details for a role (creation date, ARN, max session duration) and a list of attached permission policies such as base-permissions, codebuild-access, codedeploy-access, and codestar-connections.
Example trust policy (assume role) for a pipeline role:
Common permissions a pipeline role typically needs (high level):
  • S3: s3:GetObject, s3:PutObject, s3:ListBucket
  • CodeBuild: codebuild:StartBuild, codebuild:BatchGetBuilds, codebuild:BatchGetProjects
  • CodeDeploy: codedeploy:CreateDeployment, codedeploy:GetDeployment, codedeploy:RegisterOnPremisesInstance, etc.
  • CodeStar connections: actions to start interactions with external repositories if configured

Build and deploy roles (examples)

Build roles frequently require:
  • ECR read access (to pull base images)
  • Secrets Manager or SSM Parameter Store access (for secrets/config)
  • Permission to write logs and store build artifacts
Example SSM parameter access policy limited to a parameter path:
Deploy roles may require permissions across Auto Scaling, ELB, EC2, ECS, Lambda, CloudWatch, and more. Example high-level deploy permissions:
Best practice: scope permissions to specific ARNs and actions required by your deployment pattern instead of using Resource: "*" wherever feasible.

CodeArtifact repository policies and cross-account access

CodeArtifact supports resource-based repository policies that permit other accounts to read from or publish to a repository. You can grant different sets of actions to multiple principals in a single repository policy (for example, granting read access to build roles and publish access to a dedicated publisher role). Example CodeArtifact repository policy allowing a build role in one account to read and a publisher role in another account to publish:
When troubleshooting CodeArtifact access:
  • Ensure the caller has the required identity policy allowing CodeArtifact actions.
  • Confirm the repository policy explicitly permits the caller/principal.
  • If the repository is in another account, verify the repository policy uses the correct principal ARN and actions.

KMS key policies and encrypted artifacts

If artifacts are encrypted with a customer-managed KMS key (CMK), the key policy must allow the service roles to use the key for cryptographic operations. Typical required actions include kms:Encrypt, kms:Decrypt, kms:ReEncrypt*, kms:GenerateDataKey*, and kms:DescribeKey. Example statement in a KMS key policy allowing two service roles to use the key:
Also confirm:
  • Any IAM policies granting KMS actions to roles/users are present.
  • There are no SCPs that deny KMS actions across the organization.
  • The KMS key is in the same region as the encrypted artifacts or configured for cross-region usage if needed.

Troubleshooting checklist

If you encounter permission problems accessing artifacts, check these items in order:
  1. Identity-based IAM policy for the caller (role or user).
  2. Resource-based policy on the target (S3 bucket policy, CodeArtifact repository policy).
  3. KMS key policy (if the artifact is encrypted).
  4. Organization Service Control Policies (SCPs).
  5. Any organization-level resource control policies (RCPs).
  6. VPC endpoint policy (if using VPC endpoints for S3 or other services).
  7. Permission boundaries applied to the IAM principal.
Additional operational notes:
  • Enforce least-privilege: prefer narrow Resource ARNs and action lists rather than wildcards.
  • When one AWS service invokes another (e.g., CodePipeline invoking CodeBuild or CodeDeploy), the invoker must be allowed to iam:PassRole for the service role being passed — validate that iam:PassRole is included in the invoker’s permissions and scoped to the correct role ARN.
  • Confirm trust relationships (the role’s assume-role policy) allow the correct service principal (for example, codepipeline.amazonaws.com for pipeline roles).
By following the layered checks above and verifying trust relationships, resource policies, and KMS access, you can systematically resolve most cross-service permission issues encountered in pipelines and artifact access.

Watch Video

Practice Lab