Join our Newsletter — 33% off our NHI Course
Home› Guides› How to find secrets in CI logs and…
Guide Non-Human Identity (NHI)

How to find secrets in CI logs and build artefacts: scan, purge and rotate

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 28 October 2026 10 min read
On this page

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 (dir mode) and TruffleHog (filesystem, docker, circleci and jenkins sources) can scan downloaded logs, archives and images.
  • Verify before you escalate: TruffleHog's --results=verified mode 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/checkout saves the job token in .git/config by default, so workflows that uploaded the checkout directory as an artefact published live tokens in projects run by large vendors. Fixes included persist-credentials: false and uploading only specific build outputs.
  • When a debug step was added: commands such as printing the environment, verbose HTTP clients or set -x shell 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 .env files, 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

OutputWhere it lives (GitHub Actions example)Typical leak
Job logsWorkflow run page; Download log archive from the gear menu; REST API run logsEncoded or derived tokens, environment dumps, verbose tool errors on STDERR
ArtefactsRun page Artifacts section; REST API artefacts list with expires_atConfig files, .env files, test reports with headers, packaged directories
CachesActions cache for dependencies and build outputsCredential files written into cached directories (for example registry or package manager config)
Container imagesRegistries the pipeline pushes toSecrets copied into layers, build-time files, manifests
Jenkins console output and archived artefactsBuild pages on the controllerGroovy-interpolated credentials and transformed values that masking misses
Test and coverage uploadsThird-party services the pipeline posts toEnvironment 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

  1. List recent runs per repository with gh run list, then download logs with gh run view <run-id> --log or 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.
  2. Download artefacts with gh run download <run-id>, or list them through the REST artefacts endpoint and record each one's expires_at.
  3. 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.
  4. For images, pull each tag the pipeline publishes, or export it to a tar file, for scanning in place.
  5. 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 --redact and -f json -r report.json. Use a baseline file (-b) for accepted findings so reruns show only new issues.
  • TruffleHog on files: the filesystem source scans paths; add --results=verified to keep only credentials it confirmed as live, or verified,unknown for high-confidence results, with --json output.
  • TruffleHog on platforms directly: its documented sources include docker --image (including file:// tar exports), circleci --token and jenkins --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

FindingSeverity guideAction
Verified live credential in a public project's log or artefactCriticalRotate now, delete the run output, review provider logs for use since the run date
Verified live credential in a private projectHighRotate within your SLA, delete the output, check who could read the project
Unverified but plausible credentialMediumAsk the owner to confirm; treat as live if they cannot
Expired, revoked or test credentialLowDelete the output, fix the step that printed it
False positiveNoneAdd to the baseline with a reason

5. Purge and rotate

  1. 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.
  2. 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.
  3. Delete artefacts or the run: GitHub warns that a deleted artefact cannot be restored, and deleting a workflow run deletes all its artefacts.
  4. Remove image tags that contain secrets and rebuild them cleanly; consumers may still hold copies, which is why rotation comes first.
  5. Fix the cause: remove the debug step, stop printing environment variables, and register derived values as secrets.

Verify it worked

MetricHow to measureTarget
Verified live secrets in CI outputsTruffleHog verified results per scanZero open
Time from detection to rotationTicket timestampsWithin your critical SLA (for example same day)
Log and artefact retentionRepository, organisation and enterprise settingsShortened from the 90-day default where the business allows
Repeat leaks from the same pipelineFindings grouped by workflowNone after the fix
CoveragePipelines scanned against total pipelines with production secrets100% 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's setSecret), 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-days option of actions/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 STDOUT and STDERR.
  • 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: false on checkout unless a later step needs git authentication.
  • Restrict who can read runs: keep sensitive pipelines in private repositories and limit read access.
FrameworkReferenceRelevance
NIST CSF 2.0PR.AA-01, DE.CM-03Credential management; monitoring for exposure
NIST SP 800-53 Rev 5IA-5, SA-15, AU-6Authenticator protection, secure development tooling, log review
CIS Controls v8.1Controls 3 and 16Data protection and application software security
MITRE ATT&CKT1552.001, T1552, T1195.002Credentials in files, unsecured credentials, software supply chain compromise
OWASP Top 10 CI/CD Security RisksCICD-SEC-6, CICD-SEC-10Credential 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 dir and TruffleHog filesystem or docker, 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

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

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 28 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.