vault

by Helm

Helm chartv1.19.0App 1.19.0

A Helm chart for Vault, a tool for managing secrets

About this chart

Vault Helm Chart

This directory contains a Kubernetes Helm chart to deploy a Vault server. For further details of how are we using Vault read this post.

Prerequisites Details

  • Kubernetes 1.6+

Chart Details

This chart will do the following:

  • Implement a Vault deployment

Please note that a backend service for Vault (for example, Consul) must be deployed beforehand and configured with the vault.config option. YAML provided under this option will be converted to JSON for the final vault config.json file.

Please also note that scaling to more than 1 replicas can be made successfully only with a configured HA Storage backend. By default this chart uses file backend, which is not HA.

See https://www.vaultproject.io/docs/configuration/ for more information.

Installing the Chart

To install the chart, use the following:

helm repo add banzaicloud-stable https://kubernetes-charts.banzaicloud.com
helm install banzaicloud-stable/vault

To install the chart backed with a Consul cluster, use the following:

helm install banzaicloud-stable/vault --set vault.config.storage.consul.address="myconsul-svc-name:8500",vault.config.storage.consul.path="vault"

An alternative values.yaml example using the Amazon S3 backend can be specified using:

vault:
  config:
    storage:
      s3:
        access_key: "AWS-ACCESS-KEY"
        secret_key: "AWS-SECRET-KEY"
        bucket: "AWS-BUCKET"
        region: "eu-central-1"

An alternate example using Amazon custom secrets passed as environment variables to Vault:

# Create an aws secret with your AWS credentials
kubectl create secret generic aws --from-literal=AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID --from-literal=AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY

# Tell the chart to pass these as env vars to Vault and as a file mount if needed
helm install banzaicloud-stable/vault --set "vault.customSecrets[0].secretName=aws" --set "vault.customSecrets[0].mountPath=/vault/aws"

Google Storage and KMS example

You can set up Vault to use Google KMS for sealing and Google Storage for storing your encrypted secrets. See the usage example below:

# Create a google secret with your Secret Account Key file in json fromat.
kubectl create secret generic google --from-literal=GOOGLE_APPLICATION_CREDENTIALS=/etc/gcp/service-account.json --from-file=service-account.json=./service-account.json

# Tell the chart to pass these vars to Vault and as a file mount if needed
helm install banzaicloud-stable/vault \
--set "vault.customSecrets[0].secretName=google" \
--set "vault.customSecrets[0].mountPath=/etc/gcp" \
--set "vault.config.storage.gcs.bucket=[google-bucket-name]" \
--set "vault.config.seal.gcpckms.project=[google-project-id]" \
--set "vault.config.seal.gcpckms.region=[google-kms-region]" \
--set "vault.config.seal.gcpckms.key_ring=[google-kms-key-ring]" \
--set "vault.config.seal.gcpckms.crypto_key=[google-kms-crypto-key]" \
--set "unsealer.args[0]=--mode" \
--set "unsealer.args[1]=google-cloud-kms-gcs" \
--set "unsealer.args[2]=--google-cloud-kms-key-ring" \
--set "unsealer.args[3]=[google-kms-key-ring]" \
--set "unsealer.args[4]=--google-cloud-kms-crypto-key" \
--set "unsealer.args[5]=[google-kms-crypto-key]" \
--set "unsealer.args[6]=--google-cloud-kms-location" \
--set "unsealer.args[7]=global" \
--set "unsealer.args[8]=--google-cloud-kms-project" \
--set "unsealer.args[9]=[google-project-id]" \
--set "unsealer.args[10]=--google-cloud-storage-bucket" \
--set "unsealer.args[11]=[google-bucket-name]"

Vault HA with MySQL backend

You can set up a HA Vault to use MySQL for storing your encrypted secrets. MySQL supports the HA coordination of Vault, see the official docs for more details.

See the complete working Helm example below:

# Install MySQL first with the official Helm chart, tell to create a user and a database called 'vault':
helm install --name mysql stable/mysql --set mysqlUser=vault --set mysqlDatabase=vault

# Install the Vault chart, tell it to use MySQL as the storage backend, also specify where the 'vault' user's password should be coming from (the MySQL chart generates a secret called 'mysql' holding the password):
helm install --name vault banzaicloud-stable/vault \
--set replicaCount=2 \
--set vault.config.storage.mysql.address=mysql:3306 \
--set vault.config.storage.mysql.username=vault \
--set vault.config.storage.mysql.password="[[.Env.MYSQL_PASSWORD]]" \
--set "vault.envSecrets[0].secretName=mysql" \
--set "vault.envSecrets[0].secretKey=mysql-password" \
--set "vault.envSecrets[0].envName=MYSQL_PASSWORD"

Configuration

The following tables lists the configurable parameters of the vault chart and their default values.

ParameterDescriptionDefault
image.pullPolicyContainer pull policyIfNotPresent
image.repositoryContainer image to usevault
image.tagContainer image tag to deploy1.6.2
ingress.enabledEnables Ingressfalse
ingress.ingressClassNameIngress class name""
ingress.annotationsIngress annotations{}
ingress.hostsIngress accepted hostnames with path[]
ingress.tlsIngress TLS configuration[]
vault.envsCustom environment variables available to Vault[]
vault.customSecretsCustom secrets available to Vault[]
vault.envSecretsCustom secrets available to Vault as env vars[]
vault.configVault configurationNo default backend
vault.externalConfigVault API based configurationNo default backend
replicaCountk8s replicas1
resources.limits.cpuContainer requested CPUnil
resources.limits.memoryContainer requested memorynil
unsealer.argsBank Vaults args["--mode", "k8s", "--k8s-secret-namespace", "default", "--k8s-secret-name", "bank-vaults"]
unsealer.image.tagBank Vaults image tag.Chart.AppVersion
rbac.psp.enabledUse pod security policyfalse
nodeSelectorNode labels for pod assignment. https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector{}
tolerationsList of node tolerations for the pods. https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/[]
affinityNode affinity settings for the pods. https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/If not set it defaults topodAntiAffinity to preferredDuringSchedulingIgnoredDuringExecution
labelsAdditonal labels to be applied to the Vault StatefulSet and Pods{}
extraInitContainersInit containers to add to the bank-vaults pod[]
extraContainersSidecar containers to add to the bank-vaults pod[]
extraContainerVolumesVolumes that can be mounted in sidecar containers[]
tls.secretNameCustom TLS certifcate secret name""
podDisruptionBudget.enabledenable PodDisruptionBudgettrue
podDisruptionBudget.minAvailablerepresents the number of Pods that must be available (integer or percentage)nil
podDisruptionBudget.maxUnavailablerepresents the number of Pods that can be unavailable (integer or percentage)1
priorityClassNameThe PriorityClass to assign to Pods""

Specify each parameter using the --set key=value[,key=value] argument to helm install.

Using Vault

Once the Vault pod is ready, it can be accessed using kubectl port-forward:

$ kubectl port-forward vault-pod 8200
$ export VAULT_ADDR=http://127.0.0.1:8200
$ vault status

OpenShift Implementation

Tested with

  • OpenShift Container Platform 3.11
  • Helm 3

First create a new project named "vault"

oc new-app vault

Then create a new scc based on the scc restricted and add the capability "IPC_LOCK". Now add the new scc to the ServiceAccount vault of the new vault project:

oc adm policy add-scc-to-user <new_scc> system:serviceaccount:vault:vault

Or you can define users in scc directly and in this case, you only have to create the scc.

oc create -f <scc_file.yaml>

Example vault-restricted scc with defined user:

apiVersion: security.openshift.io/v1
kind: SecurityC

Deploy vault with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has vault 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 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