»Vault Agent Injector TLS Configuration

The following instructions demonstrate how to manually configure the Vault Agent Injector with self-signed certificates.

»Create a Certificate Authority (CA)

First, create a private key to be used by our custom Certificate Authority (CA):

$ openssl genrsa -out injector-ca.key 2048

Next, create a certificate authority certificate:

$ openssl req \
   -x509 \
   -new \
   -nodes \
   -key injector-ca.key \
   -sha256 \
   -days 1825 \
   -out injector-ca.crt \
   -subj "/C=US/ST=CA/L=San Francisco/O=HashiCorp/CN=vault-agent-injector-svc"

»Create Vault Agent Injector Certificate

Next we can create a certificate and key signed by the certificiate authority generated above. This certificiate and key will be used by the Vault Agent Injector for TLS communications with the Kuberenetes API.

First, create a private key for the certificate:

$ openssl genrsa -out tls.key 2048

Next, create a certificate signing request (CSR) to be used when signing the certificate:

$ openssl req \
   -new \
   -key tls.key \
   -out tls.csr \
   -subj "/C=US/ST=CA/L=San Francisco/O=HashiCorp/CN=vault-agent-injector-svc"

After creating the CSR, create an extension file to configure additional parameters for signing the certificate.

In this example the Vault Agent Injector service name is vault-agent-injector-svc in the vault namespace. This uses the pattern <k8s service name>.<k8s namespace>.svc.cluster.local.

$ cat <<EOF >csr.conf
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

DNS.1 = vault-agent-injector-svc
DNS.2 = vault-agent-injector-svc.vault
DNS.3 = vault-agent-injector-svc.vault.svc
DNS.4 = vault-agent-injector-svc.vault.svc.cluster.local

Finally, sign the certificiate:

$ openssl x509 \
  -req \
  -in tls.csr \
  -CA injector-ca.crt \
  -CAkey injector-ca.key \
  -CAcreateserial \
  -out tls.crt \
  -days 1825 \
  -sha256 \
  -extfile csr.conf


Now that a certificate authority and a signed certificate have been created, we can now configure Helm and the Vault Agent Injector to use them.

First, create a Kubernetes secret containing the certificate and key created above:

$ kubectl create secret generic injector-tls \
    --from-file tls.crt \
    --from-file tls.key \

Next, base64 encode the certificate authority so Kubernetes can verify the authenticity of the certificate:

$ export CA_BUNDLE=$(cat injector-ca.crt | base64)

Finally, install the Vault Agent Injector with the following custom values:

$ helm install vault hashicorp/vault \
  --namespace=vault \
  --set="injector.certs.secretName=injector-tls" \