From 0ebcb9c1cb8b6f63b0851ddca05abe5fba73f3cd Mon Sep 17 00:00:00 2001 From: MichaelCade Date: Fri, 21 Jul 2023 10:09:09 +0100 Subject: [PATCH] fixing and adding day39 brief steps --- .DS_Store | Bin 10244 -> 10244 bytes 2023/day39.md | 111 +++++++--------------------- 2023/day39/cluster-keys.json | 6 +- 2023/day39/deployment-01-webapp.yml | 2 - 2023/day39/devwebapp.yaml | 16 ++++ 5 files changed, 47 insertions(+), 88 deletions(-) create mode 100644 2023/day39/devwebapp.yaml diff --git a/.DS_Store b/.DS_Store index df74ac8c01e39cdfd4a52937b33b53da2d9ebbb7..25e87e4337c7f7593c9688ef0472261306b24e47 100644 GIT binary patch delta 16 XcmZn(XbIS$C&X-QWW3o>=&~pPEv*F- delta 16 XcmZn(XbIS$C&X-KVzk*%=&~pPEzJcM diff --git a/2023/day39.md b/2023/day39.md index aadcdd974..b71098cb7 100644 --- a/2023/day39.md +++ b/2023/day39.md @@ -131,122 +131,67 @@ We must now exec into our vault-0 pod to enable the secret engine. `kubectl exec --stdin=true --tty=true vault-0 -n vault -- /bin/sh` -We will now have to authenticate and login using `vault login` and provide the token we discovered with root_token in a previous step. - ![](images/day39-7.png) -We will now run the following commands the first will enable the secret engine and the second will create secret at the path. - -``` -vault secrets enable -path=secret kv-v2 - -vault kv put secret/webapp/config username="static-user" password="static-password" -``` -You can then verify with the following command +`vault secrets enable -path=secret kv-v2` -`vault kv get secret/webapp/config` -So far we have used our root token this root user can peform any operation at any path and as you can expect best practices states that we dont or should not use this account other than initial setup and configuration. +`vault kv put secret/devwebapp/config username='giraffe' password='salsa'` -You should still be in your vault-0 pod. We are going to enable the Kubernetes authentication method with the following command: +`vault kv get secret/devwebapp/config` `vault auth enable kubernetes` -***Vault accepts this service token from any client within the Kubernetes cluster. During authentication, Vault verifies that the service account token is valid by querying a configured Kubernetes endpoint.*** - -Next we need to configure the Kubernetes authentication method to use the location of the Kubernetes API. - ``` vault write auth/kubernetes/config \ kubernetes_host="https://$KUBERNETES_PORT_443_TCP_ADDR:443" ``` - -## Creating a Vault Policy - -For a client or application to access the secret data defined, at secret/webapp/config, requires that the read capability be granted for the path secret/data/webapp/config. - ``` -vault policy write webapp - < devwebapp.yaml < -n webapp 8080:8080 -``` +`kubectl exec --stdin=true --tty=true devwebapp -n devwebapp -c devwebapp -- cat /vault/secrets/credentials.txt` diff --git a/2023/day39/cluster-keys.json b/2023/day39/cluster-keys.json index d5ac0109c..86e05759c 100644 --- a/2023/day39/cluster-keys.json +++ b/2023/day39/cluster-keys.json @@ -1,9 +1,9 @@ { "unseal_keys_b64": [ - "qZiqjl0/r8zgnoCU8j9tdr5eN8W56rXb6xFpGmGumUs=" + "s/zg7van3BR5U55FXJchQCZrA5IRA2mLAwVklF/lExM=" ], "unseal_keys_hex": [ - "a998aa8e5d3fafcce09e8094f23f6d76be5e37c5b9eab5dbeb11691a61ae994b" + "b3fce0eef6a7dc1479539e455c972140266b03921103698b030564945fe51313" ], "unseal_shares": 1, "unseal_threshold": 1, @@ -11,5 +11,5 @@ "recovery_keys_hex": [], "recovery_keys_shares": 0, "recovery_keys_threshold": 0, - "root_token": "hvs.SyXEwWlOzmBnQxe4xr6r337P" + "root_token": "hvs.p1rm1RK7193dXelo4q3wSjDu" } diff --git a/2023/day39/deployment-01-webapp.yml b/2023/day39/deployment-01-webapp.yml index b9703b195..c703f2dbe 100644 --- a/2023/day39/deployment-01-webapp.yml +++ b/2023/day39/deployment-01-webapp.yml @@ -3,13 +3,11 @@ apiVersion: v1 kind: ServiceAccount metadata: name: vault - namespace: webapp --- apiVersion: apps/v1 kind: Deployment metadata: name: webapp - namespace: webapp labels: app: webapp spec: diff --git a/2023/day39/devwebapp.yaml b/2023/day39/devwebapp.yaml new file mode 100644 index 000000000..1f09ae53f --- /dev/null +++ b/2023/day39/devwebapp.yaml @@ -0,0 +1,16 @@ +--- +apiVersion: v1 +kind: Pod +metadata: + name: devwebapp + labels: + app: devwebapp + annotations: + vault.hashicorp.com/agent-inject: "true" + vault.hashicorp.com/role: "devweb-app" + vault.hashicorp.com/agent-inject-secret-credentials.txt: "secret/data/devwebapp/config" +spec: + serviceAccountName: internal-app + containers: + - name: devwebapp + image: jweissig/app:0.0.1