Secrets in CI/CD

Tokens stored in .github/workflows/*.yml, .gitlab-ci.yml, a Jenkinsfile, deployment shell scripts or build-time files can leak through the repository and build logs.

If a secret was exposed

  1. Immediately revoke an exposed token or change an exposed password. Store the replacement in GitHub Actions Secrets or your CI/CD platform’s credential store.
  2. Remove live values from workflows and deployment scripts. Use a platform reference such as ${{ secrets.NAME }}.
  3. Check previous run logs for the exposed value.

Recommended approach

Grant deployment credentials only the permissions they need and set a rotation interval. For cloud deployments, check whether OIDC or workload identity can supply short-lived credentials in place of stored, long-lived keys.

Examples

Before

yaml
steps:
  - name: Deploy
    run: |
      curl -H "Authorization: Bearer ghp_xxxxxxxxx" https://example.com/deploy

After

yaml
steps:
  - name: Deploy
    env:
      DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
    run: |
      curl -H "Authorization: Bearer ${DEPLOY_TOKEN}" https://example.com/deploy

Additional checks

  • Verify that new runs mask secret values in logs.
  • Check which jobs triggered by external events, such as pull requests from forks, can access deployment secrets. Restrict that access.