CI platforms redact the secrets they know about, but encoded, derived and structured secrets regularly slip into job logs, test reports and uploaded artefacts, where they sit for months and can be downloaded by anyone with read access to the project. This guide shows how to find those leaks: which outputs to collect, how to scan them with open source secret scanners, how to confirm and purge findings, and how to stop the next one. Examples use GitHub Actions because its documentation is explicit about redaction limits and retention, with notes for Jenkins and container images. It is for platform engineers, AppSec teams and incident responders. Scanning source code is covered in the Git Secret Scanning Guide; this page is about what pipelines produce.
Key takeaways
- Redaction is best effort: GitHub states that because a secret can be transformed in many ways, automatic redaction is not guaranteed, and that structured data such as JSON, XML or YAML blobs can cause redaction to fail.
- Retention makes leaks durable: GitHub stores build logs and artefacts for 90 days by default, so one bad run stays downloadable for three months unless you shorten retention or delete it.
- Rotate first, then delete: GitHub advises deleting a log that contains an unredacted secret and rotating the secret; deleting alone leaves anyone who already copied it with a working credential.
- Scan outputs, not just code: tools such as Gitleaks (
dirmode) and TruffleHog (filesystem,docker,circleciandjenkinssources) can scan downloaded logs, archives and images. - Verify before you escalate: TruffleHog's
--results=verifiedmode checks whether a found credential is live, which turns a noisy report into a short rotation list.
When you need this
- After a CI platform or supplier incident: in the CircleCI breach, customers were told to rotate every secret stored on the platform and review activity, because environment variables, tokens and keys could have been accessed. Knowing where else those secrets had leaked (logs, artefacts) shortens the review.
- When a project goes public or gains outside contributors: anyone with read access can view and download workflow logs and artefacts on GitHub, so historical runs become exposed.
- As a scheduled hygiene task: monthly scans of recent logs and artefacts for production pipelines, aligned with your secret sprawl metrics. See the Secret Sprawl Measurement Guide.
- When workflows upload whole directories: in ArtiPACKED, Unit 42 found that
actions/checkoutsaves the job token in.git/configby default, so workflows that uploaded the checkout directory as an artefact published live tokens in projects run by large vendors. Fixes includedpersist-credentials: falseand uploading only specific build outputs. - When a debug step was added: commands such as printing the environment, verbose HTTP clients or
set -xshell tracing are common sources of leaks. - When images are published: build outputs include container images. In the Docker Hub secrets leak, Flare found credentials in
.envfiles, Dockerfiles, copied project folders and manifests inside public images.
Before you start
- Authority and scope: get written approval covering which organisations, projects and registries you will scan. Downloaded logs may contain personal data and live credentials, so treat the working directory as sensitive.
- A secure workspace: an isolated, encrypted machine or ephemeral VM with no sync to personal cloud storage. Delete the downloads when finished.
- Tooling: GitHub CLI (
gh) or API access with read permission on Actions; Gitleaks and TruffleHog from their official releases. Pin versions. - Output handling: run scanners with redaction (Gitleaks
--redact) and JSON or SARIF reports so findings do not reprint full secrets into new logs. - Rotation contacts: an owner list for each credential type (cloud, registry, SaaS API keys) so verified findings can be rotated the same day.
Step-by-step
1. Decide what to collect
| Output | Where it lives (GitHub Actions example) | Typical leak |
|---|---|---|
| Job logs | Workflow run page; Download log archive from the gear menu; REST API run logs | Encoded or derived tokens, environment dumps, verbose tool errors on STDERR |
| Artefacts | Run page Artifacts section; REST API artefacts list with expires_at | Config files, .env files, test reports with headers, packaged directories |
| Caches | Actions cache for dependencies and build outputs | Credential files written into cached directories (for example registry or package manager config) |
| Container images | Registries the pipeline pushes to | Secrets copied into layers, build-time files, manifests |
| Jenkins console output and archived artefacts | Build pages on the controller | Groovy-interpolated credentials and transformed values that masking misses |
| Test and coverage uploads | Third-party services the pipeline posts to | Environment variables captured by upload scripts |
Prioritise pipelines that hold production or publishing credentials, public repositories, and runs from the last 90 days (the default retention window).
2. Collect logs and artefacts
- List recent runs per repository with
gh run list, then download logs withgh run view <run-id> --logor the log archive. Note that GitHub says a log archive for a partially re-run workflow contains only the re-run jobs, so fetch earlier attempts too. - Download artefacts with
gh run download <run-id>, or list them through the REST artefacts endpoint and record each one'sexpires_at. - For Jenkins, collect console text and archived artefacts for the same window using an account with read access only. See How to audit Jenkins credentials and secrets.
- For images, pull each tag the pipeline publishes, or export it to a tar file, for scanning in place.
- Keep a manifest of what was collected: repository, run ID, attempt, artefact name, image digest and download time.
3. Scan
- Gitleaks on files:
gitleaks dir -v <path>scans directories and files; add--redactand-f json -r report.json. Use a baseline file (-b) for accepted findings so reruns show only new issues. - TruffleHog on files: the
filesystemsource scans paths; add--results=verifiedto keep only credentials it confirmed as live, orverified,unknownfor high-confidence results, with--jsonoutput. - TruffleHog on platforms directly: its documented sources include
docker --image(includingfile://tar exports),circleci --tokenandjenkins --url, which avoids building your own collector for those platforms. - Your own patterns: add rules for internal token formats and for encodings your tooling produces (base64 blobs, URL-encoded strings). See the Secret Scanner Rule Coverage Comparison Guide.
4. Triage each finding
| Finding | Severity guide | Action |
|---|---|---|
| Verified live credential in a public project's log or artefact | Critical | Rotate now, delete the run output, review provider logs for use since the run date |
| Verified live credential in a private project | High | Rotate within your SLA, delete the output, check who could read the project |
| Unverified but plausible credential | Medium | Ask the owner to confirm; treat as live if they cannot |
| Expired, revoked or test credential | Low | Delete the output, fix the step that printed it |
| False positive | None | Add to the baseline with a reason |
5. Purge and rotate
- Rotate at the provider: issue a replacement, update the CI secret, run the pipeline, then revoke the old credential. The Docker Hub case summary makes the same point: revoke, do not just delete.
- Delete the log: on GitHub use Delete all logs on the run, or the documented script and REST API for many runs. Deleting logs needs write access.
- Delete artefacts or the run: GitHub warns that a deleted artefact cannot be restored, and deleting a workflow run deletes all its artefacts.
- Remove image tags that contain secrets and rebuild them cleanly; consumers may still hold copies, which is why rotation comes first.
- Fix the cause: remove the debug step, stop printing environment variables, and register derived values as secrets.
Verify it worked
| Metric | How to measure | Target |
|---|---|---|
| Verified live secrets in CI outputs | TruffleHog verified results per scan | Zero open |
| Time from detection to rotation | Ticket timestamps | Within your critical SLA (for example same day) |
| Log and artefact retention | Repository, organisation and enterprise settings | Shortened from the 90-day default where the business allows |
| Repeat leaks from the same pipeline | Findings grouped by workflow | None after the fix |
| Coverage | Pipelines scanned against total pipelines with production secrets | 100% each cycle |
Re-run the pipeline that leaked and scan its new log and artefacts: the finding should be gone. Confirm with the provider's audit log that the old credential now fails, and on GitHub check the organisation audit log for secret changes such as org.update_actions_secret.
Rollback and common errors
- Deleting evidence too early: if the leak may have been used, preserve a copy of the affected log (encrypted, access-restricted) for the incident record before you purge it. Deletion on GitHub is permanent.
- Rotating without updating the pipeline: builds fail. Rollback is restoring the previous secret value only while the old credential is still valid, which is why you revoke last.
- Scanning only the default branch runs: pull request and feature branch runs produce logs too, and untrusted pull request workflows are where secrets are most exposed.
- Trusting masking for structured secrets: a service account JSON key or a kubeconfig stored as one secret is a GitHub-documented redaction failure case. Store individual values or use federation.
- Forgetting derived values: GitHub notes that a value generated from a secret, such as a signed token, must itself be registered (
::add-mask::or the toolkit'ssetSecret), and that the same applies to base64 or URL-encoded forms. Masking must be done once per value per job. - Re-leaking through scanner output: scanner reports pasted into tickets or chat become a new leak. Redact, and store reports with the same care as the secrets.
Hardening afterwards
- Replace static secrets with OIDC federation: short-lived tokens leaked in a log expire quickly. See the CI/CD Pipeline Identity Security Guide.
- Shorten retention: set log and artefact retention at the organisation level and per artefact with the
retention-daysoption ofactions/upload-artifact. - Review logs after test runs: GitHub recommends viewing run logs after testing valid and invalid inputs to check secrets are redacted, because tools may send errors containing secrets to
STDOUTandSTDERR. - Scan before publishing: scan images and artefacts in the pipeline before push or upload, and fail the job on verified findings. See the Secrets in Container Images and Build Artefacts Guide.
- Upload only what you need: name specific output paths in upload steps rather than the workspace, and set
persist-credentials: falseon checkout unless a later step needs git authentication. - Restrict who can read runs: keep sensitive pipelines in private repositories and limit read access.
| Framework | Reference | Relevance |
|---|---|---|
| NIST CSF 2.0 | PR.AA-01, DE.CM-03 | Credential management; monitoring for exposure |
| NIST SP 800-53 Rev 5 | IA-5, SA-15, AU-6 | Authenticator protection, secure development tooling, log review |
| CIS Controls v8.1 | Controls 3 and 16 | Data protection and application software security |
| MITRE ATT&CK | T1552.001, T1552, T1195.002 | Credentials in files, unsecured credentials, software supply chain compromise |
| OWASP Top 10 CI/CD Security Risks | CICD-SEC-6, CICD-SEC-10 | Credential hygiene and logging. See the OWASP CI/CD Top 10 CICD-SEC-6 Insufficient Credential Hygiene Guide. |
Practitioner checklist
- Agree scope and set up an isolated, encrypted workspace for downloads.
- Collect job logs (all attempts), artefacts, Jenkins console output and published images for the retention window.
- Scan with Gitleaks
dirand TruffleHogfilesystemordocker, with redaction and JSON reports. - Verify findings and triage by exposure and liveness.
- Rotate at the provider first, then delete logs, artefacts, runs or image tags.
- Fix the step that printed the secret and register derived values with
::add-mask::. - Shorten log and artefact retention and add pre-publish scanning that fails on verified secrets.
- Move pipeline credentials to OIDC federation where the target supports it.
Standards and references
- GitHub Docs: Secure use reference for GitHub Actions
- GitHub Docs: Using workflow run logs
- GitHub Docs: Removing workflow artifacts
- GitHub Docs: Workflow commands (add-mask)
- Jenkins: Using a Jenkinsfile (string interpolation and credentials)
- Gitleaks: Project documentation
- TruffleHog: Project documentation
- OWASP: Top 10 CI/CD Security Risks
Related NHI Mgmt Group resources: Git Secret Scanning Guide · Secrets in Container Images and Build Artefacts Guide · CI/CD Pipeline Compromise Playbook · OWASP NHI Top 10 NHI2 Secret Leakage Guide