Have the following tools installed:
- kind (creates throw-away K8s clusters in containers)
- kubectl (K8s CLI)
- helm (K8s "package manager")
- helmfile (Wrapper for advanced usage of helm)
- vault (Vault Binary including CLI)
You will also need a container runtime for kind, like:
This demo is tested with Podman Desktop on MacOS, but should also run on any other OS with docker or podman. The container runtime can be run rootless.
Alternatively, if you are using nix, you can just make use of the provided flake.nix included in this repo. It can be used with nix-shell to get an environment with all required prerequisites. Check out the docs for further information.
When using direnv in addition, it will detect the provided .envrc file in this repo. You'll need to allow the usage of the porivided env by direnv allow.
-
Run
kind create cluster --config kind-config.yamlinside this directory to create a K8s cluster. -
Run
helmfile initto ensure all required helm plugins are available and the tool is ready to use. -
Run
helmfile applyinside this directory to install all required dependencies for the environment inside the cluster. Make sure the right cluster context is set. -
Wait for all containers to become ready, except the Vault container. Check by
watch kubectl get pods -A.
-
Run
export VAULT_ADDR="http://localhost:8200"to set the URL for thevaultCLI. -
Run
vault operator init -n 1 -t 1to initalize the Vault. IMPORTANT: Save the output for later use! -
Run
vault operator unsealand you will be prompted for a unseal key, which you can find in the saved output of the previous command. -
Run
vault loginand you will be prompted fo a token. Use the root token provided in the saved output.
Run all following commands inside the directory vault-tf-config.
-
Run
terraform init. -
Run
terraform apply -auto-approve.
Check out https://localhost:8200 and login with the root token from the previous steps, if you want to inspect the configuration from the Vault UI.
Check out the resources inside the directors examples/external-secrets-operator. Run all following commands from this directory.
-
Run
kubectl apply -f 00-serviceaccount.ymlto create a ServiceAccount the ESO will use to authenticate to Vault. -
Run
kubectl apply -f 01-secret-store.ymlto create a SecretStore pointing to the KVv2 Enginekv. It will authenticate using the previously created ServiceAccount. -
Run
kubectl get secretstore -n eso demo-secret-storeto inspect if the SecretStore is valid. -
Run
kubectl get secrets -n esoto proof the Secretdemo-secretdoes not already exist. -
Run
kubectl apply -f 02-external-secret.ymlto create an ExternalSecret which the ESO will use to retrieve secret data from the Vault and store it in a K8s Secret. -
Run
kubectl get secrets -n eso demo-secret -o yamlto check the generated Secret.
Check out the resources inside the directors examples/vault-csi-provider. Run all following commands from this directory.
-
Run
kubectl apply -f 00-serviceaccount.ymlto create a ServiceAccount the CSI Provider will use to authenticate to Vault. -
Run
kubectl apply -f 01-secret-provider-class.ymlto create a SecretProviderClass pointing to the KVv2 Enginekvand referencing the requested secret data. It will authenticate using the previously created ServiceAccount. -
Run
kubectl apply -f 02-pod.ymlto create an Pod using the previously created SecretProviderClass. -
Run
kubectl exec -n csi demo-pod -- cat /mnt/secrets-store/footo inspect the created file inside the Pod.
Check out the resources inside the directors examples/vault-agent-injector. Run all following commands from this directory.
-
Run
kubectl apply -f 00-serviceaccount.ymlto create a ServiceAccount the Vault Agent will use to authenticate to Vault. -
Run
kubectl apply -f 02-pod.ymlto create an Pod. All required information about which secret data to retrieve and how to authenticate is stored within annotations. -
Run
kubectl exec -n vai demo-pod -- cat /vault/secrets/footo inspect the created file inside the Pod.
Check out the resources inside the directors examples/vault-secrets-webhook. Run all following commands from this directory.
-
Run
kubectl apply -f 00-serviceaccount.ymlto create a ServiceAccountvault-env(injected by the webhook) will use to authenticate to Vault. -
Run
kubectl apply -f 01-pod.ymlto create an Pod. All required information about which secret data to retrieve and how to authenticate is stored within annotations. The webhook will use this information to alter the Pod on creation. -
Run
kubectl get pod -n vswh demo-pod -o yamlto check how the webhook altered the Pod. -
Run
kubectl logs -n vswh demo-podto check the outputs of this Pod. It is configured to print out the environment variables which should contain the secrets.
- Inspect the logs of the installed components.
- Change the secret data inside Vault and see if it propagates. This should work for all solutions except the Webhook.
- Delete the ExternalSecret and check if the Secret is deleted.
- Change the SecretProviderClass and check if the changes are reflected within the Pod. Recreate the Pod.
If you ran into any issue during this demo, feel free to contact me or raise an issue on this repo.