Skip to content

Commit e0d7774

Browse files
rodrigorfkinteon
authored andcommitted
feat: adding documentation describing how to configure Vault for mTLS
Signed-off-by: Rodrigo Fior Kuntzer <[email protected]>
1 parent d6f47c8 commit e0d7774

File tree

1 file changed

+201
-0
lines changed

1 file changed

+201
-0
lines changed

content/docs/configuration/vault.md

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,207 @@ spec:
4747
...
4848
```
4949
50+
### Accessing a Vault Server with mTLS enforced
51+
52+
In certain use cases, the Vault Server could be configured to enforce clients to present a
53+
client certificates, those client certificates are just a transport layer enforcement,
54+
it does not provide any authentication and authorization mechanism to the Vault APIs itself.
55+
You can read more about the Vault server TCP listener [in the official documentation](https://developer.hashicorp.com/vault/docs/configuration/listener/tcp)
56+
57+
Please follow the steps below to configure Vault with mTLS enforced:
58+
- Generate the bundle CA and the server TLS certificate:
59+
```shell
60+
step certificate create "Example Server Root CA" server_ca.crt server_ca.key \
61+
--profile root-ca \
62+
--not-after=87600h \
63+
--no-password \
64+
--insecure
65+
66+
67+
step certificate create vault.vault vault.crt vault.key \
68+
--profile leaf \
69+
--not-after=8760h \
70+
--ca ./server_ca.crt \
71+
--ca-key server_ca.key \
72+
--no-password \
73+
--insecure
74+
```
75+
- Generate Vault client certificate and CA:
76+
```shell
77+
step certificate create "Example Client Root CA" client_ca.crt client_ca.key \
78+
--profile root-ca \
79+
--not-after=87600h \
80+
--no-password \
81+
--insecure
82+
83+
step certificate create client.vault vault_client.crt vault_client.key \
84+
--profile leaf \
85+
--not-after=8760h \
86+
--ca ./client_ca.crt \
87+
--ca-key client_ca.key \
88+
--no-password \
89+
--insecure
90+
```
91+
- Prepare the Vault installation, assuming you would be installing Vault in the Kubernetes cluster using the [official Helm chart](https://github.com/hashicorp/vault-helm):
92+
- Create the Vault namespace
93+
```shell
94+
kubectl create ns vault
95+
```
96+
- Create a Kubernetes Secret in the same namespace where Vault will be installed and add the generated PKI files as following:
97+
```shell
98+
kubectl create secret generic vault-tls \
99+
--namespace vault \
100+
--from-file=server.key=vault.key \
101+
--from-file=server.crt=vault.crt \
102+
--from-file=client-ca.crt=client_ca.crt \
103+
--from-file=client.crt=vault_client.crt \
104+
--from-file=client.key=vault_client.key
105+
```
106+
- Deploy Vault using the following values file:
107+
```yaml
108+
# vault-values.yaml
109+
global:
110+
tlsDisable: false
111+
injector:
112+
enabled: false
113+
server:
114+
dataStorage:
115+
enabled: false
116+
standalone:
117+
enabled: true
118+
config: |
119+
listener "tcp" {
120+
address = "[::]:8200"
121+
cluster_address = "[::]:8201"
122+
tls_disable = false
123+
tls_client_ca_file = "/vault/tls/client-ca.crt"
124+
tls_cert_file = "/vault/tls/server.crt"
125+
tls_key_file = "/vault/tls/server.key"
126+
tls_require_and_verify_client_cert = true
127+
}
128+
extraArgs: "-dev-tls -dev-listen-address=[::]:8202"
129+
extraEnvironmentVars:
130+
VAULT_TLSCERT: /vault/tls/server.crt
131+
VAULT_TLSKEY: /vault/tls/server.key
132+
VAULT_CLIENT_CERT: /vault/tls/client.crt
133+
VAULT_CLIENT_KEY: /vault/tls/client.key
134+
volumes:
135+
- name: vault-tls
136+
secret:
137+
defaultMode: 420
138+
secretName: vault-tls
139+
volumeMounts:
140+
- mountPath: /vault/tls
141+
name: vault-tls
142+
readOnly: true
143+
```
144+
145+
```shell
146+
helm upgrade vault hashicorp/vault --install --namespace vault --create-namespace --values vault-values.yaml
147+
```
148+
149+
- Configure Vault server for Kubernetes auth
150+
```shell
151+
kubectl -n vault exec pods/vault-0 -- \
152+
vault auth enable --tls-skip-verify kubernetes
153+
154+
kubectl -n vault exec pods/vault-0 -- \
155+
vault write --tls-skip-verify \
156+
auth/kubernetes/role/vault-issuer \
157+
bound_service_account_names=vault-issuer \
158+
bound_service_account_namespaces=application-1 \
159+
audience="vault://application-1/vault-issuer" \
160+
policies=vault-issuer \
161+
ttl=1m
162+
163+
kubectl -n vault exec pods/vault-0 -- \
164+
vault write --tls-skip-verify \
165+
auth/kubernetes/config \
166+
kubernetes_host=https://kubernetes.default
167+
```
168+
- Create application namespace
169+
```shell
170+
kubectl create ns application-1
171+
```
172+
- Create Service account
173+
```shell
174+
kubectl create serviceaccount -n application-1 vault-issuer
175+
```
176+
- Create Role and Binding
177+
```yaml
178+
# rbac.yaml
179+
apiVersion: rbac.authorization.k8s.io/v1
180+
kind: Role
181+
metadata:
182+
name: vault-issuer
183+
namespace: application-1
184+
rules:
185+
- apiGroups: ['']
186+
resources: ['serviceaccounts/token']
187+
resourceNames: ['vault-issuer']
188+
verbs: ['create']
189+
---
190+
apiVersion: rbac.authorization.k8s.io/v1
191+
kind: RoleBinding
192+
metadata:
193+
name: vault-issuer
194+
namespace: application-1
195+
subjects:
196+
- kind: ServiceAccount
197+
name: cert-manager
198+
namespace: cert-manager
199+
roleRef:
200+
apiGroup: rbac.authorization.k8s.io
201+
kind: Role
202+
name: vault-issuer
203+
```
204+
```shell
205+
kubectl apply -f rbac.yaml
206+
```
207+
- Create Vault client certificate secret
208+
```shell
209+
kubectl create secret generic vault-client-tls \
210+
--namespace application-1 \
211+
--from-file=client.crt=vault_client.crt \
212+
--from-file=client.key=vault_client.key
213+
```
214+
- Create Issuer
215+
```shell
216+
export CA_BUNDLE=$(base64 -w 0 server_ca.crt)
217+
```
218+
```yaml
219+
# vault-issuer.yaml
220+
apiVersion: cert-manager.io/v1
221+
kind: Issuer
222+
metadata:
223+
name: vault-issuer
224+
namespace: application-1
225+
spec:
226+
vault:
227+
path: pki_int/sign/application-1
228+
server: https://vault.vault:8200
229+
caBundle: ${CA_BUNDLE}
230+
clientCertSecretRef:
231+
name: vault-client-tls
232+
key: vault_client.crt
233+
clientKeySecretRef:
234+
name: vault-client-tls
235+
key: vault_client.key
236+
auth:
237+
kubernetes:
238+
role: vault-issuer
239+
mountPath: /v1/auth/kubernetes
240+
serviceAccountRef:
241+
name: vault-issuer
242+
```
243+
```shell
244+
envsubst < vault-issuer.yaml | kubectl -f -
245+
```
246+
- Check Issuer status
247+
```shell
248+
kubectl describe issuer -n application-1
249+
```
250+
50251
## Authenticating
51252

52253
In order to request signing of certificates by Vault, the issuer must be able to

0 commit comments

Comments
 (0)