vault-secrets-webhook

by Helm

Helm chartv1.19.0App 1.19.0

A Helm chart that deploys a mutating admission webhook that configures applications to request secrets from Vault

About this chart

Vault Secrets webhook

This chart will install a mutating admission webhook, that injects an executable to containers in Pods which than can request secrets from Vault through environment variable definitions. Also, it can inject statically into ConfigMaps, Secrets, and CustomResources.

Before you start

Before you install this chart you must create a namespace for it, this is due to the order in which the resources in the charts are applied (Helm collects all of the resources in a given Chart and it's dependencies, groups them by resource type, and then installs them in a predefined order (see here - Helm 2.10).

The MutatingWebhookConfiguration gets created before the actual backend Pod which serves as the webhook itself, Kubernetes would like to mutate that pod as well, but it is not ready to mutate yet (infinite recursion in logic).

Using External Vault Instances

You will need to add the following annotations to the resources that you wish to mutate:

vault.security.banzaicloud.io/vault-addr: https://[URL FOR VAULT]
vault.security.banzaicloud.io/vault-path: [Auth path]
vault.security.banzaicloud.io/vault-role: [Auth role]
vault.security.banzaicloud.io/vault-skip-verify: "true" # Container is missing Trusted Mozilla roots too.

Be mindful how you reference Vault secrets itself. For KV v2 secrets, you will need to add the /data/ to the path of the secret.

PS C:\> vault kv get kv/rax/test
====== Metadata ======
Key              Value
---              -----
created_time     2019-09-21T16:55:26.479739656Z
deletion_time    n/a
destroyed        false
version          1

=========== Data ===========
Key                    Value
---                    -----
MYSQL_PASSWORD         3xtr3ms3cr3t
MYSQL_ROOT_PASSWORD    s3cr3t

The secret shown above is referenced like this:

vault:[ENGINE]/data/[SECRET_NAME]#KEY
vault:kv/rax/data/test#MYSQL_PASSWORD

If you want to use a specific key version, you can append it after the key so it becomes like this:

vault:kv/rax/data/test#MYSQL_PASSWORD#1

Omitting the version will tell Vault to pull the latest version.

Installing the Chart

In case of the K8s version is lower than 1.15 the namespace where you install the webhook must have a label of name with the namespace name as the label value, so the namespaceSelector in the MutatingWebhookConfiguration can skip the namespace of the webhook, so no self-mutation takes place. If the K8s version is 1.15 at least, the default objectSelector will prevent the self-mutation (you don't have to configure anything) and you are free to install to any namespace of your choice..

# You have to do this only in case you are not using Helm 3.2 or later and Kubernetes 1.15 or later.
WEBHOOK_NS=${WEBHOOK_NS:-vswh}
kubectl create namespace "${WEBHOOK_NS}"
kubectl label ns "${WEBHOOK_NS}" name="${WEBHOOK_NS}"
$ helm repo add banzaicloud-stable https://kubernetes-charts.banzaicloud.com/
$ helm repo update
$ helm upgrade --namespace vswh --install vswh banzaicloud-stable/vault-secrets-webhook --create-namespace

NOTE: --wait is sometimes necessary because of some Helm timing issues, please see this issue.

Openshift 4.3

For security reasons, the runAsUser must be in the range between 1000570000 and 1000579999. By setting the value of securityContext.runAsUser to "", OpenShift chooses a valid User.

$ helm upgrade --namespace vswh --install vswh banzaicloud-stable/vault-secrets-webhook --set-string securityContext.runAsUser="" --create-namespace

About GKE Private Clusters

When Google configures the control plane for private clusters, they automatically configure VPC peering between your Kubernetes cluster’s network in a separate Google managed project.

The auto-generated rules only open ports 10250 and 443 between masters and nodes. This means that to use the webhook component with a GKE private cluster, you must configure an additional firewall rule to allow your masters CIDR to access your webhook pod using the port 8443.

You can read more information on how to add firewall rules for the GKE control plane nodes in the GKE docs.

Configuration

The following tables lists configurable parameters of the vault-secrets-webhook chart and their default values:

ParameterDescriptionDefault
affinityaffinities to use{}
debugdebug logs for webhookfalse
image.pullPolicyimage pull policyIfNotPresent
image.repositoryimage repo that contains the admission serverghcr.io/banzaicloud/vault-secrets-webhook
image.tagimage tag.Chart.AppVersion
image.imagePullSecretsimage pull secrets for private repositories[]
vaultEnv.repositoryimage repo that contains the vault-env containerghcr.io/banzaicloud/vault-env
vaultEnv.tagimage tag for the vault-env container.Chart.AppVersion
namespaceSelectornamespace selector to use, will limit webhook scope{}
objectSelectorobject selector to use, will limit webhook scope (K8s version 1.15+){}
nodeSelectornode selector to use{}
labelsextra labels to add to the deployment and pods{}
podAnnotationsextra annotations to add to pod metadata{}
replicaCountnumber of replicas2
resourcesresources to request{}
service.externalPortwebhook service external port443
service.namewebhook service namevault-secrets-webhook
service.typewebhook service typeClusterIP
tolerationstolerations to add[]
topologySpreadConstraintstopologySpreadConstraints to add{}
rbac.psp.enableduse pod security policyfalse
rbac.authDelegatorRole.enabledbind system:auth-delegator to the ServiceAccountfalse
env.VAULT_IMAGEvault imagevault:1.6.2
env.VAULT_ENV_CPU_REQUESTcpu requests for init-containers vault-env and copy-vault-env50m
env.VAULT_ENV_MEMORY_REQUESTmemory requests for init-containers vault-env and copy-vault-env64Mi
env.VAULT_ENV_CPU_LIMITcpu limits for init-containers vault-env and copy-vault-env250m
env.VAULT_ENV_MEMORY_LIMITmemory limits for init-containers vault-env and copy-vault-env64Mi
env.VAULT_ENV_LOG_SERVERdefine remote log server for vault-env``
initContainerscontainers, which are run before the app containers are started[]
volumesextra volume definitions[]
volumeMountsextra volume mounts[]
configMapMutationenable injecting values from Vault to ConfigMapsfalse
secretsMutationenable injecting values from Vault to Secretstrue
deployment.strategyrolling strategy for webhook deployment{}
pods.objectSelectorobject selector to use - ( overrides root ObjectSelector ){}
pods.namespaceSelectornamespace selector to use - ( overrides root namespaceSelector ){}
secrets.objectSelectorobject selector to use - ( overrides root ObjectSelector ){}
secrets.namespaceSelectornamespace selector to use - ( overrides root namespaceSelector ){}
configMaps.objectSelectorobject selector to use - ( overrides root ObjectSelector ){}
configMaps.namespaceSelectornamespace selector to use - ( overrides root namespaceSelector ){}
customResources.objectSelectorobject selector to use - ( overrides root ObjectSelector ){}
customResources.namespaceSelectornamespace selector to use - ( overrides root namespaceSelector ){}
customResourceMutationslist of CustomResources to inject values from Vault[]
podDisruptionBudget.enabledenable PodDisruptionBudgettrue
podDisruptionBudget.minAvailablerepresents the number of Pods that must be available (integer or percentage)1
podDisruptionBudget.maxUnavailablerepresents the number of Pods that can be unavailable (integer or percentage)
certificate.generateshould a new CA and TLS certificate be generated for the webhooktrue
certificate.useCertManagershould request cert-manager for getting a new CA and TLS certificatefalse
certificate.servingCertificateshould use an already externally defined Certificate by cert-managernull
certificate.ca.crtBase64 encoded CA certificate``
certificate.server.tls.crtBase64 encoded TLS certificate signed by the CA``

|

Deploy vault-secrets-webhook with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has vault-secrets-webhook on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartvault-secrets-webhook is pinned at v1.19.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply