An Open Source Proof of Concept demonstrating secret injection into Kubernetes Pods using HashiCorp Vault Agent Injector.
This Proof of Concept demonstrates how HashiCorp Vault Agent Injector injects secrets into Kubernetes Pods without embedding sensitive information inside container images.
A simple Python HTTP server validates that the injected secret is available at runtime.
This Proof of Concept demonstrates how to:
- Deploy HashiCorp Vault on Kubernetes.
- Enable Vault Agent Injector.
- Store secrets inside Vault.
- Authenticate Kubernetes workloads.
- Inject secrets into Pods automatically.
- Access injected secrets from a Python application.
- Kubernetes Cluster
- kubectl
- Helm 3
- Docker
- Vault CLI (optional)
Add the Helm repository:
helm repo add hashicorp https://helm.releases.hashicorp.com
helm repo updateInstall Vault:
helm install vault hashicorp/vault \
--set "server.dev.enabled=true" \
--set "injector.enabled=true"Verify that Vault is running:
kubectl get podsExpected output:
vault-0
vault-agent-injector-xxxxx
Open a shell inside the Vault Pod:
kubectl exec -it vault-0 -- shVerify Vault status:
vault statusEnable the KV Secrets Engine:
vault secrets enable -path=secret kv-v2Create the secret:
vault kv put secret/python-vault/realm \
realm_xml='<realm><users><user><name>john</name></user></users></realm>'Create the Vault policy:
vault policy write python-vault-read-policy - <<EOF
path "secret/data/python-vault/*" {
capabilities = ["read"]
}
EOFEnable Kubernetes authentication:
vault auth enable kubernetesConfigure Kubernetes authentication:
vault write auth/kubernetes/config \
kubernetes_host="https://kubernetes.default.svc:443" \
kubernetes_ca_cert=@/var/run/secrets/kubernetes.io/serviceaccount/ca.crtCreate the Kubernetes role:
vault write auth/kubernetes/role/python-vault-policy-role \
bound_service_account_names=default \
bound_service_account_namespaces=default \
policies=python-vault-read-policy \
ttl=1hExit the Vault Pod:
exitBuild the Docker image:
docker build -t python-vault-validation:1.0.0 .If using Kind:
kind load docker-image python-vault-validation:1.0.0Deploy the application:
kubectl apply -f python-app-deployment.yamlVerify that the Pod is running:
kubectl get podsExpected output:
python-vault-app-deployment-xxxxx 2/2 Running
Verify the injected secret:
kubectl exec deploy/python-vault-app-deployment \
-c python-vault-container \
-- ls -la /vault/secretsExpected output:
realm.xml
Display the injected secret:
kubectl exec deploy/python-vault-app-deployment \
-c python-vault-container \
-- cat /vault/secrets/realm.xmlForward the application:
kubectl port-forward svc/python-vault-app-service 8080:8080Verify the health endpoint:
curl http://localhost:8080/_pingExpected output:
{
"status": "ok",
"app": "python-vault-validation"
}Verify the injected secret:
curl http://localhost:8080/secret-requiredExpected output:
{
"path": "/vault/secrets/realm.xml",
"exists": true,
"size_bytes": 60,
"first_80_chars": "<realm><users><user><name>john</name></user></users></realm>"
}After completing this Proof of Concept, you will understand how to:
- Install HashiCorp Vault using Helm.
- Enable Vault Agent Injector.
- Configure Kubernetes authentication.
- Create Vault policies and roles.
- Inject secrets into Kubernetes Pods.
- Consume injected secrets from a Python application.
- Apply Kubernetes secret management best practices.
Authentication backend not enabled:
vault auth enable kubernetesBackend configuration missing:
vault write auth/kubernetes/config \
kubernetes_host="https://kubernetes.default.svc:443" \
kubernetes_ca_cert=@/var/run/secrets/kubernetes.io/serviceaccount/ca.crtPod stuck during initialization:
kubectl logs deploy/python-vault-app-deployment \
-c vault-agent-initVerify the secret inside Vault:
vault kv get secret/python-vault/realmDelete the application:
kubectl delete -f python-app-deployment.yamlUninstall Vault:
helm uninstall vault- https://developer.hashicorp.com/vault
- https://developer.hashicorp.com/vault/docs/platform/k8s/injector
OpenMind Systems Lab is an independent French non-profit association dedicated to research, experimental development and technical benchmarking in Cloud Native technologies.
Our mission is to produce practical, reproducible and educational Open Source Proofs of Concept covering Kubernetes, Platform Engineering, Distributed Messaging, Infrastructure Security and Artificial Intelligence.
GitHub Organization:
https://github.com/openmind-systems-lab
Made with β€οΈ by OpenMind Systems Lab

