Module 15 · Advanced
CI/CD & Secret Exposure
How pipeline secrets and source-control exposure actually fail, how a professional scopes a review, and where TruffleHog and Gitleaks fit. Conceptual only: no extraction steps, no token harvesting, no scanner command lines.
Authorized testing only. Practice on systems you own, isolated labs, or targets with written permission. Unauthorized access is illegal.
Outcomes
- Describe where CI systems and git histories leak credentials
- Scope a secrets review to repositories and history you are allowed to read
- Explain what TruffleHog and Gitleaks are for, and what they are not
- Recommend prevention: secret stores, short-lived credentials, rotation, and hooks
Lessons
Secrets in build and deploy pipelines
CI jobs need credentials to deploy. The failure is when those credentials are long-lived, over-privileged, printed in logs, or copied into the repo because that was faster.
Learning objectives
- Name the places a pipeline secret usually lives
- Contrast a long-lived key with short-lived federation
- Recognize log and artifact exposure as part of the same problem
- State the preventive controls a report should recommend
Deep teach-through
What a pipeline is trusted with
A continuous integration job checks out code, runs tests, builds an artifact, and often deploys it. To do that last step it needs a credential: a cloud role, a package-registry token, a signing key, an SSH key, or an API token for production. That credential is a secret even when the repository is private. Anyone who can change the pipeline, read its logs, or controls the runner can reach whatever the secret can reach.
The intended home for that material is the CI system's secret store or, better, a workload identity that mints a short-lived credential for one job. The unintended homes are a committed env file, a Dockerfile argument baked into an image, a wiki page, a chat paste, and a variable defined in the job file in plain text because someone was debugging a failed deploy.
This lesson does not show how to pull secrets out of a runner or a log archive. It teaches you to ask whether the design needed a long-lived secret at all.
Failure modes you should be able to name
Standing cloud keys in CI variables, shared across every repository in the organization, with administrator rights 'so deploys do not fail.' One compromised repo then deploys, or destroys, more than its own app.
Secrets printed while debugging. The command that echoes the environment, the verbose error that includes the connection string, and the build log retained for months are all copies. Log access becomes secret access.
Pull-request pipelines that run untrusted code with production secrets available. A fork or a feature branch should not receive the production deploy credential. The professional recommendation is environment protection: production secrets only on protected branches, reviewed changes, and trusted runners.
Build artifacts that contain the secret because it was passed as a build argument or copied into the image layer. Deleting the variable later does not rewrite the image that was pushed yesterday.
What to recommend
Prefer workload identity federation (OIDC from the CI provider to the cloud) so the job receives a short-lived credential for one deployment and nothing sits in a variable for a year. Where a static secret is unavoidable, store it in the CI secret manager or a dedicated vault, scope it to one environment, and rotate it on a schedule and on personnel changes.
Separate read credentials for tests from deploy credentials for production. Mask secrets in logs. Limit who can read logs and who can edit pipeline definitions. Protect the environments that hold production rights.
When a review finds a live credential, the first action is rotation and revocation, coordinated with the owner, not a longer write-up of where else it might work. The report then explains the design change that keeps the next one from landing in the same place.
Key concepts
- CI secret
- A credential the build system holds so a job can reach another system.
- Workload identity
- The pipeline proves who it is and receives a short-lived credential, instead of storing a long-lived key.
- Environment protection
- Rules that release production secrets only to reviewed jobs on trusted branches.
- Log exposure
- A secret copied into build output, where everyone who can read logs can read the secret.
Common mistakes
- Treating a private repository as a safe place for production keys
- Giving every pipeline the same administrator cloud key
- Rotating the variable and forgetting the image layers and log archives
- Testing secret scanners against repositories you were not hired to read
Defender view
- Inventory CI variables the same way you inventory cloud roles.
- Alert when a pipeline definition starts printing the environment.
- Production deploy rights belong to a protected environment, not to every pull request.
Operator checklist
- The scope names organizations, repositories, and CI systems
- I will not run scanners against code outside that list
- A live secret finding triggers rotation with the owner before a wide report
- Recommendations prefer short-lived federation over a new static key
Practice drills
- List five places a deploy credential can leak without anyone 'hacking' the server
- Write the difference between a CI variable and workload identity federation
- Draft the rotation sentence you would send the owner if a key had been committed
Tools for this lesson
Next: Source control keeps history. That is the next lesson.
Secrets in source control
Deleting a key from the latest commit does not delete it from history. TruffleHog and Gitleaks are how teams look. This page explains the idea and the response, not how to extract anything.
Learning objectives
- Explain why git history, forks, and mirrors keep a committed secret alive
- Describe TruffleHog and Gitleaks as scanners, including the difference in approach
- Scope a history review and handle findings as incidents
- Recommend hooks, ignore rules, and secret managers so the next commit stays clean
Deep teach-through
Why deletion is not remediation
Git stores every commit. A password added on Monday and removed on Tuesday is still in Monday's commit, and in every clone made in between. Squashing on one branch does not rewrite every fork, every CI cache, and every laptop. A public repository is readable by anyone. A private repository is readable by everyone who was ever granted access, plus backups.
Exposure is not only a file named .env. Secrets show up in infrastructure snippets, test fixtures, notebook outputs, container manifests, and tickets that were copied into the tree. A sample that looks fake sometimes is not. Treat a high-confidence match as a credential until the owner proves it was a decoy.
Your job in an authorized review is to find exposure and drive rotation. It is not to use the secret, prove how far it reaches beyond what the owner asks, or keep a personal copy. Using a found credential is an incident of your own making unless the rules of engagement explicitly allow a tightly bounded check and the owner is on the call.
TruffleHog and Gitleaks
Both tools are already in the OpsField directory. They scan content you are allowed to read and report strings that look like credentials. Gitleaks is a fast pattern-based scanner teams often run in pre-commit hooks and in CI so a known key format is blocked before it merges. TruffleHog searches git history and other sources and can verify some provider credentials so the report leans toward live keys rather than every high-entropy string.
Neither tool is a license to scan the internet's repositories. Point them at the organization, the history window, and the clones named in scope. Expect false positives: test fixtures, revoked keys, and documentation samples. Expect false negatives: a secret that does not match a known pattern. A clean scan is not proof the tree is safe. It is one control.
Read the tool pages for what each project is. This lesson intentionally has no command lines and no walkthrough of pulling a secret back out of an old commit. If you need the vendor's own usage notes, use them inside a repository you own or are contracted to assess, after you have a place to send findings.
Professional response
Scope: which hosts (GitHub, GitLab, a self-hosted server), which organizations, whether forks are included, how far back history goes, and who receives the raw findings. Raw findings are credentials. Store them like credentials, with a short retention clock, not in a shared slide deck.
Order of operations when something looks live: tell the owner through the agreed channel, revoke or rotate, then confirm the new credential is in the secret manager and the old one is dead. History rewriting is painful and incomplete; it is a cleanup step after rotation, not a substitute for rotation. Notify downstream clones if the repository was public or widely forked.
Prevention you should be able to recommend without a tool manual: secret managers, pre-commit and CI scanning, a documented exception path for intentional test fixtures, protected branches, least-privilege tokens, and a short page that tells developers what to do in the first hour after they commit a key. The first hour is rotation, not a force-push and a hope that nobody pulled.
Key concepts
- History exposure
- A secret remains in older commits and clones after it disappears from the latest tree.
- Gitleaks
- A pattern-based secret scanner commonly used as a pre-commit and CI control.
- TruffleHog
- A secret scanner that searches history and can verify some credentials against the provider.
- Rotation
- Revoke the exposed credential and issue a new one. Deleting the file is not rotation.
Common mistakes
- Declaring the issue fixed because the latest commit no longer contains the key
- Scanning public code you were not asked to assess and then trying the keys
- Emailing raw secrets to a wide recipient list
- Rewriting history first and rotating later, or never
Defender view
- Block pushes that match known secret patterns, and review the bypass list.
- Treat a public commit of a cloud key as an incident with a clock, not a backlog ticket.
- Give developers a one-page response card so the first action is revocation.
Operator checklist
- Repositories and history windows are listed before any scan
- I know who receives raw matches and how long they are kept
- I will not use a discovered credential
- The report leads with rotation, then design changes, then scanner names
Practice drills
- Explain to a developer why removing the file in a new commit leaves the secret in place
- Write two sentences that distinguish Gitleaks from TruffleHog without any flags or commands
- Draft a six-line incident note: what was exposed, who rotates it, what must not be done with it
Tools for this lesson
Next: Mobile apps hide a different class of secret and a different test path. That module is next.