Run Vault on Kubernetes
Vault works with Kubernetes in various modes: dev
, standalone
, ha
,
and external
.
Important Note: This chart is not compatible with Helm 2. Please use Helm 3.6+ with this chart.
Helm Chart
The Vault Helm chart is the recommended way to install and configure Vault on Kubernetes. In addition to running Vault itself, the Helm chart is the primary method for installing and configuring Vault to integrate with other services such as Consul for High Availability (HA) deployments.
While the Helm chart automatically sets up complex resources and exposes the configuration to meet your requirements, it does not automatically operate Vault. You are still responsible for learning how to monitor, backup, upgrade, etc. the Vault cluster.
Security Warning: By default, the chart runs in standalone mode. This mode uses a single Vault server with a file storage backend. This is a less secure and less resilient installation that is NOT appropriate for a production setup. It is highly recommended to use a properly secured Kubernetes cluster, learn the available configuration options, and read the production deployment checklist.
How-To
Install Vault
Helm must be installed and configured on your machine. Please refer to the Helm documentation or the Vault Installation to Minikube via Helm tutorial.
To use the Helm chart, add the Hashicorp helm repository and check that you have access to the chart:
Important: The Helm chart is new and under significant development.
Please always run Helm with --dry-run
before any install or upgrade to verify
changes.
Use helm install
to install the latest release of the Vault Helm chart.
Or install a specific version of the chart.
The helm install
command accepts parameters to override default configuration
values inline or defined in a file.
Override the server.dev.enabled
configuration value:
Override all the configuration found in a file:
Dev mode
The Helm chart may run a Vault server in development. This installs a single Vault server with a memory storage backend.
Dev mode: This is ideal for learning and demonstration environments but NOT recommended for a production environment.
Install the latest Vault Helm chart in development mode.
Standalone mode
The Helm chart defaults to run in standalone
mode. This installs a single
Vault server with a file storage backend.
Install the latest Vault Helm chart in standalone mode.
HA mode
The Helm chart may be run in high availability (HA) mode. This installs three Vault servers with an existing Consul storage backend. It is suggested that Consul is installed via the Consul Helm chart.
Install the latest Vault Helm chart in HA mode.
Refer to the Vault Installation to Minikube via Helm tutorial to learn how to set up Consul and Vault in HA mode.
External mode
The Helm chart may be run in external mode. This installs no Vault server and relies on a network addressable Vault server to exist.
Install the latest Vault Helm chart in external mode.
Refer to the Integrate a Kubernetes Cluster with an External Vault tutorial to learn how to use an external Vault within a Kubernetes cluster.
View the Vault UI
The Vault UI is enabled but NOT exposed as service for security reasons. The
Vault UI can also be exposed via port-forwarding or through a ui
configuration value.
Expose the Vault UI with port-forwarding:
Initialize and unseal Vault
After the Vault Helm chart is installed in standalone
or ha
mode one of the
Vault servers need to be
initialized. The
initialization generates the credentials necessary to
unseal all the Vault
servers.
CLI initialize and unseal
View all the Vault pods in the current namespace:
Initialize one Vault server with the default number of key shares and default key threshold:
The output displays the key shares and initial root key generated.
Unseal the Vault server with the key shares until the key threshold is met:
Repeat the unseal process for all Vault server pods. When all Vault server pods
are unsealed they report READY 1/1
.
Google KMS Auto Unseal
The Helm chart may be run with Google KMS for Auto Unseal. This enables Vault server pods to auto unseal if they are rescheduled.
Vault Helm requires the Google Cloud KMS credentials stored in
credentials.json
and mounted as a secret in each Vault server pod.
Create the Secret
First, create the secret in Kubernetes:
Vault Helm mounts this to /vault/userconfig/kms-creds/credentials.json
.
Config Example
This is a Vault Helm configuration that uses Google KMS:
Amazon KMS Auto Unseal
The Helm chart may be run with AWS KMS for Auto Unseal. This enables Vault server pods to auto unseal if they are rescheduled.
Vault Helm requires the AWS credentials stored as environment variables that are defined in each Vault server pod.
Create the Secret
First, create a secret with your KMS access key/secret:
Config Example
This is a Vault Helm configuration that uses AWS KMS:
Probes
Probes are essential for detecting failures, rescheduling and using pods in Kubernetes. The helm chart offers configurable readiness and liveliness probes which can be customized for a variety of use cases.
Vault's /sys/health` endpoint can be customized to change the behavior of the health check. For example, we can change the Vault readiness probe to show the Vault pods are ready even if they're still uninitialized and sealed using the following probe:
Using this customized probe, a postStart
script could automatically run once the
pod is ready for additional setup.
Upgrading Vault on Kubernetes
To upgrade Vault on Kubernetes, we follow the same pattern as generally upgrading Vault, except we can use the Helm chart to update the Vault server StatefulSet. It is important to understand how to generally upgrade Vault before reading this section.
The Vault StatefulSet uses OnDelete
update strategy. It is critical to use OnDelete
instead
of RollingUpdate
because standbys must be updated before the active primary. A
failover to an older version of Vault must always be avoided.
IMPORTANT NOTE: Always back up your data before upgrading! Vault does not make backward-compatibility guarantees for its data store. Simply replacing the newly-installed Vault binary with the previous version not cleanly downgrade Vault, as upgrades may perform changes to the underlying data structure that make the data incompatible with a downgrade. If you need to roll back to a previous version of Vault, you should roll back your data store as well.
Upgrading Vault Servers
IMPORTANT NOTE: Helm will install the latest chart found in a repo by default. It's recommended to specify the chart version when upgrading.
To initiate the upgrade, set the server.image
values to the desired Vault
version, either in a values yaml file or on the command line. For illustrative
purposes, the example below uses vault:123.456
.
Next, list the Helm versions and choose the desired version to install.
Next, test the upgrade with --dry-run
first to verify the changes sent to the
Kubernetes cluster.
This should cause no changes (although the resources are updated). If
everything is stable, helm upgrade
can be run.
The helm upgrade
command should have updated the StatefulSet template for
the Vault servers, however, no pods have been deleted. The pods must be manually
deleted to upgrade. Deleting the pods does not delete any persisted data.
If Vault is not deployed using ha
mode, the single Vault server may be deleted by
running:
If Vault is deployed using ha
mode, the standby pods must be upgraded first.
To identify which pod is currently the active primary, run the following command
on each Vault pod:
Next, delete every pod that is not the active primary:
If auto-unseal is not being used, the newly scheduled Vault standby pods needs to be unsealed:
Finally, once the standby nodes have been updated and unsealed, delete the active primary:
Similar to the standby nodes, the former primary also needs to be unsealed:
After a few moments the Vault cluster should elect a new active primary. The Vault cluster is now upgraded!
Protecting Sensitive Vault Configurations
Vault Helm renders a Vault configuration file during installation and stores the file in a Kubernetes configmap. Some configurations require sensitive data to be included in the configuration file and would not be encrypted at rest once created in Kubernetes.
The following example shows how to add extra configuration files to Vault Helm to protect sensitive configurations from being in plaintext at rest using Kubernetes secrets.
First, create a partial Vault configuration with the sensitive settings Vault loads during startup:
Next, create a Kubernetes secret containing this partial configuration:
Finally, mount this secret as an extra volume and add an additional -config
flag
to the Vault startup command:
Architecture
We recommend running Vault on Kubernetes with the same general architecture as running it anywhere else. There are some benefits Kubernetes can provide that eases operating a Vault cluster and we document those below. The standard production deployment tutorial is still an important read even if running Vault within Kubernetes.
Production Deployment Checklist
End-to-End TLS. Vault should always be used with TLS in production. If intermediate load balancers or reverse proxies are used to front Vault, they should not terminate TLS. This way traffic is always encrypted in transit to Vault and minimizes risks introduced by intermediate layers. See the official documentation for example on configuring Vault Helm to use TLS.
Single Tenancy. Vault should be the only main process running on a machine.
This reduces the risk that another process running on the same machine is
compromised and can interact with Vault. This can be accomplished by using Vault
Helm's affinity
configurable. See the
official documentation
for example on configuring Vault Helm to use affinity rules.
Enable Auditing. Vault supports several auditing backends. Enabling auditing
provides a history of all operations performed by Vault and provides a forensics
trail in the case of misuse or compromise. Audit logs securely hash any sensitive
data, but access should still be restricted to prevent any unintended disclosures.
Vault Helm includes a configurable auditStorage
option that provisions a persistent
volume to store audit logs. See the
official documentation
for an example on configuring Vault Helm to use auditing.
Immutable Upgrades. Vault relies on an external storage backend for persistence, and this decoupling allows the servers running Vault to be managed immutably. When upgrading to new versions, new servers with the upgraded version of Vault are brought online. They are attached to the same shared storage backend and unsealed. Then the old servers are destroyed. This reduces the need for remote access and upgrade orchestration which may introduce security gaps. See the upgrade section for instructions on upgrading Vault on Kubernetes.
Upgrade Frequently. Vault is actively developed, and updating frequently is important to incorporate security fixes and any changes in default settings such as key lengths or cipher suites. Subscribe to the Vault mailing list and GitHub CHANGELOG for updates.
Restrict Storage Access. Vault encrypts all data at rest, regardless of which storage backend is used. Although the data is encrypted, an attacker with arbitrary control can cause data corruption or loss by modifying or deleting keys. Access to the storage backend should be restricted to only Vault to avoid unauthorized access or operations.