Remove secrets by replacing embedded credentials with short-lived, centrally issued credentials or identity-based access. Use a vault, OIDC-backed federation, or cloud instance roles so the access model where the runner fetches secrets at runtime, rather than storing SSH keys, passwords, or API tokens in code, variables, or state files. Rotate any residual secrets and block plaintext output in logs.
Why infrastructure automation should stop embedding secrets
Infrastructure automation works best when the runner proves its own workload identity and receives just enough access for the task at runtime. That removes the secret from code, variables, templates, and state, which are all places where accidental reuse and disclosure become much more likely. The practical goal is to make automation authenticate, not to make it remember credentials.
When teams treat a secret as part of the automation design, they create a long-lived dependency that is hard to inventory and harder to revoke. A safer model uses centrally issued credentials with tight scope, short duration, and clear rotation ownership, so compromise of one pipeline or runner does not automatically expose every downstream system it can reach.
What the replacement pattern looks like in practice
The replacement pattern is usually secretless or near-secretless automation: the job starts, authenticates with a federated identity, and fetches only the values it needs at runtime. That can be done with a vault, cloud instance roles, or OIDC-backed federation, depending on the platform. Secrets Management Guide is useful here because it frames the move from stored credentials to runtime access as an operating model, not just a tooling choice.
For infrastructure as code, the same pattern applies to templates, variables, and state files. If a pipeline still needs a credential, that credential should be centrally issued, tightly scoped, and easy to replace without changing the infrastructure definition itself. Infrastructure as Code Security Guide covers the related state and module risks, which is where secrets often reappear after teams think they have removed them.
If the automation needs API keys rather than cloud role assumption, the key should be treated as an exception, not a default. API Key Management Guide supports the operational side of that decision, especially scoping, revocation, and response when a key is exposed.
Where teams usually miss residual exposure
The most common failure is partial removal. Teams delete a hardcoded password from the script, but leave the same value in environment variables, state snapshots, CI logs, artifact bundles, or backup copies. Another common miss is assuming that a secret is safe because it is no longer in source control, when the real exposure may be in a runner cache or a build log.
Rotation matters after removal because old credentials can persist outside the automation path. If the secret was ever used by a runner, assume it may have been copied into logs, debugging output, or downstream systems that replay job metadata. That is why secret elimination should be paired with revocation, not just replacement.
Teams that use federated identity or cloud instance roles should still verify the trust boundary carefully. The access model is only safer if the token audience, claim conditions, role scope, and logging are all constrained enough that a stolen job token cannot be reused elsewhere. OWASP Non-Human Identity Top 10 is a good external reference for the identity and privilege risks that appear when automation becomes the accessor.
Risk and Threat Considerations
Embedded secrets create a wide blast radius because they are easy to copy, hard to locate, and often overprivileged. If a pipeline variable, state file, or runner log leaks, an attacker may be able to authenticate directly to production services, impersonate automation, or move laterally through trusted integrations.
Failure mechanism: the automation path stores reusable credentials in places that are replicated, cached, logged, or shared, so one exposed copy becomes a durable access path until the credential is rotated or revoked.
Impact: exposed automation secrets can lead to unauthorized infrastructure changes, data access, service disruption, and persistent access that survives the original incident unless teams actively revoke every credential and dependent token.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 addresses the attack and risk surface, while NIST SP 800-53 Rev 5, NIST SP 800-57, CIS Controls v8 and OWASP ASVS set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | Automation secrets are often leaked through code, state, logs, and runner output. |
| NHI-07 — Long-Lived Secrets | The question is about replacing persistent automation credentials with short-lived access. | |
| NHI-05 — Overprivileged NHI | Automation access should be narrowly scoped so a leaked credential cannot overreach. | |
| Recommendation — Remove reusable secrets from automation paths and rotate any credential that may have been exposed. Replace long-lived automation secrets with short-lived credentials and runtime federation. Scope automation credentials to the minimum permissions needed for the job. | ||
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | Covers issuing, rotating, and revoking the credentials automation depends on. |
| IA-9 — Identification and Authentication (Non-Organizational Users) | Applies when workloads, services, or external automation authenticate to systems. | |
| AC-6 — Least Privilege | Automation access should be limited to reduce blast radius if credentials leak. | |
| Recommendation — Rotate, replace, and revoke automation authenticators on a defined lifecycle. Use federated, identity-based authentication for automation instead of embedded shared secrets. Restrict automation permissions to the minimum required access. | ||
| NIST SP 800-57 | Key Management | Relevant where automation uses keys or token material that must be issued and retired safely. |
| Recommendation — Manage credential and key lifecycles so stale automation secrets are retired quickly. | ||
| CIS Controls v8 | 5 — Account Management | Removing secrets from automation depends on controlling account and credential lifecycle. |
| Recommendation — Inventory automation accounts, remove unused secrets, and disable stale access paths. | ||
| OWASP ASVS | V6 — Authentication | The answer centers on replacing stored secrets with stronger authentication methods. |
| Recommendation — Use stronger authentication patterns instead of embedding reusable credentials. | ||
Practitioner Guidance
What to verify: confirm that the runner can obtain access without any long-lived secret being present in code, variables, state, or image layers. If a secret still exists, verify whether it is truly runtime-only, narrowly scoped, and independently revocable.
Implementation sequence: first replace the secret with federated or role-based access, then rotate and revoke the old value, then hunt for copies in logs, state, caches, and artifacts. Do not reverse that order, because leaving the old credential active creates unnecessary overlap.
Common mistake: treating secret removal as complete once the repository is clean. For automation, the real question is whether the control plane, job output, and downstream state still contain usable authentication material.
Practitioner takeaway: the best outcome is not “no secrets anywhere,” it is “no reusable secret on the automation path,” with every remaining credential short-lived, scoped, observable, and disposable.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
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.
Reviewed and updated by the NHIMG editorial team on November 6, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org