In this lesson, you will learn how to move away from static pipeline environment variables by dynamically retrieving secrets from external providers like HashiCorp Vault or Cloud Secret Managers during your CI/CD execution.
The Problem with Pipeline Secrets
Historically, developers relied on "Secret Masking" within CI tools (e.g., GitHub Secrets or GitLab CI Variables). While convenient, these are static: they reside in the CI provider’s database, are often replicated across multiple environments, and are difficult to rotate. If your CI tool’s security is compromised, your secrets are exposed.
Dynamic Injection Architecture
Integrating an external provider shifts the secret management responsibility away from the CI engine. Instead of storing a DB_PASSWORD in your pipeline settings, you configure your runner to authenticate with a central Vault.
- Authentication: The pipeline runner (using a Service Account or OIDC token) authenticates against Vault.
- Authorization: Vault verifies the identity of the runner.
- Retrieval: The runner requests the secret at runtime. The secret is held only in the memory of the runner process and never written to disk or the pipeline logs.
Implementation Illustration
If you are running your CI/CD jobs inside Kubernetes, you can leverage the Vault Agent Sidecar Injector. This allows your job pods to mount secrets as files automatically, keeping them out of your environment variables:
# A job definition using Vault annotations
metadata:
annotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/role: "ci-pipeline-role"
vault.hashicorp.com/agent-inject-secret-config.json: "database/creds/myapp"
spec:
containers:
- name: runner
command: ["cat", "/vault/secrets/config.json"] # Secret is now a file
By using this approach, the secret is "injected" only when the job starts. When the job completes, the pod (and the ephemeral secret) is destroyed. This creates a "just-in-time" security posture where your secrets are never at rest within the CI/CD platform. You achieve true separation of concerns: the CI tool orchestrates the pipeline, while the Vault provider enforces security policy and secret rotation.
Key Takeaway: By using external Vault providers, you transform static, long-lived credentials into dynamic, ephemeral tokens that exist only in memory for the duration of a single job execution.