Securing CI/CD Pipelines: Identity, Secrets and Software Supply Chains
Protect build and deployment workflows with short-lived cloud identity, constrained permissions, trusted dependencies, and verifiable artifacts.
CI/CD systems can read source code, access package registries, build release artifacts, and deploy into cloud accounts. A compromised workflow or third-party action may therefore become a path from a pull request to production. Pipeline security is a cloud identity problem, a code integrity problem, and a software supply-chain problem at once.
The workflow below is conceptual. Replace the repository, role, region, and deployment steps with values reviewed for a real environment; no pipeline or deployment is claimed here.
Reduce pipeline authority
Long-lived cloud access keys stored as repository secrets can be copied, logged, or left active after use. Their lifetime and scope may extend beyond the workflow that needed them. OpenID Connect (OIDC) federation allows a workflow to request a short-lived identity token and exchange it for temporary AWS role credentials. The AWS role trust policy then decides which GitHub identity may assume the role. GitHub's AWS OIDC guide recommends conditions that restrict the sub claim.
The workflow also needs minimal GitHub token permissions. Set permissions explicitly, grant id-token: write only to the job that needs federation, and keep repository contents read-only unless a step needs more. Do not run deployment credentials in untrusted pull request jobs. Use protected branches, code review, and GitHub Environments with required reviewers for production access.
Trust policy and workflow sketch
The role trust policy should bind the GitHub OIDC provider, expected audience, and repository/ref or protected environment subject. A broad subject such as every repository in an organization can allow unrelated workflows to request cloud credentials. The role's permissions policy should be separate and grant only the deployment actions and resources necessary for that environment.
name: Deploy
on:
push:
branches: [main]
permissions:
contents: read
jobs:
deploy:
environment: production
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Pin to a reviewed full commit SHA in production
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4 # Pin to a reviewed full commit SHA
with:
role-to-assume: arn:aws:iam::123456789012:role/portfolio-deploy
aws-region: eu-west-1
- name: Deploy reviewed artifact
run: ./deploy.sh
The workflow has no static AWS access key. GitHub issues a token for the job, AWS STS returns temporary credentials for the assumed role, and the role permissions bound what deployment can change. In a real workflow, pin third-party actions to full commit SHAs and review updates. Version tags such as @v4 are readable but movable references; SHA pinning improves integrity while creating an update-maintenance responsibility.
The AWS trust relationship should restrict token.actions.githubusercontent.com:aud to sts.amazonaws.com and the sub value to the intended repository and branch or environment. With an environment subject, branch restrictions should also be configured on that GitHub Environment. Confirm the subject format in the repository's configuration, particularly as GitHub supports immutable subject claim formats for some repositories.
Secrets and untrusted code
Avoid printing secrets or enabling shell tracing around sensitive commands. Masking reduces accidental disclosure in logs, but it is not a boundary against malicious code that can transmit credentials. Keep secrets out of build arguments and artifacts, restrict who can edit workflow files, and review changes to deployment scripts. Fork pull requests and dependency update workflows need particular care because their code may be attacker-controlled.
Prefer OIDC for supported cloud access. For other credentials, use a dedicated secret store, narrow scope, rotate regularly, and expose values only to the step that needs them. Minimize token lifetime and prevent write permissions on jobs that only test or scan code.
Supply-chain controls and artifact integrity
Third-party actions execute code in the runner context. Use a small approved set, pin immutable references, review source and permissions, and monitor security advisories. Lock dependency versions and verify package sources. Build an artifact once, scan it, generate an SBOM and provenance where supported, then promote the same immutable artifact rather than rebuilding separately for each environment. Signatures and attestations are useful only when deployment verifies the expected identity and provenance.
Run static analysis, dependency checks, secret detection, and container scans before release. Define risk-based gates: for example, block known exploitable critical findings while creating a tracked exception for false positives. Scanning does not replace code review, patch management, or threat modeling. Protect artifact repositories and prevent untrusted workflows from overwriting release artifacts.
Deployment controls and monitoring
Separate build permissions from deployment permissions. Use distinct roles for development, staging, and production; each should target only its environment. Require approvals for production, protect deployment branches, and prevent arbitrary workflow dispatch inputs from selecting privileged roles or commands. Audit role assumptions in CloudTrail and correlate them with GitHub workflow run identity and commit references. Alert on role assumptions from unexpected repositories, branches, or workflows.
Common mistakes include trusting an organization-wide wildcard in sub, granting AdministratorAccess to the deploy role, assuming temporary credentials are harmless, using unpinned actions, granting write-all, and exposing production secrets to pull request code. OIDC removes stored long-lived AWS keys from the repository; it does not make workflow code trustworthy or eliminate the need for a restricted IAM role.
A learning exercise
A safe lab could configure a dedicated AWS test role for a repository and protected branch, then verify that the intended workflow can assume it while a different branch or repository is rejected. Review the resulting CloudTrail event and test that the role cannot alter unrelated resources. This is a suggested exercise, not a report that these tests have been run.
Conclusion
Secure pipelines minimize what workflow code can access, for how long, and under what repository identity. OIDC removes one persistent credential class, while trust conditions, role scope, action pinning, artifact integrity, review gates, and monitoring address the broader attack surface. These controls connect secure infrastructure code and container artifacts to a safer deployment path.