Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 36 ยท Operations and Integration

Vault Integration: CI/CD Pipelines, Kubernetes and the HTTP API

Connect Vault to real workloads: CI/CD with JWT/OIDC, Kubernetes auth with Agent Injector, CSI provider and Vault Secrets Operator, plus the HTTP API and client libraries.

Vault is only useful when workloads can reach it safely. The key idea of all integrations is the same: do not store a long-lived Vault token in the pipeline or the container. Instead, the workload proves who it is using something the platform already provides (a Kubernetes service account token, a CI job's signed identity), and Vault hands back a short-lived token or secret.

Vault, Kubernetes and the CI services are not available on this site. All configs are real examples for you to adapt; the JavaScript blocks are stand-ins.

The HTTP API underneath everything

Every CLI command is an HTTP call. Knowing this helps in any language:

Terminal
curl --header "X-Vault-Token: $VAULT_TOKEN" \
     https://vault.example.internal:8200/v1/secret/data/myapp/db

Responses are JSON. For KV v2 the secret sits in data.data:

JSON
{"request_id":"...","lease_duration":0,"data":{"data":{"user":"app","password":"..."},"metadata":{"version":3}}}

Official client libraries exist for Go, Python (hvac is the community standard), Java, Node.js, .NET and Ruby. Always send the token in a header, use TLS and handle 403 (denied), 404 (missing) and 5xx (retry with backoff).

JS Stand-in: reading a KV v2 response

Press Run (or Ctrl + Enter) to see the console output here.

No output.

CI/CD with JWT/OIDC

Modern CI systems (GitHub Actions, GitLab CI, CircleCI) issue each job a signed OIDC token that states the repository, branch and workflow. Configure Vault's JWT auth method to trust the issuer and bind roles to claims:

Terminal
vault auth enable jwt
vault write auth/jwt/config oidc_discovery_url="https://token.actions.githubusercontent.com" \
    bound_issuer="https://token.actions.githubusercontent.com"
vault write auth/jwt/role/deploy role_type=jwt user_claim=repository \
    bound_audiences=vault bound_claims='{"repository":"acme/shop","ref":"refs/heads/main"}' \
    policies=deploy ttl=10m

A workflow then logs in with the job token and fetches secrets with no stored credential. Only the main branch of acme/shop can obtain the deploy policy.

JS Stand-in: check bound claims

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Kubernetes

Pods authenticate with the Kubernetes auth method: Vault verifies the pod's service account token with the cluster's API and maps it to a role.

Terminal
vault auth enable kubernetes
vault write auth/kubernetes/config kubernetes_host="https://$KUBERNETES_SERVICE_HOST:443"
vault write auth/kubernetes/role/shop bound_service_account_names=shop \
    bound_service_account_namespaces=prod policies=app-readonly ttl=1h

Three ways to deliver secrets to pods:

  1. Agent Injector (mutating webhook): annotate the pod and a sidecar writes secret files.
    YAML
    annotations:
      vault.hashicorp.com/agent-inject: "true"
      vault.hashicorp.com/role: "shop"
      vault.hashicorp.com/agent-inject-secret-db: "secret/data/myapp/db"
    
  2. Vault CSI provider: mounts secrets as volumes through the Secrets Store CSI driver; no sidecar.
  3. Vault Secrets Operator (VSO): syncs Vault secrets into native Kubernetes Secret objects using custom resources. Easy for existing apps, but the data then also lives in etcd, so enable etcd encryption.

Vault itself can run on Kubernetes with the official Helm chart (helm install vault hashicorp/vault) using Raft storage and auto-unseal. See Vault Agent for what the sidecar does.

Choosing an approach

Situation Good fit
App can call an API Client library or Agent proxy
App reads files Agent templates or Injector
App needs a native Kubernetes Secret VSO
CI pipeline JWT/OIDC login, short TTL
Legacy scripts AppRole with a wrapped secret ID

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where is a KV v2 secret found in the JSON API response?

    KV v2 nests the key/value pairs in data.data and metadata beside it.
  2. 2. Why prefer JWT/OIDC login in CI over a stored Vault token?

    The job proves its identity at runtime, so there is nothing long-lived to leak.
  3. 3. Which Kubernetes option creates native Secret objects from Vault data?

    VSO syncs Vault secrets into Kubernetes Secrets.
  4. 4. What does the Kubernetes auth method verify?

    Vault asks Kubernetes to validate the token and maps it to a role.

Summary

  • Everything is the HTTP API; use official or community libraries with TLS.
  • CI jobs authenticate with OIDC/JWT claims, not stored tokens.
  • Kubernetes workloads use the Kubernetes auth method plus Injector, CSI or VSO.
  • Choose the delivery method by how your app consumes secrets.

Next: Project: A Secure Web App Workflow