vault-k8s is HashiCorp's Kubernetes integration that automatically injects Vault Agent containers into pods via a mutating admission webhook, enabling applications to seamlessly access HashiCorp Vault secrets without code changes by intercepting pod creation, reading annotations, and modifying pod specifications to include secret retrieval and rendering capabilities.
Pull the latest version of this image from the Ghost registry. Pulling requires authentication — generate a token and run docker login first (see Authentication below).
The Ghost catalog is public to browse, but pulling images requires an account. Generate a pull token below (or from your Account → Tokens page) — you'll get a ready-to-paste docker login command, then docker pull works.
The username is generated automatically (it looks like robot$<project>+<auto-id>, not the name you typed) and is included in the docker login command above. The secret is shown only once when you create the token.
All Ghost images are signed with cosign. Verifying the signature before deployment ensures the image has not been tampered with.
Install cosign via brew install cosign or download from the Sigstore releases page.
Reference this image in your Dockerfile as a base layer:
This is a vendor-built FIPS-enabled image: its cryptography runs on FIPS 140-3 validated modules configured by the upstream vendor. You can inspect the image metadata:
| Standard | FIPS 140-3 |
| Crypto module | Vendor-configured validated modules |
| Cryptography | Validated modules only |
| Use case | Government, regulated industries, compliance workloads |
All examples in this guide use the public image. If you've mirrored the repository for your own use (for example, to your Docker Hub namespace), update your commands to reference the mirrored image instead of the public one.
For example:
registry.ghost-prod.alphabravo.io/ghost-base/vault-k8s:<tag><your-namespace>/dhi-vault-k8s:<tag>For the examples, you must first use docker login registry.ghost-prod.alphabravo.io to authenticate to the registry to pull the images.
Vault K8s is designed to work with HashiCorp Vault in Kubernetes environments. It provides the agent-inject functionality that automatically injects secrets from Vault into pods.
First, deploy a Vault server in dev mode for testing. In production, you would use a properly configured Vault instance.
# Create namespace
kubectl create namespace vault
# Deploy Vault server in dev mode
cat > vault-server.yaml << 'EOF'
apiVersion: v1
kind: ServiceAccount
metadata:
name: vault
namespace: vault
---
apiVersion: v1
kind: Service
metadata:
name: vault
namespace: vault
spec:
ports:
- name: vault
port: 8200
targetPort: 8200
selector:
app: vault
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: vault
namespace: vault
spec:
serviceName: vault
replicas: 1
selector:
matchLabels:
app: vault
template:
metadata:
labels:
app: vault
spec:
serviceAccountName: vault
containers:
- name: vault
image: hashicorp/vault:1.21.1
args:
- server
- -dev
- -dev-root-token-id=root
- -dev-listen-address=0.0.0.0:8200
env:
- name: VAULT_DEV_ROOT_TOKEN_ID
value: "root"
- name: VAULT_ADDR
value: "http://127.0.0.1:8200"
ports:
- containerPort: 8200
name: vault
readinessProbe:
httpGet:
path: /v1/sys/health
port: 8200
initialDelaySeconds: 5
EOF
kubectl apply -f vault-server.yaml
# Wait for Vault to be ready
kubectl wait --for=condition=ready pod -l app=vault -n vault --timeout=60s
The vault-agent-injector operates as a Kubernetes Mutating Admission Webhook. Kubernetes requires all admission webhooks to use HTTPS/TLS for security - this is not optional, it's a Kubernetes requirement.
Let's generate TLS certificates and deploy the Vault K8s agent injector.
# Generate TLS certificates for the webhook
SERVICE_NAME=vault-agent-injector-svc
NAMESPACE=vault
SECRET_NAME=vault-agent-injector-certs
TMPDIR=$(mktemp -d)
openssl genrsa -out ${TMPDIR}/tls.key 2048
openssl req -new -x509 -key ${TMPDIR}/tls.key -out ${TMPDIR}/tls.crt -days 365 \
-subj "/CN=${SERVICE_NAME}.${NAMESPACE}.svc" \
-addext "subjectAltName=DNS:${SERVICE_NAME}.${NAMESPACE}.svc,DNS:${SERVICE_NAME}.${NAMESPACE}.svc.cluster.local"
kubectl create secret tls ${SECRET_NAME} \
--cert=${TMPDIR}/tls.crt \
--key=${TMPDIR}/tls.key \
-n ${NAMESPACE}
rm -rf ${TMPDIR}
# Deploy Vault K8s Agent Injector with DHI
cat > vault-agent-injector.yaml << 'EOF'
apiVersion: v1
kind: ServiceAccount
metadata:
name: vault-agent-injector
namespace: vault
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: vault-agent-injector
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- list
- watch
- apiGroups:
- admissionregistration.k8s.io
resources:
- mutatingwebhookconfigurations
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: vault-agent-injector
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: vault-agent-injector
subjects:
- kind: ServiceAccount
name: vault-agent-injector
namespace: vault
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: vault-agent-injector
namespace: vault
labels:
app: vault-agent-injector
spec:
replicas: 1
selector:
matchLabels:
app: vault-agent-injector
template:
metadata:
labels:
app: vault-agent-injector
spec:
serviceAccountName: vault-agent-injector
containers:
- name: vault-agent-injector
image: <your-namespace>/vault-k8s:<tag>
args:
- agent-inject
- -vault-address=http://vault.vault.svc:8200
- -listen=:8080
- -tls-cert-file=/etc/webhook/certs/tls.crt
- -tls-key-file=/etc/webhook/certs/tls.key
ports:
- name: https
containerPort: 8080
volumeMounts:
- name: webhook-certs
mountPath: /etc/webhook/certs
readOnly: true
volumes:
- name: webhook-certs
secret:
secretName: vault-agent-injector-certs
---
apiVersion: v1
kind: Service
metadata:
name: vault-agent-injector-svc
namespace: vault
spec:
ports:
- name: https
port: 443
targetPort: 8080
selector:
app: vault-agent-injector
EOF
kubectl apply -f vault-agent-injector.yaml
If you have an existing MutatingWebhookConfiguration, update it with the new CA bundle:
# Update the webhook with the new CA certificate
CA_BUNDLE=$(kubectl get secret vault-agent-injector-certs -n vault -o jsonpath='{.data.tls\.crt}')
kubectl patch mutatingwebhookconfiguration vault-agent-injector-cfg --type='json' -p="[
{
\"op\": \"replace\",
\"path\": \"/webhooks/0/clientConfig/caBundle\",
\"value\": \"${CA_BUNDLE}\"
}
]" 2>/dev/null || echo "No existing webhook configuration to update"
kubectl get pods -n vault
kubectl logs -n vault -l app=vault-agent-injector
Set up Kubernetes authentication for Vault.
# Enable Kubernetes auth in Vault
kubectl exec -n vault vault-0 -- sh -c 'VAULT_TOKEN=root vault auth enable kubernetes'
# Configure Kubernetes auth
KUBE_HOST=$(kubectl exec -n vault vault-0 -- sh -c 'echo $KUBERNETES_SERVICE_HOST')
KUBE_PORT=$(kubectl exec -n vault vault-0 -- sh -c 'echo $KUBERNETES_SERVICE_PORT')
kubectl exec -n vault vault-0 -- sh -c "VAULT_TOKEN=root vault write auth/kubernetes/config \
kubernetes_host='https://${KUBE_HOST}:${KUBE_PORT}' \
disable_local_ca_jwt=false"
# Create a test secret
kubectl exec -n vault vault-0 -- sh -c 'VAULT_TOKEN=root vault kv put secret/database/config \
username="db-user" \
password="db-password"'
# Create a policy
cat > /tmp/webapp-policy.hcl << 'EOF'
path "secret/data/database/config" {
capabilities = ["read"]
}
EOF
kubectl cp /tmp/webapp-policy.hcl vault/vault-0:/tmp/webapp-policy.hcl
kubectl exec -n vault vault-0 -- sh -c 'VAULT_TOKEN=root vault policy write webapp /tmp/webapp-policy.hcl'
# Create service account for the application
kubectl create serviceaccount webapp -n default
# Create role
kubectl exec -n vault vault-0 -- sh -c 'VAULT_TOKEN=root vault write auth/kubernetes/role/webapp \
bound_service_account_names=webapp \
bound_service_account_namespaces=default \
policies=webapp \
ttl=24h'
Annotate your application pods to automatically inject Vault secrets.
cat > app-with-secrets.yaml << 'EOF'
apiVersion: v1
kind: Pod
metadata:
name: webapp
namespace: default
annotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/role: "webapp"
vault.hashicorp.com/agent-inject-secret-database-config: "secret/data/database/config"
vault.hashicorp.com/agent-inject-template-database-config: |
{{- with secret "secret/data/database/config" -}}
postgresql://{{ .Data.data.username }}:{{ .Data.data.password }}@postgres:5432/mydb
{{- end }}
spec:
serviceAccountName: webapp
containers:
- name: webapp
image: nginx:latest
ports:
- containerPort: 8080
EOF
kubectl apply -f app-with-secrets.yaml
Once the pod is running, verify the secret was injected:
# Wait for pod to be ready
kubectl wait --for=condition=ready pod webapp -n default --timeout=60s
# Check the injected secret
kubectl exec webapp -n default -c webapp -- cat /vault/secrets/database-config
You should see the rendered template with the actual credentials:
postgresql://db-user:db-password@postgres:5432/mydb
| Feature | Standard Vault K8s | Docker Hardened Vault K8s |
|---|---|---|
| Security | Standard minimal base | Hardened base with security patches |
| Shell access | No shell in runtime variants | No shell in runtime variants |
| Package manager | No package manager in runtime variants | No package manager in runtime variants |
| User | Runs as vault user | Runs as nonroot user (UID 65532) |
| Image size (runtime) | ~35 MB (uncompressed) | ~12 MB (uncompressed) - 67% smaller |
| Attack surface | Minimal binaries and libraries | Further minimized with additional hardening |
| Debugging | Use Docker Debug or kubectl debug | Use Docker Debug or kubectl debug |
Ghost hardened images prioritize security through minimalism:
The hardened images intended for runtime don't contain a shell nor any tools for debugging. Common debugging methods for applications built with Ghost hardened images include:
kubectl debugDocker Debug provides a shell, common debugging tools, and lets you install other tools in an ephemeral, writable layer that only exists during the debugging session.
For Kubernetes environments, you can use kubectl debug:
kubectl debug -n vault pod/<pod-name> -it --image=busybox --target=vault-agent-injector
Or use Docker Debug if you have access to the node:
docker debug <container-id>
Ghost hardened images come in different variants depending on their intended use.
Runtime variants are designed to run your application in production. These images are intended to be used either directly or as the FROM image in the final stage of a multi-stage build. These images typically:
Build-time variants typically include dev in the variant name and are intended for use in the first stage of a
multi-stage Dockerfile. These images typically:
FIPS variants include fips in the variant name and tag. They come in both runtime and build-time variants. These
variants use cryptographic modules that have been validated under FIPS 140, a U.S. government standard for secure
cryptographic operations. For example, usage of MD5 fails in FIPS variants.
The Vault K8s Ghost hardened image is available in all variant types: runtime, dev, FIPS, and FIPS-dev. To view the image variants and get more information about them, select the Tags tab for this repository, and then select a tag.
To migrate your application to a Ghost hardened image, you must update your Dockerfile. At minimum, you must update the base image in your existing Dockerfile to a Ghost hardened image. This and a few other common changes are listed in the following table of migration notes:
| Item | Migration note |
|---|---|
| Base image | Replace your base images in your Dockerfile with a Ghost hardened image. |
| Non-root user | By default, images run as the nonroot user. Ensure that necessary files and directories are accessible to the nonroot user. |
| TLS certificates | Ghost hardened images contain standard TLS certificates by default. There is no need to install TLS certificates. |
| Ports | Hardened images run as a nonroot user by default. As a result, applications in these images can't bind to privileged ports (below 1024) when running in Kubernetes or in Docker Engine versions older than 20.10. |
| Entry point | Ghost hardened images may have different entry points than images such as Docker Official Images. Inspect entry points for Ghost hardened images and update your Dockerfile if necessary. |
The following steps outline the general migration process.
Find hardened images for your app. A hardened image may have several variants. Inspect the image tags and find the image variant that meets your needs.
Update the base image in your Dockerfile. Update the base image in your application's Dockerfile to the hardened image you found in the previous step.
Verify permissions Since the image runs as nonroot user, ensure that data directories and mounted volumes are accessible to the nonroot user.
The recommended method for debugging applications built with Ghost hardened images is to use Docker Debug to attach to these containers. Docker Debug provides a shell, common debugging tools, and lets you install other tools in an ephemeral, writable layer that only exists during the debugging session.
By default image variants run as the nonroot user. Ensure that necessary files and directories are accessible to the nonroot user. You may need to copy files to different directories or change permissions so your application running as the nonroot user can access them.
Hardened images run as a nonroot user by default. As a result, applications in these images can't bind to privileged ports (below 1024) when running in Kubernetes or in Docker Engine versions older than 20.10.
Ghost hardened images may have different entry points than images such as Docker Official Images. Use docker inspect
to inspect entry points for Ghost hardened images and update your Dockerfile if necessary.