Secrets Management with HashiCorp Vault
Module Overview
Duration: 25 minutes
Format: Hands-on lab
Audience: Platform Engineers, Security Engineers, IT Operations
Console Access
-
Username:
{openshift_cluster_admin_username} -
Password:
{openshift_cluster_admin_password} -
Console: {openshift_cluster_console_url}[window=blank]
| We recommend using the OCP Console tab within this Showroom interface as it is easier to follow along. |
Learning Objectives
By the end of this module, you will:
-
Deploy HashiCorp Vault on OpenShift using the official Helm chart
-
Configure Vault policies, Kubernetes authentication, and KV secrets
-
Deploy a pod that consumes Vault secrets through the Vault Agent Injector
-
Deploy the External Secrets Operator to fetch secrets from Vault and inject them into Kubernetes Secrets
Why use Vault on Kubernetes?
HashiCorp Vault stores and brokers access to secrets, certificates, and encryption keys. Instead of embedding credentials in container images, Git repositories, or long-lived Kubernetes Secret objects, Vault keeps sensitive data in a dedicated secrets store and issues short-lived access on demand. The official Vault Helm chart installs Vault on Kubernetes or OpenShift and can optionally deploy the Vault Agent Injector for pod secret injection. The injector mutates pod specifications at admission time so an init container can authenticate to Vault and render secrets into a volume before your application starts.
This lab covers one Layer 1 capability from the Layered Zero Trust Validated Pattern—a Red Hat reference architecture built on the Validated Patterns Framework. That pattern stacks components in layers:
-
Validated Patterns Framework — bootstraps the cluster with OpenShift GitOps (Argo CD) and the Validated Patterns Operator; everything above is deployed and reconciled by Argo CD
-
Layer 0 — Foundations — TLS, compliance scanning, advanced cluster management, and runtime security enforcement
-
Layer 1 — Feature Sets — workload identity (SPIFFE/SPIRE), secrets management (Vault + ESO), and user authentication (Keycloak); optionally a private image registry (Quay + NooBaa)
-
Layer 2 — Mapping — the demo application (qtodo) and, optionally, the secure supply chain pipeline (RHTAS, RHTPA, OpenShift Pipelines)
Vault is the secrets store in that stack. You will also use External Secrets Operator (ESO) to sync Vault data into native Kubernetes Secret objects for workloads that expect standard secret references.
|
This lab runs Vault in dev mode (auto-unsealed, root token |
Deploy Vault
The workshop install script deploys the HashiCorp Helm chart into the vault namespace with the Agent Injector enabled.
-
Clone the repo and run the installer from the bastion:
cd ~/ git clone https://github.com/rhpds/openshift-days-ops-showroom.git cd openshift-days-ops-showroom/setup-scripts/vault-config-scripts ./install-vault.sh
The script:
-
Adds the HashiCorp Helm repository and installs chart
hashicorp/vault -
Enables OpenShift integration and dev mode
-
Creates an OpenShift Route for the Vault UI
-
Enables the Vault Agent Injector for pod secret injection
Sample output:
[VAULT] Vault URL: https://vault.apps.<cluster-domain>/
[VAULT] Username: Token
[VAULT] Password: root
-
CTRL + Click on the URL after the script completes to open the Vault UI in a new tab.
Verify the deployment
Confirm the Vault server and injector are running:
oc get pods,svc,route -n vault
You should see the Vault server pod Running, the vault-agent-injector deployment Running, and a Route to the UI.
Configure Vault
In this step, we will configure Vault policies and authentication methods to securely manage and access secrets within the Kubernetes cluster. This configuration ensures that only authorized applications can retrieve sensitive data from Vault.
You will start by using the CLI to configure Vault policies and authentication methods and take a look at the UI to verify the configuration. This happens from within the Vault pod.
-
Connect to the Vault pod:
oc exec -it -n vault vault-0 -- /bin/sh export VAULT_ADDR=http://127.0.0.1:8200 export VAULT_TOKEN=root -
Create a policy file that allows a pod to read secrets:
cat <<EOF > /home/vault/read-policy.hcl path "secret*" { capabilities = ["read"] } EOF -
Apply the policy:
vault policy write read-policy /home/vault/read-policy.hcl -
Next, enable Kubernetes authentication:
vault auth enable kubernetes -
And allow Vault to communicate with the Kubernetes API server via a service account token:
vault write auth/kubernetes/config \ token_reviewer_jwt="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \ kubernetes_host="https://kubernetes.default.svc:443" \ kubernetes_ca_cert=@/var/run/secrets/kubernetes.io/serviceaccount/ca.crt -
Enable the KV v2 secrets engine at
secret/:vault secrets enable -path=secret kv-v2 2>/dev/null || true -
Create role
vault-rolethat binds the policy to service accountvault-serviceaccountin namespacevault:AUD=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token | cut -d. -f2 | base64 -d 2>/dev/null | sed -n 's/.*"aud":\["\([^"]*\)".*/\1/p') vault write auth/kubernetes/role/vault-role \ bound_service_account_names=vault-serviceaccount \ bound_service_account_namespaces=vault \ policies=read-policy \ ttl=1h \ audience="${AUD}"Vault 1.21 validates the service account token
audclaim against the roleaudience. The command above reads the cluster audience from the Vault pod token (typicallyhttps://kubernetes.default.svcon OpenShift). -
Exit the Vault pod shell when configuration is complete:
exit
Create secrets in Vault
We’ve created some roles. Now, let’s create some secrets in Vault.
-
Reconnect to the Vault pod if you exited the shell:
oc exec -it -n vault vault-0 -- /bin/sh export VAULT_ADDR=http://127.0.0.1:8200 export VAULT_TOKEN=root -
Create and verify secrets:
vault kv put secret/login rhos-token=workshop-token-abc123 vault kv put secret/my-first-secret username=workshop-user password=workshop-password vault kv list secretExpected list output includes paths
loginandmy-first-secret:/ $ vault kv put secret/login rhos-token=workshop-token-abc123 == Secret Path == secret/data/login ======= Metadata ======= Key Value --- ----- created_time 2026-06-22T00:33:53.542846195Z custom_metadata <nil> deletion_time n/a destroyed false version 1 / $ vault kv put secret/my-first-secret username=workshop-user password=workshop-password ======= Secret Path ======= secret/data/my-first-secret ======= Metadata ======= Key Value --- ----- created_time 2026-06-22T00:33:53.613507078Z custom_metadata <nil> deletion_time n/a destroyed false version 1 -
Exit the Vault pod shell:
exit
Verify the secrets in the Vault UI
-
Print the Vault UI URL, then open it in a new browser tab (Ctrl+click on Windows/Linux, Cmd+click on Mac):
echo "https://$(oc get route vault -n vault -o jsonpath='{.spec.host}')/" -
Sign in with method Token and token
root. You should see your newly created secrets in the UI. -
Navigate to Secrets Engines → secret.
-
Click Create secret and set:
Path:
my-second-secret
Secret data: add two key/value pairs:-
username=workshop-user-2 -
password=workshop-password-2The Vault path must be exactly
my-second-secret(under thesecretengine). ESO reads from that path and writes a KubernetesSecretnamedmy-second-secret-sync—the names are different on purpose.
-
-
Review the secret information and click Save.
Access secrets from a Kubernetes pod
With Vault configured and secrets stored, you will deploy a sample application in the vault namespace. The Vault Agent Injector mutates the pod to add an init container that authenticates with Kubernetes auth and renders secrets to /vault/secrets/.
The deployment uses annotations to inject secret/login and secret/my-first-secret:
-
vault.hashicorp.com/agent-inject: "true"— enable injection for this pod -
vault.hashicorp.com/role: "vault-role"— Kubernetes auth role to use -
vault.hashicorp.com/agent-inject-secret-<name>— Vault path to fetch -
vault.hashicorp.com/agent-inject-template-<name>— format written to the volume
-
Deploy the Vault Secrets App — a web application that receives injected secrets and is exposed on an OpenShift Route:
cat <<'EOF' | oc apply -f - --- apiVersion: v1 kind: ConfigMap metadata: name: vault-secrets-app-html namespace: vault labels: app: vault-secrets-app data: index.html: | <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Vault Secrets App</title> <style> body { font-family: system-ui, sans-serif; max-width: 40rem; margin: 3rem auto; padding: 0 1rem; color: #151515; } h1 { color: #ee0000; } code { background: #f0f0f0; padding: 0.1rem 0.3rem; border-radius: 3px; } </style> </head> <body> <h1>Vault Secrets App</h1> <p>This demo application authenticates to HashiCorp Vault through the <strong>Vault Agent Injector</strong>.</p> <p>Injected secrets are mounted at <code>/vault/secrets/</code> inside the pod. Use the lab CLI steps to read them—credentials are not displayed in the browser.</p> <p><strong>Status:</strong> Application is running and reachable through the OpenShift Route.</p> </body> </html> --- apiVersion: v1 kind: ServiceAccount metadata: name: vault-serviceaccount namespace: vault labels: app: vault-secrets-app --- apiVersion: apps/v1 kind: Deployment metadata: name: vault-secrets-app namespace: vault labels: app: vault-secrets-app spec: replicas: 1 selector: matchLabels: app: vault-secrets-app template: metadata: labels: app: vault-secrets-app annotations: vault.hashicorp.com/agent-inject: "true" vault.hashicorp.com/agent-inject-status: "update" vault.hashicorp.com/role: "vault-role" vault.hashicorp.com/agent-inject-address: "http://vault.vault.svc:8200" vault.hashicorp.com/agent-inject-containers: "web" vault.hashicorp.com/agent-inject-secret-login: "secret/login" vault.hashicorp.com/agent-inject-template-login: | {{- with secret "secret/login" -}} rhos-token={{ index .Data.data "rhos-token" }} {{- end }} vault.hashicorp.com/agent-inject-secret-my-first-secret: "secret/my-first-secret" vault.hashicorp.com/agent-inject-template-my-first-secret: | {{- with secret "secret/my-first-secret" -}} username={{ .Data.data.username }} password={{ .Data.data.password }} {{- end }} spec: serviceAccountName: vault-serviceaccount volumes: - name: html configMap: name: vault-secrets-app-html containers: - name: web image: docker.io/nginxinc/nginx-unprivileged:1.27-alpine ports: - name: http containerPort: 8080 volumeMounts: - name: html mountPath: /usr/share/nginx/html readOnly: true --- apiVersion: v1 kind: Service metadata: name: vault-secrets-app namespace: vault labels: app: vault-secrets-app spec: selector: app: vault-secrets-app ports: - name: http port: 8080 targetPort: http --- apiVersion: route.openshift.io/v1 kind: Route metadata: name: vault-secrets-app namespace: vault labels: app: vault-secrets-app spec: to: kind: Service name: vault-secrets-app port: targetPort: http tls: termination: edge insecureEdgeTerminationPolicy: Redirect EOF -
Wait for the pod to be ready:
oc get pods -n vault -l app=vault-secrets-app -wPress
Ctrl+Cwhen the pod is2/2Ready (web container + Vault Agent sidecar). -
Open the Vault Secrets App in your browser (Ctrl+click on Windows/Linux, Cmd+click on Mac):
echo "https://$(oc get route vault-secrets-app -n vault -o jsonpath='{.spec.host}')/"You should see the Vault Secrets App welcome page.
-
Read the injected secrets from the pod:
POD=$(oc get pod -n vault -l app=vault-secrets-app -o jsonpath='{.items[0].metadata.name}') oc exec -n vault "${POD}" -c web -- sh -c "cat /vault/secrets/login && echo && cat /vault/secrets/my-first-secret"Expected output:
rhos-token=workshop-token-abc123 username=workshop-user password=workshop-password -
Optional: inspect Agent Injector logs if secrets are missing:
oc logs -n vault "${POD}" -c vault-agent-init oc describe pod -n vault "${POD}"
Nice! You’ve injected the first created secret into a running pod. Next, you will use External Secrets Operator to sync the 2nd secret you created into another workload.
Access secrets with External Secrets Operator
The first deployment used the Vault Agent Injector to render secrets as files under /vault/secrets/. The External Secrets Operator (ESO) offers a different pattern: it reads secrets from Vault and materializes them as native Kubernetes Secret objects. Workloads then consume those secrets through env, envFrom, or volume mounts—the same way they would use any other Kubernetes secret.
Install External Secrets Operator
-
Install ESO from the official Helm chart into the
external-secretsnamespace:helm repo add external-secrets https://charts.external-secrets.io helm repo update external-secrets helm upgrade --install external-secrets external-secrets/external-secrets \ -n external-secrets \ --create-namespace \ --set installCRDs=true \ --wait --timeout 10m -
Confirm the operator is running:
oc get pods -n external-secrets
You should see the external-secrets deployment pod in Running state.
Configure ESO to sync from Vault
ESO reads the my-second-secret you created in the Vault UI and syncs it into a Kubernetes Secret named my-second-secret-sync.
In dev mode, ESO authenticates to Vault with the root token stored in a Kubernetes Secret. A SecretStore defines how to reach Vault; an ExternalSecret defines which Vault paths to copy and the name of the target Kubernetes Secret.
-
Apply the token,
SecretStore, andExternalSecretin thevaultnamespace:cat <<'EOF' | oc apply -f - --- apiVersion: v1 kind: Secret metadata: name: vault-token namespace: vault type: Opaque stringData: token: root --- apiVersion: external-secrets.io/v1 kind: SecretStore metadata: name: vault-backend namespace: vault spec: provider: vault: server: "http://vault.vault.svc:8200" path: "secret" version: "v2" auth: tokenSecretRef: name: vault-token key: token --- apiVersion: external-secrets.io/v1 kind: ExternalSecret metadata: name: sync-my-second-secret namespace: vault spec: refreshInterval: 1h secretStoreRef: name: vault-backend kind: SecretStore target: name: my-second-secret-sync creationPolicy: Owner data: - secretKey: username remoteRef: key: my-second-secret property: username - secretKey: password remoteRef: key: my-second-secret property: password EOF -
Verify ESO created the Kubernetes
Secret:oc get externalsecret,secretstore -n vault oc get externalsecret sync-my-second-secret -n vault -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}{"\n"}' oc get secret my-second-secret-sync -n vault -o jsonpath='{.data.username}{"\n"}' | base64 -d && echo
Expected: ExternalSecret Ready status is True, and the decoded username is workshop-user-2.
If status is SecretSyncedError and my-second-secret-sync was not created, confirm my-second-secret in the Vault UI includes both username and password, then inspect the error:
|
oc describe externalsecret sync-my-second-secret -n vault | tail -20
oc get externalsecret sync-my-second-secret -n vault -w
Press Ctrl+C when READY is True, then re-run the verification commands above.
Deploy a second application using the synced Secret
Deploy a second workload that reads credentials from the Kubernetes Secret ESO created—not from Vault Agent files.
-
Deploy the application:
cat <<'EOF' | oc apply -f - apiVersion: apps/v1 kind: Deployment metadata: name: eso-vault-test namespace: vault labels: app: eso-read-vault-secret spec: replicas: 1 selector: matchLabels: app: eso-read-vault-secret template: metadata: labels: app: eso-read-vault-secret spec: containers: - name: app image: registry.access.redhat.com/ubi9/ubi-minimal:latest command: ["sleep", "infinity"] env: - name: USERNAME valueFrom: secretKeyRef: name: my-second-secret-sync key: username - name: PASSWORD valueFrom: secretKeyRef: name: my-second-secret-sync key: password EOFoc get pods -n vault -l app=eso-read-vault-secret -wPress
Ctrl+Cwhen the pod is1/1Ready.
-
Confirm the pod received the synced credentials:
ESO_POD=$(oc get pod -n vault -l app=eso-read-vault-secret -o jsonpath='{.items[0].metadata.name}') oc exec -n vault "${ESO_POD}" -c app -- sh -c 'echo "username=${USERNAME}" && echo "password=${PASSWORD}"'
Expected output:
username=workshop-user-2
password=workshop-password-2
Perfect! You’ve deployed a second workload that reads credentials from the Kubernetes Secret ESO created—not from the Vault Agent Injector. The ESO is an alternative way to consume secrets in a workload and can be used with your preferred secrets store.
Clean up
When you finish this module, run the workshop cleanup script from the bastion. It removes External Secrets Operator, all demo applications, Vault, and related namespaces.
-
Run the cleanup script:
cd ~/openshift-days-ops-showroom/setup-scripts/vault-config-scripts ./cleanup-vault-lab.sh
Expected output ends with [vault-lab-cleanup] Done. and no vault or external-secrets namespaces remaining.
What you learned
-
Vault on OpenShift centralizes secrets outside etcd while the Agent Injector delivers them to pods at runtime.
-
Kubernetes auth ties Vault access to a namespace and service account (
vault-serviceaccount→ rolevault-role). -
The Vault Agent Injector writes secrets to files under
/vault/secrets/inside the pod. -
External Secrets Operator syncs Vault data into native Kubernetes
Secretobjects for use withenv,envFrom, or volume mounts. -
You deployed two consumption patterns: Agent Injector (
vault-secrets-app) and ESO-backed Kubernetes Secrets (eso-vault-test).
Wrap up
Great job! You installed Vault, configured Kubernetes authentication, consumed secrets with the Agent Injector, and synced secrets into Kubernetes with External Secrets Operator.
If you want to learn more about the Zero-trust architecture, check out the Layered Zero Trust Validated Pattern on GitHub.
Good luck with the next module!


