Deploying Vault Secrets Operator on OpenShift
This guide provides a comprehensive walkthrough for deploying and configuring the Vault Secrets Operator (VSO) in an OpenShift cluster. The VSO enables automatic synchronization of secrets from HashiCorp Vault to Kubernetes secrets, allowing applications to consume Vault secrets natively through Kubernetes.
The Vault Secrets Operator deployment consists of:
- Vault Server: The source of truth for secrets.
- VSO Controller: Manages the synchronization between Vault and Kubernetes.
- VaultAuth: Custom resource defining authentication to Vault.
- VaultStaticSecret: Custom resource defining which secrets to sync.
- Kubernetes Secrets: Target secrets created and managed by VSO.
Prerequisites
Before beginning the installation, ensure the following requirements are met:
- Vault Server: A running Vault server accessible within the cluster.
This guide assumes Vault is accessible at: http://vault.vault.svc.cluster.local:8200.
Vault can be running with in-memory storage or persistent storage.
- Cluster Access: Verify you are logged into the OpenShift cluster:
oc whoami - Vault Root Token: Access to Vault with administrative privileges for initial configuration.
- Helm: Helm 3.x installed and configured.
Procedure
The Vault Secrets Operator is now deployed and configured. Secrets from Vault are automatically synchronized to Kubernetes secrets and can be consumed by applications.
Using secrets in applications
Example: mounting secret as environment variables.
apiVersion: v1
kind: Pod
metadata:
name: myapp
namespace: vault-operator
spec:
containers:
- name: myapp
image: nginx:latest
env:
- name: USERNAME
valueFrom:
secretKeyRef:
name: static-secret2
key: username
- name: PASSWORD
valueFrom:
secretKeyRef:
name: static-secret2
key: password
Example: mounting secret as volume.
apiVersion: v1
kind: Pod
metadata:
name: myapp
namespace: vault-operator
spec:
containers:
- name: myapp
image: nginx:latest
volumeMounts:
- name: secrets
mountPath: /etc/secrets
readOnly: true
volumes:
- name: secrets
secret:
secretName: static-secret2
Best practices
- Use Namespaces: Deploy VSO and applications in separate namespaces for better isolation.
- Least Privilege: Create specific policies for each application with minimal required permissions.
- Secret Rotation: Configure appropriate
refreshAfterintervals based on your security requirements. - TLS Encryption: Always use TLS in production environments.
- Monitor Sync Status: Regularly check
VaultStaticSecretstatus to ensure secrets are syncing correctly. - Backup Credentials: Securely store
AppRolecredentials in a secrets management system. - Audit Logging: Enable Vault audit logging to track secret access.
Cleanup
To remove the VSO deployment:
# Delete secrets sync
oc delete vaultstaticsecret --all -n vault-operator
# Delete auth
oc delete vaultauth --all -n vault-operator
# Remove finalizer (if stuck)
oc patch vaultconnection default -n vault-operator \
--type=merge \
-p '{"metadata":{"finalizers":[]}}'
# Delete connection
oc delete vaultconnection --all -n vault-operator
# Delete app secret
oc delete secret approle-secret -n vault-operator
# Uninstall operator
helm uninstall vault-secrets-operator -n vault-operator
# Delete namespace
oc delete namespace vault-operator
Note: The patch command removes finalizers from the VaultConnection resource,
which may prevent deletion if the resource is stuck in a terminating state. This is a common issue
when cleaning up custom resources.