Vault in ARO
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 that you can use for encrypting volumes.
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.
Set up the Vault development environment
Once you've set up Vault, you're ready to set up your development environment.
Pure Storage does not recommend using this for production environments.
-
Create a
config.hcl
file, then start the Vault server:config.hcl
listener "tcp" {
address = "0.0.0.0:8200"
tls_disable = 1
}
storage "file" {
path = "/tmp/vault-data"
}
disable_mlock = truemkdir -p /tmp/vault-data
vault server -config=config.hcl -
When Vault initializes, it will present the unseal keys and initial root token. Securely store and distribute the keys, as they will be used in later operations.
export VAULT_ADDR='http://127.0.0.1:8200'
vault operator initUnseal Key 1: 4jYbl2CBIv6SpkKj6Hos9iD32k5RfGkLzlosrrq/JgOm
Unseal Key 2: B05G1DRtfYckFV5BbdBvXq0wkK5HFqB9g2jcDmNfTQiS
Unseal Key 3: Arig0N9rN9ezkTRo7qTB7gsIZDaonOcc53EHo83F5chA
Unseal Key 4: 0cZE0C/gEk3YHaKjIWxhyyfs8REhqkRW/CSXTnmTilv+
Unseal Key 5: fYhZOseRgzxmJCmIqUdxEm9C3jB5Q27AowER9w4FC2Ck
Initial Root Token: <your-root-token>
Vault initialized with 5 key shares and a key threshold of 3. Please securely
distribute the key shares printed above. When the Vault is re-sealed,
restarted, or stopped, you must supply at least 3 of these keys to unseal it
before it can start servicing requests.
Vault does not store the generated main key. Without at least 3 key to
reconstruct the main key, Vault will remain permanently sealed!
It is possible to generate new unseal keys, provided you have a quorum of
existing unseal keys shares. See "vault operator rekey" for more information. -
When you first start Vault, you must unseal it. Enter the following command to unseal the Vault server. Repeat it 3 times:
vault operator unseal
Unseal Key (will be hidden):
Key Value
--- -----
Seal Type shamir
Initialized true
Sealed true
Total Shares 5
Threshold 3
Unseal Progress 1/3
Unseal Nonce xxxxxxxx-xxxx-xxxx-xxxx-e63ddb34b2a9
Version 1.7.0
Storage Type raft
HA Enabled true -
Log in to the Vault server using the root token you generated in step 2:
vault login <initial-root-token>
-
Verify the installation by entering the following vault command. Specify your own value for
<my-vault-secret>
:vault kv put secret/my-secret my-value=<my-vault-secret>
Key Value
--- -----
created_time 2019-06-19T17:20:22.985303Z
deletion_time n/a
destroyed false
version 1
Kubernetes users
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 authetication: 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 kube-system
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 setup Kubernetes Vault authentication, refer to the Vault documentation.
-
Create a
ServiceAccount
for Vault authentication delegation.Run the following
oc create
commands to create aServiceAccount
andClusterRoleBinding
. Vault uses thisServiceAccount
and its associated token to authenticate requests from Portworx. Vault uses the Kubernetes TokenReview API.oc create serviceaccount vault-auth -n kube-system
oc create clusterrolebinding vault-tokenreview-binding --clusterrole=system:auth-delegator --serviceaccount=kube-system:vault-auth -
Enable Kubernetes authentication in Vault. Enter the following
vault auth
command 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:
export VAULT_SA_NAME=$(oc get sa vault-auth -n kube-system \
-o jsonpath="{.secrets[*]['name']}")
export SA_JWT_TOKEN=$(oc get secret $VAULT_SA_NAME -n kube-system \
-o jsonpath="{.data.token}" | base64 --decode; echo)
export SA_CA_CRT=$(oc get secret $VAULT_SA_NAME -n kube-system \
-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"
-
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
portworx
orkube-system
. IfPX_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: <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.
Using AppRole authentication method
This method allows Portworx to authenticate with Vault using AppRole
authentication. AppRole
authentication requires a Role ID and a Secret ID. For more information about how to set up AppRole authentication, refer to the Vault AppRole documentation.