Any CI job that deploys something needs a credential for the place it deploys to: a cloud role, a database password, a registry token, an SSH key. For as long as the job runs, that credential sits on the CI runner, where the build script and every third-party action in the job can read it.
What is CI/CD secrets management?
CI/CD secrets management is how a delivery pipeline gets the credentials it needs (cloud access, database passwords, registry and API tokens, SSH and signing keys) without those credentials ending up in code, in logs or in the wrong job. It covers where each secret is kept, which pipelines can obtain it, how long it stays valid and who can see that it was used.
Pipeline secrets management is the same thing under another name. DevOps secrets management is the wider field, which also takes in the secrets applications read at runtime, Kubernetes Secrets and the keys on engineers’ laptops. This guide stays with the pipeline, because the threat there is unusual: on every build, code you didn’t write runs next to your credentials.
The usual answer is a vault or a cloud secrets manager. Keep secrets in one place, inject them at runtime, rotate them on a schedule. That beats hardcoded secrets in a repository by a wide margin, and it still hands the job a working password or key. We’d ask a different question of each secret first: does the job need to hold it at all?
Where pipeline secrets leak
GitHub’s security hardening guide states the core problem plainly. A compromised action “would have access to all secrets configured on your repository, and may be able to use the GITHUB_TOKEN to write to the repository.” Every route below is a version of that.
Logs come first. Masking works by finding the exact secret value in the output, so anything that changes the value gets past it. GitHub warns that a secret stored as a JSON, XML or YAML blob can defeat redaction, and CISA noted that the tj-actions payload printed secrets as double-encoded base64. In a public repository, workflow logs are readable by anyone.
Then there’s the runner itself. Every step in a job runs on the same machine, so code in one step can read files and environment variables left by another, and the Trivy payload below went as far as the runner’s own process memory. Scoping a secret to the step that uses it keeps your own scripts tidy. It doesn’t keep a malicious action out.
Pull requests reach further than people expect. GitHub’s guidance is that anyone who can fork a repository and open a pull request can compromise a self-hosted runner that builds it, and get at the secrets that runner holds.
Last comes secret sprawl, which is slower and more common. One deploy key gets copied into the secrets of a dozen repositories, an organization secret gets shared with every repository, and a token pasted into a workflow file years ago is still in git history. Hardcoded secrets in Dockerfiles live on in image layers. When one of those long-lived credentials leaks, nobody can say how many copies to revoke.
OWASP files most of this under CICD-SEC-6: Insufficient Credential Hygiene in its Top 10 CI/CD Security Risks, with the over-broad pipeline identities behind it under CICD-SEC-2.
What the tj-actions and Trivy compromises showed
In March 2025, someone repointed the version tags of tj-actions/changed-files, an action that lists the files a commit changed, to a malicious commit. CISA’s alert (CVE-2025-30066) gives the exposure window as March 12, 00:00 UTC to March 15, 12:00 UTC, and the loot as cloud access keys, GitHub personal access tokens, npm tokens and private RSA keys, written into workflow logs. CISA also linked it to a compromise of reviewdog/action-setup@v1 around the same time, which may have enabled it.
A year later the same thing happened to the Trivy scanner, with a nastier payload. The GitHub advisory (CVE-2026-33634) says that on March 19, 2026, an attacker force-pushed 76 of the 77 version tags of aquasecurity/trivy-action and all 7 tags of aquasecurity/setup-trivy. Before the real scan ran, the injected code dumped the memory of the runner’s Runner.Worker process through /proc/<pid>/mem, swept more than 50 file paths for SSH keys, cloud credentials, Kubernetes tokens and .env files, encrypted the haul and sent it to the attacker’s servers.
Three details in that advisory change how we’d defend a pipeline.
Reading the worker’s memory makes most in-job hygiene irrelevant. Masking only ever touched the logs, and a secret didn’t have to be passed to the Trivy step to be within reach of a payload that reads the process holding the job’s secrets.
Pinning protected fewer people than expected. The advisory lists teams that pinned trivy-action to a commit SHA from before April 9, 2025 as affected too, because that version of trivy-action pulled setup-trivy by tag. A SHA pin freezes the action you reference; anything it references by tag can still move. GitHub’s guide now puts workflow dependency lockfiles ahead of SHA pinning: a lockfile records the exact commit of every action a workflow depends on, transitive ones included.
And the attacker may have come back through the cleanup. The March 19 attack followed a compromise of the project disclosed on March 1. The project’s secret rotation then ran over a few days instead of happening all at once, and the advisory says a token that was still valid could have been used to read the new secrets as they were issued.
Three ways to give a CI job a credential
Every credential a pipeline uses ends up in one of three arrangements, and what a compromised step leaves with differs a lot between them.
| Stored secret, injected at runtime | Short-lived credential via OIDC | Secret kept on a proxy | |
|---|---|---|---|
| Where the secret lives | CI secret store or vault, copied into the job | Nowhere; the job holds a signed identity token | On the proxy, or fetched by it when a connection opens |
| What a compromised step gets | The secret, valid until someone rotates it | A credential that expires on its own, usually within an hour | Access through the proxy, under its policy, until the job’s token expires |
| Works with | Anything that takes a password or key | Services that trust an OIDC issuer: AWS, Google Cloud, Azure, HashiCorp Vault | Whatever protocols the proxy speaks: databases, SSH, HTTP APIs |
| Cleaning up after a leak | Rotate every copy | Tighten or remove the trust policy | Change the proxy policy or the upstream credential |
Stored secrets stay the default because they work with everything. Short-lived credentials are the pipeline version of zero standing privileges: nothing usable exists between runs. A real pipeline ends up using all three, and the work is moving each credential as far right in that table as its target allows.
How does GitHub Actions OIDC work?
GitHub Actions OIDC lets a workflow job prove which repository, branch and environment it runs from instead of presenting a stored key. GitHub’s OIDC provider signs a JSON Web Token for each job. The cloud provider or service checks the signature, the audience and the claims against a trust policy it was configured with, and when they match it returns credentials that expire shortly afterwards.
The job has to ask for the token with permissions: id-token: write, which GitHub notes grants no write access to any resource. The claims carry the context: in GitHub’s example token, sub is repo:octo-org/octo-repo:environment:prod, alongside repository, ref, environment, workflow, actor and runner_environment.
Most of the risk sits in the trust policy. GitHub’s AWS guide shows two. One matches sub exactly with StringEquals. The other uses StringLike with repo:octo-org/octo-repo:*, which GitHub says allows any branch, pull request merge branch or environment in that repository to assume the role. If that role can deploy to production, so can a workflow on any branch someone can push to. Match the full subject of a protected environment or branch, and check aud too.
Subjects are also changing shape. Repositories created after July 15, 2026 get an immutable default subject format that includes the owner and repository IDs (not on GitHub Enterprise Server), so check which format a repository uses before copying a trust policy from an older one. Our Endpoint docs avoid names altogether: the claim condition they recommend for GitHub Actions matches repository_owner_id and repository_id.
One property catches people out. With id-token: write, GitHub sets ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN in every step of the job, so any action in it can mint a token and use whatever credentials that token buys until they expire. What it can’t do is leave with a key that still works next week. Grant the permission to the deploy job only, and keep third-party actions you can do without out of that job.
GitLab, CircleCI and Buildkite issue OIDC tokens to jobs as well, with their own claim names, and the same rules about tight trust policies apply. On the receiving side, Google Cloud calls this workload identity federation; on AWS it’s an IAM OIDC identity provider plus a role assumed with AssumeRoleWithWebIdentity.
Databases, SSH and APIs that don’t take OIDC
Point an OIDC token at a Postgres server and nothing happens. The database wants a username and password or a client certificate, and the same goes for MySQL, for SSH hosts that authenticate with keys, and for the many SaaS APIs that take one static key. Once the cloud keys are gone, these are the secrets left in the pipeline, and they tend to sit closest to customer records and other sensitive data.
There are two ways to handle them. A secrets broker can issue a fresh login per job; Vault’s database secrets engine, for one, creates a database user on request. The job still receives a working password, just one that expires. Or a proxy in front of the resource keeps the password and adds it to the connection, so the job authenticates to the proxy with its OIDC identity and never sees it at all. A proxy also sees each query or command that goes through it, so access control and audit can work per statement, which a broker can’t offer.
How Formal keeps database and SSH credentials off the runner
The second pattern is what we built Formal PAM around, so read this section with that in mind.
The job authenticates to Formal’s control plane with its CI token through an OIDC integration. Each integration has an issuer, a machine user and a claim condition written in CEL, such as claims.sub == 'repo:formalco/monorepo:ref:refs/heads/main'. A condition that fails, errors or returns anything but a boolean denies the login. The job then calls CreateFederationToken and receives a Connector token that expires at the earlier of the CI token’s own expiry and one hour from now. Only OIDC-authenticated machine users can mint one; API keys and human sessions can’t. From there the job connects to the Connector with the returned username and token as its database login, psql "host=<CONNECTOR_HOST> ... user=<USERNAME> password=<FEDERATION_TOKEN>" in the docs’ example. The Connector signs in upstream as a Native User: a password, an SSH key, cloud IAM, a kubeconfig or an API key header, stored encrypted in Formal, read from an environment variable on the Connector, or returned by a hook at connection time. The docs’ hook example fetches a read-only database login from Vault, and the hook only runs after policy has allowed the connection. At no point does the runner hold the database password.
Connector policies can read the CI token’s claims (Connector 2.16.1 or later). This session policy from the OIDC integration docs lets in one repository’s main branch and blocks everything else:
package formal.v2
import future.keywords.if
default session := {
"action": "block",
"type": "block_with_formal_message"
}
session := {
"action": "allow",
"reason": "Trusted repository and branch"
} if {
input.user.oidc.claims.repository == "formalco/monorepo"
input.user.oidc.claims.ref == "refs/heads/main"
}
Two rough edges are worth knowing before you script it. OpenSSH truncates passwords longer than 1,023 bytes, and federation tokens carry the source claims, so they often run past that; the docs have you send a formalhash: SHA-256 of the token as the SSH password instead. And protocols that match stored credentials, such as some MySQL and S3 paths, only accept a token once it has synced to the Connector, so retry briefly right after minting.
A run can also be tied to the person who triggered it. An end-user email expression maps a claim to a Formal user, and if nothing matches, no token is issued. The docs’ warning applies: build it only from claims the workload can’t choose itself. Audit events keep the integration and a bounded copy of the claims, never the raw JWT, and the integration is a formal_integration_oidc resource in Terraform, so a change to who can reach production gets reviewed like any other change.
For jobs that call many services, the Formal Endpoint can run inside the job instead. It signs in with the GitHub Actions token on GitHub-hosted or self-hosted runners and fetches a new token before the current one expires, for as long as the job runs. On GitLab and other CI systems that hand the job a JWT in an environment variable, it can’t renew, so a long job needs a restart with a fresh token. Its Azure token source doesn’t support Azure DevOps Pipelines.
We don’t think Formal belongs in front of your cloud APIs here: if the job only needs AWS, Google Cloud or Azure, let it federate with the cloud directly. Formal earns its place for the resources that only take static credentials. We moved our own Terraform Cloud runs from a long-lived Formal API key to OIDC the same way, which our post on giving cloud agents production access with OIDC describes.
Self-hosted runners
GitHub’s guidance on self-hosted runners is blunt: unlike GitHub-hosted ones, they “can be persistently compromised by untrusted code in a workflow.” A file one job writes to disk, a credential a CLI caches in a home directory, or an API key someone baked into the runner’s environment is still there for the next job, whoever’s code that job runs.
So the case for storing nothing is strongest here. Start the Endpoint from the runner’s job-started hook, which our docs list as a supported way to launch it, and each job gets its own short-lived identity with no Formal API key on the machine. Runners that are thrown away after one job remove the persistence itself, and they’re worth the setup on any runner that builds code from pull requests. Default-deny egress filtering on the runner covers the other end: the Trivy payload still had to send what it found somewhere.
Best practices for the GitHub Actions secrets you still store
Some secrets will stay: a signing key, a token for a SaaS API nobody has put behind a proxy yet, a vendor that has never heard of OIDC. For those, on GitHub Actions (other CI platforms have close equivalents):
- Keep production deployment secrets in environments with required reviewers. A job can’t read them until a reviewer approves the run.
- Store one value per secret. GitHub warns that structured blobs break log redaction, and any value you derive at runtime needs registering as a mask.
- Set the default
GITHUB_TOKENpermissions to read-only and grant write scopes per job. - Lock workflow dependencies with a lockfile, or pin every third-party action to a full commit SHA where you can’t, and then look at what those actions reference themselves.
- Don’t attach self-hosted runners to public repositories.
- When a secret leaks, revoke everything it could have exposed in one change and issue the replacements after.
Vaults, masking and rotation schedules, the core of most secrets management advice, all assume the secret belongs on the runner and try to limit the damage once it’s there. The tj-actions secrets were masked, and the payload printed them anyway; the Trivy payload never needed the logs. Each credential you move to OIDC or behind a proxy is one less to chase down the next time an action you depend on turns out to be compromised.