Vault
Portworx can integrate with Vault to store your encryption keys, secrets, and credentials. This topic explains how to connect a Portworx cluster to a Vault development server endpoint and use it to store secrets for encrypting volumes, as well as credentials such as vSphere credentials.
You can either use Vault for volume encryption and Kubernetes Secrets for storing vSphere credentials, or use Vault for both purposes.
Set up Vault
Set up and deploy Vault by following the instructions in the Install Vault section of the Vault documentation. This includes installation, setting up policies, and configuring secrets.
To run a dev server, use the vault server -dev command. This will only run on 127.0.0.1:8200, and cannot be connected by the container. Ensure the server endpoint is securely exposed to the Portworx clusters.
## Authenticate Vault with Portworx
Step 1: Choose the Vault authentication method.
Authentication methods are responsible for authenticating Portworx with Vault. Based on your Vault configuration and the authentication method you choose, you must use one of the following two methods:
- Using Token authentication: A static Vault token is provided to Portworx.
- Using Kubernetes authentication: Portworx uses Kubernetes service account to fetch and refresh Vault tokens.
- Using Vault AppRole authentication: Portworx uses Vault AppRole's Role ID and Secret ID to authenticate and generate Vault Tokens.
Using token authentication method
With this method, Portworx requires a Vault static token that you should provide through a Kubernetes secret.
Provide Vault credentials to Portworx. Refer to the Vault credentials reference for details on the credentials.
Create the Kubernetes secret with the name px-vault in the portworx namespace. If PX_SECRETS_NAMESPACE is set, create the secret in the defined namespace.
For example
apiVersion: v1
kind: Secret
metadata:
name: px-vault
namespace: portworx
type: Opaque
data:
VAULT_ADDR: (required)<base64 encoded value of the vault endpoint address>
VAULT_TOKEN: (required)<base64 encoded value of the vault token>
VAULT_CACERT: (recommended)<base64 encoded file path where the CA Certificate is present on all the nodes>
VAULT_CAPATH: (recommended)<base64 encoded file path where the Certificate Authority is present on all the nodes>
VAULT_CLIENT_CERT: (recommended)<base64 encoded file path where the Client Certificate is present on all the nodes>
VAULT_CLIENT_KEY: (recommended)<base64 encoded file path where the Client Key is present on all the nodes>
VAULT_TLS_SERVER_NAME: (recommended)<base64 encoded value of the TLS server name>
VAULT_BACKEND_PATH: (optional)<base64 encoded value of the custom backend path if different than the default "secret">
VAULT_NAMESPACE: (optional)<base64 encoded value of the global vault namespace for portworx>
Portworx searches for this secret with name px-vault under the portworx namespace.
If the VAULT_TOKEN provided in the secret above is refreshed, then you must manually update this secret.
After configuring Vault using the Vault authentication method, proceed to Step 2.
Using Kubernetes authentication method
This method allows Portworx to authenticate with Vault using a Kubernetes service account token. For more information about how to set up Kubernetes Vault authentication, refer to the Vault documentation.
-
Create a
ServiceAccountfor Vault authentication delegation.Run the following
kubectl createoroc createcommands to create aServiceAccountandClusterRoleBinding. Vault uses thisServiceAccountand its associated token to authenticate requests from Portworx. Vault uses the Kubernetes TokenReview API.- Kubernetes
- OpenShift
kubectl apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
name: vault-auth
namespace: portworx
secrets:
- name: vault-auth-token
EOFserviceaccount/vault-auth createdkubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: vault-auth-token
namespace: portworx
annotations:
kubernetes.io/service-account.name: vault-auth
type: kubernetes.io/service-account-token
EOFsecret/vault-auth-token createdkubectl create clusterrolebinding vault-tokenreview-binding --clusterrole=system:auth-delegator --serviceaccount=portworx:vault-authclusterrolebinding.rbac.authorization.k8s.io/vault-tokenreview-binding createdoc apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
name: vault-auth
namespace: portworx
secrets:
- name: vault-auth-token
EOFserviceaccount/vault-auth createdoc apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: vault-auth-token
namespace: portworx
annotations:
kubernetes.io/service-account.name: vault-auth
type: kubernetes.io/service-account-token
EOFsecret/vault-auth-token createdoc create clusterrolebinding vault-tokenreview-binding --clusterrole=system:auth-delegator --serviceaccount=portworx:vault-authclusterrolebinding.rbac.authorization.k8s.io/vault-tokenreview-binding created -
Enable Kubernetes authentication in Vault. Enter the following
vault authcommand to enable Kubernetes authentication in Vault:vault auth enable kubernetes -
Create a Kubernetes authentication configuration in Vault. Enter the following export commands to get the JWT token and CA certificate of Kubernetes ServiceAccount:
- Kubernetes
- OpenShift
export SA_JWT_TOKEN=$(kubectl get secret vault-auth-token -n portworx \
-o jsonpath="{.data.token}" | base64 --decode; echo)
export SA_CA_CRT=$(kubectl get secret vault-auth-token -n portworx \
-o jsonpath="{.data['ca\.crt']}" | base64 --decode; echo)
export SA_JWT_TOKEN=$(oc get secret vault-auth-token -n portworx \
-o jsonpath="{.data.token}" | base64 --decode; echo)
export SA_CA_CRT=$(oc get secret vault-auth-token -n portworx \
-o jsonpath="{.data['ca\.crt']}" | base64 --decode; echo)
Enter the following vault write command, replacing <kubernetes-endpoint> with your Kubernetes API-server endpoint to write a Kubernetes authentication configuration to Vault:
vault write auth/kubernetes/config \
token_reviewer_jwt="$SA_JWT_TOKEN" \
kubernetes_host="<kubernetes endpoint>" \
kubernetes_ca_cert="$SA_CA_CRT" \
issuer="https://kubernetes.default.svc.cluster.local" # Optional
-
Create a Kubernetes authentication role for Portworx, named
portworx, in Vault:vault write auth/kubernetes/role/portworx \
bound_service_account_names=portworx \
bound_service_account_namespaces=<namespace> \
policies=portworx \
ttl=<ttl> -
Provide Vault credentials to Portworx. Refer to Vault credentials reference for details on the credentials.
Portworx reads the Vault credentials required to authenticate with Vault through a Kubernetes secret. Create the Kubernetes secret in the namespace where Portworx is deployed, for example
portworxorportworx. IfPX_SECRETS_NAMESPACEis set, create the secret in the defined namespace. For example:apiVersion: v1
kind: Secret
metadata:
name: px-vault
namespace: portworx
type: Opaque
data:
VAULT_ADDR: <base64 encoded value of the vault endpoint address>
VAULT_BACKEND_PATH: <base64 encoded value of the custom backend path if different than the default "secret">
VAULT_CACERT: <base64 encoded file path where the CA Certificate is present on all the nodes>
VAULT_CAPATH: <base64 encoded file path where the Certificate Authority is present on all the nodes>
VAULT_CLIENT_CERT: <base64 encoded file path where the Client Certificate is present on all the nodes>
VAULT_CLIENT_KEY: <base64 encoded file path where the Client Key is present on all the nodes>
VAULT_TLS_SERVER_NAME: <base64 encoded value of the TLS server name>
VAULT_AUTH_METHOD: a3ViZXJuZXRlcw== # base64 encoded value of "kubernetes"
VAULT_AUTH_KUBERNETES_ROLE: cG9ydHdvcng= # base64 encoded value of the kubernetes auth role "portworx"
VAULT_NAMESPACE: <base64 encoded value of the global vault namespace for portworx>
During installation, Portworx creates a Kubernetes role binding that grants read access to Kubernetes secrets from only the defined namespace.