Expose vault secrets as environment variables in newly spawned process.
Secrets are frequently poorly maintained (never rotated, copied across developers and environments, etc, etc), so the intent of this utility is to simplify secrets handling using vault as primary and the only secrets storage.
There are two primary use cases:
- Securely provide an environment for ops and devs
- Provide secrets to kubernetes applications
govaultenv program arguments...Complete workflow with interactive shell spawned and vault secret exposed as environment variables:
export VAULT_ADDR=...
vault login -method=okta username=...
govaultenv -verbose=debug /bin/bashbrew tap jamhed/govaultenv https://github.com/jamhed/govaultenv
brew install govaultenvEither do:
vault loginwith one of supported auth schema (govaultenv tries to read~/.vault-tokenfile)- export
VAULT_TOKENenvironment variable with valid TOKEN - provide token value with
-tokencommand line flag - provide kubernetes token and authentication path, see below
It traverses all environment variables looking for prefix (VAULT_ by default), and then if environment variable vaule is in format:
secret-path#key, then secret is fetched from vault, and new environment variable without prefix is set to secret key value, e.g. if you have a secretteam/solrwith keypassword, and you have an environment variableVAULT_SOLR_PASS=team/solr#passworddefined, then spawned process has new environment variableSOLR_PASSset to the value of the corresponding vault secret.secret-path#key:local-path, then secret key is written to local filelocal-path, and all written secrets are deleted upon completion of calling program.secret-path, then all keys are exposed as generated environment variable named asvariableName_keyName, e.g. if you have it asVAULT_SOLR=team/solr, and solr secret has keysusernameandpassword, then following environment variables are generated:SOLR_USERNAMEandSOLR_PASSWORD.
There are command-line flags to control this behavior:
uppercase, true by default, set it to false to keep generated environment variable name as it isstripname, false by default, set it to true to strip the original environment variable name from generated one
Vault has a useful feature called wrapped tokens that allows to securely pass secrets (including tokens) around,
and govaultenv has an option unwrap to support it.
WRAPPED_TOKEN=$(vault token create -field=wrapping_token -wrap-ttl=1h -ttl=1h)
govaultenv -unwrap -token $WRAPPED_TOKEN env
Here wrapped token can be used only once, has limited time-to-live (one hour), and underlying token has also limited time-to-live (one hour).
Have govaultenv binary installed locally, have VAULT_ADDR and VAULT_TOKEN environment variables set, and expose some vault secret, e.g. VAULT_SOLR_PASS=team/solr#pass, and then:
govaultenv -append=false envYou should be able to see a secret value as environment variable value.
Make sure you have govaultenv binary residing in the image.
Start your image in proper namespace with proper service account, e.g.
kubectl run --generator=run-pod/v1 tmp --rm -i --tty --serviceaccount=vault-auth --image jamhed/govaultenvInside kubernetes pod it's possible to use service account vault authentication schema:
export VAULT_SOLR_PASS=team/solr#pass
govaultenv -kubeauth default@kubernetes -append=false env
SOLR_PASS=...How to spawn an interactive shell with secret variable keys pulled out of vault:
export VAULT_GOVC=team/env
govaultenv /bin/bash- https://github.com/mumoshu/aws-secret-operator
- https://github.com/hashicorp/envconsul
- https://github.com/channable/vaultenv
- hashicorp/vault#7364
- https://github.com/sethvargo/vault-kubernetes-authenticator
- https://github.com/tuenti/secrets-manager
- https://github.com/DaspawnW/vault-crd
- https://github.com/Talend/vault-sidecar-injector
- https://github.com/hashicorp/consul-template
- https://github.com/ricoberger/vault-secrets-operator