Skip to content

Commit b084dad

Browse files
committed
Merge remote-tracking branch 'upstream/K8SPS-583-Hackathon-encryption-monitoring' into K8SPS-583-Hackathon-encryption-monitoring
2 parents eea4d0c + ea460f3 commit b084dad

File tree

1 file changed

+67
-24
lines changed

1 file changed

+67
-24
lines changed

docs/encryption-setup.md

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This guide walks you through deploying and configuring HashiCorp Vault to work w
77
It is a good practice to isolate workloads in Kubernetes using namespaces. Create a namespace with the following command:
88

99
```{.bash data-prompt="$"}
10-
$ kubectl create namespace vault
10+
kubectl create namespace vault
1111
```
1212

1313
Export the namespace as an environment variable to simplify further configuration and management
@@ -22,15 +22,15 @@ For this setup, we install Vault in Kubernetes using the [Helm 3 package manager
2222

2323
1. Add and update the Vault Helm repository.
2424

25-
``` {.bash data-prompt="$" }
26-
$ helm repo add hashicorp https://helm.releases.hashicorp.com
27-
$ helm repo update
25+
``` bash
26+
helm repo add hashicorp https://helm.releases.hashicorp.com
27+
helm repo update
2828
```
2929

3030
2. Install Vault
3131

32-
``` {.bash data-prompt="$" }
33-
$ helm upgrade --install vault hashicorp/vault --namespace $NAMESPACE
32+
``` bash
33+
helm upgrade --install vault hashicorp/vault --namespace $NAMESPACE
3434
```
3535

3636
??? example "Sample output"
@@ -52,7 +52,7 @@ For this setup, we install Vault in Kubernetes using the [Helm 3 package manager
5252

5353
3. Retrieve the Pod name where Vault is running:
5454

55-
```{.bash data-prompt="$" }
55+
```bash
5656
$(kubectl -n $NAMESPACE get pod -l app.kubernetes.io/name=vault -o jsonpath='{.items[0].metadata.name}')
5757
```
5858

@@ -65,7 +65,7 @@ For this setup, we install Vault in Kubernetes using the [Helm 3 package manager
6565
4. After Vault is installed, you need to initialize it. Run the following command:
6666

6767
```{.bash data-prompt="$"}
68-
$ kubectl exec -it pod/vault-0 -n $NAMESPACE -- vault operator init -key-shares=1 -key-threshold=1 -format=json > /tmp/vault-init
68+
kubectl exec -it pod/vault-0 -n $NAMESPACE -- vault operator init -key-shares=1 -key-threshold=1 -format=json > /tmp/vault-init
6969
```
7070

7171
The command does the following:
@@ -80,13 +80,13 @@ For this setup, we install Vault in Kubernetes using the [Helm 3 package manager
8080
Retrieve the unseal key from the file:
8181

8282
```{.bash data-prompt="$"}
83-
$ unsealKey=$(jq -r ".unseal_keys_b64[]" < /tmp/vault-init)
83+
unsealKey=$(jq -r ".unseal_keys_b64[]" < /tmp/vault-init)
8484
```
8585

8686
Now, unseal Vault. Run the following command on every Pod where Vault is running:
8787

8888
```{.bash data-prompt="$"}
89-
$ kubectl exec -it pod/vault-0 -n $NAMESPACE -- vault operator unseal "$unsealKey"
89+
kubectl exec -it pod/vault-0 -n $NAMESPACE -- vault operator unseal "$unsealKey"
9090
```
9191

9292
??? example "Sample output"
@@ -120,7 +120,7 @@ When you started Vault, it generates and starts with a [root token :octicons-lin
120120
1. Extract the Vault root token from the file where you saved the init response output:
121121

122122
```{.bash data-prompt="$"}
123-
$ cat /tmp/vault-init | jq -r ".root_token"
123+
cat /tmp/vault-init | jq -r ".root_token"
124124
```
125125

126126
??? example "Sample output"
@@ -131,20 +131,20 @@ When you started Vault, it generates and starts with a [root token :octicons-lin
131131

132132
2. Connect to Vault Pod:
133133

134-
``` {.bash data-prompt="$" }
135-
$ kubectl exec -it vault-0 -n $NAMESPACE -- /bin/sh
134+
``` bash
135+
kubectl exec -it vault-0 -n $NAMESPACE -- /bin/sh
136136
```
137137

138138
3. Authenticate in Vault with this token:
139139

140-
```{.bash data-prompt="$" }
141-
$ vault login hvs.*************Jg9r
140+
```bash
141+
vault login hvs.*************Jg9r
142142
```
143143

144144
4. Enable the secrets engine at the mount path. The following command enables KV secrets engine v2 at the `ps-secret` mount-path:
145145

146-
``` {.bash data-prompt="$" }
147-
$ vault secrets enable --version=2 -path=ps-secret kv
146+
``` bash
147+
vault secrets enable --version=2 -path=ps-secret kv
148148
```
149149

150150
??? example "Sample output"
@@ -259,19 +259,62 @@ Now create a Secret object. Replace the `<namespace>` placeholder with the names
259259
```bash
260260
kubectl apply -f deploy/vault-secret.yaml -n <namespace>
261261
```
262+
!!! warning "If your deployment uses Group Replication as the cluster type, you must pause the cluster before patching to enable encryption."
263+
264+
After you add the required secret, unpause the cluster to resume normal operation.
262265
263266
## Reference the Secret in your Custom Resource manifest
264267
265268
Now, reference the Vault Secret in the Operator Custom Resource manifest. Note that the Secret name is the one you specified in the `metadata.name` field when you created a Secret.
266269
267-
Since this is a running cluster, we will apply a patch:
270+
1. Export the namespace where the cluster is deployed as an environment variable:
271+
272+
```bash
273+
export ps-cluster-namespace = <cluster-namespace>
274+
```
275+
276+
2. Update the cluster configuration. Since this is a running cluster, we will apply a patch.
277+
278+
=== "Group replication"
279+
280+
1. Pause the cluster:
281+
282+
``` bash
283+
kubectl patch ps ps-cluster1 \
284+
--namespace $<ps-cluster-namespace> \
285+
--type=merge \
286+
--patch '{"spec": {"pause": true}}'
287+
```
288+
289+
2. Apply the patch referencing your Secret. Note for MySQL 8.0 the default Secret name is `ps-cluster1-vault` and for MySQL 8.4 - `ps-cluster1-vault-84`. Use the following command as an example and specify the Secret name for the MySQL version you're using:
290+
291+
``` bash
292+
kubectl patch ps ps-cluster1 \
293+
--namespace $<ps-cluster-namespace> \
294+
--type=merge \
295+
--patch '{"spec":{"mysql":{"vaultSecretName":"ps-cluster1-vault"}}}'
296+
```
297+
298+
3. Unpause the cluster:
299+
300+
``` bash
301+
kubectl patch ps ps-cluster1 \
302+
--namespace $<ps-cluster-namespace> \
303+
--type=merge \
304+
--patch '{"spec": {"pause": false}}'
305+
```
306+
307+
=== "Asynchronous replication"
308+
309+
Apply the patch referencing your Secret. Note for MySQL 8.0 the default Secret name is `ps-cluster1-vault` and for MySQL 8.4 - `ps-cluster1-vault-84`. Use the following command as an example and specify the Secret name for the MySQL version you're using:
310+
311+
```bash
312+
kubectl patch ps ps-cluster1 \
313+
--namespace $<ps-cluster-namespace> \
314+
--type=merge \
315+
--patch '{"spec":{"mysql":{"vaultSecretName":"ps-cluster1-vault"}}}'
316+
```
268317
269-
```bash
270-
kubectl patch ps ps-cluster1\
271-
--namespace <namesapce> \
272-
--type=merge \
273-
--patch '{"spec":{"mysql":{"vaultSecretName":"ps-cluster1-vault"}}}'
274-
```
275318
276319
## Use data-at-rest encryption
277320

0 commit comments

Comments
 (0)