Managing Secrets in CI/CD Pipelines: Identity, Exposure and Revocation
Protect CI/CD secrets with short-lived identities, scoped deployment access, safe logging and tested revocation. Review pull requests, runners and build artefacts.
A secret is exposed when an untrusted party can use it, not only when its literal value appears in a log. A pipeline job may be able to request a token, call a deployment API or retrieve a vault value without ever printing the credential.
Map each credential to the job that needs it, the permissions it grants and the people or code that can influence that job. This makes secret management an access-control exercise rather than a masking setting.
Inventory privileged identities
List cloud access, package publishing, deployment, signing, database and third-party service credentials. Record the environment, permitted actions, owner, storage location and revocation method.
Include platform-issued job tokens and service identities. A credential generated automatically can still grant excessive access. Check whether development and production share a key, role or secret-store path.
Prefer short-lived, constrained access
Where supported, use workload identity federation instead of a stored long-lived key. The cloud trust policy should constrain the permitted repository, workflow context, branch or environment and audience as appropriate.
Enabling an OIDC token in the workflow is only part of that design. If the receiving role trusts every project or branch, a token from an unintended job may still obtain valuable access. Validate both the permitted and refused cases.
Separate trusted deployment from untrusted builds
Do not give privileged secrets to jobs that execute unreviewed contributor code, dependency scripts or generated commands. Use protected environments and appropriate approval boundaries for production.
Review indirect routes too: a trusted job might download and execute an artefact produced by an untrusted one. The absence of a secret in the first job does not remove that later trust problem.
Keep values out of logs and artefacts
Avoid shell tracing and unnecessary environment dumps in credentialed jobs. Review tool errors, debug output, test reports, caches, container layers and uploaded artefacts for accidental disclosure.
Masking is a secondary protection. Encoded, transformed or fragmented values may not match the redaction rule. Use harmless test values to exercise failure paths and confirm that sensitive fields are excluded rather than relying on the happy-path log.
Plan rotation and revocation
| Event | Required follow-through |
|---|---|
| Credential is committed or logged | Revoke it and investigate use; remove exposed copies appropriately. |
| Service integration is retired | Remove the stored secret and the receiving-side permission. |
| Contributor or supplier leaves | Review their access to workflows and downstream identities. |
| Production role becomes broader | Reassess the jobs and approval routes allowed to assume it. |
| Rotation is completed | Confirm the old credential no longer works. |
Deleting a repository line or log does not invalidate a leaked credential. Revocation should address active sessions or derived tokens where relevant to the service.
Verify the whole identity path
Test an allowed deployment and a request from an unapproved context using controlled access. Confirm that role permissions are limited to the intended resource and operation. Keep audit evidence showing which job obtained access and what it changed.
Document emergency access and a recovery owner. A secret process that cannot recover from expiry or revocation may encourage unsafe workarounds during an incident.
Further reading: GitHub Actions secure use and AWS IAM best practices.
Related resources
Read our testing methodology or discuss your assessment.