Skip to content

Commit 9eaf9c8

Browse files
committed
completed day 39 - secrets management
1 parent 0ebcb9c commit 9eaf9c8

5 files changed

Lines changed: 46 additions & 38 deletions

File tree

2023.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Or contact us via Twitter, my handle is [@MichaelCade1](https://twitter.com/Mich
9090
- [✔️] 🕵 36 > [Securing Secrets with HashiCorp Vault](2023/day36.md)
9191
- [✔️] 🕵 37 > [Working with HashiCorp Vault's Secrets Engines](2023/day37.md)
9292
- [✔️] 🕵 38 > [Increase the Security Posture of Your Organization with Dynamic Credentials](2023/day38.md)
93-
- [] 🕵 39 > [](2023/day39.md)
93+
- [✔️] 🕵 39 > [Getting Hands-On with HashiCorp Vault](2023/day39.md)
9494
- [] 🕵 40 > [](2023/day40.md)
9595
- [] 🕵 41 > [](2023/day41.md)
9696

2023/day39.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,35 @@ We must now exec into our vault-0 pod to enable the secret engine.
136136

137137
`vault secrets enable -path=secret kv-v2`
138138

139+
## Creating a new secret for our app
139140

140-
`vault kv put secret/devwebapp/config username='giraffe' password='salsa'`
141+
As a simple test we want to create an application in its own namespace within our Kubernetes cluster to then communicate with vault in its own namespace.
142+
143+
This is one thing that is not defined in the tutorial linked, and I wanted to provide a bit more real life use case because yes the default namespace can be used but that doesn't mean it should be.
144+
145+
`vault kv put secret/devwebapp/config username='90DaysOfDevOps' password='90DaysOfDevOps'`
146+
147+
We can confirm what we have just created with the following command:
141148

142149
`vault kv get secret/devwebapp/config`
143150

151+
You can see the above commands ran in my terminal below.
152+
153+
![](images/day39-8.png)
154+
155+
Next we need to enable the Kubernetes authentication method.
156+
144157
`vault auth enable kubernetes`
145158

159+
Configure the Kubernetes authentication method to use the location of the Kubernetes API.
160+
146161
```
147162
vault write auth/kubernetes/config \
148163
kubernetes_host="https://$KUBERNETES_PORT_443_TCP_ADDR:443"
149164
```
165+
166+
We can now create our policy named devwebapp that enables the read capability for secrets at path secret/data/devwebapp/config
167+
150168
```
151169
vault policy write devwebapp - <<EOF
152170
path "secret/data/devwebapp/config" {
@@ -155,20 +173,33 @@ path "secret/data/devwebapp/config" {
155173
EOF
156174
```
157175

176+
Create a Kubernetes authentication role named devweb-app, this has been taken from the tutorial from Hashicorp but notice that we define a namespace other than default.
177+
158178
```
159179
vault write auth/kubernetes/role/devweb-app \
160180
bound_service_account_names=internal-app \
161-
bound_service_account_namespaces=default \
181+
bound_service_account_namespaces=webdevapp \
162182
policies=devwebapp \
163183
ttl=24h
164184
```
185+
Now we can exit our vault-0 pod.
165186

166187
`exit`
167188

168-
`kubectl create ns webdevapp`
189+
## Deploying our Application
190+
191+
As mentioned now back into our Kubernetes cluster, it is time to create and deploy our application to complete this demo.
192+
193+
Firstly, create the application namespace with
194+
195+
`kubectl create ns devwebapp`
196+
197+
We will now create our serviceaccount.
169198

170199
`kubectl create sa internal-app -n devwebapp`
171200

201+
Now for our application, we will create the following yaml file and you will find this in the day39 folder.
202+
172203
```
173204
cat > devwebapp.yaml <<EOF
174205
---
@@ -189,9 +220,20 @@ spec:
189220
image: jweissig/app:0.0.1
190221
EOF
191222
```
223+
We will be deploying this to our newly created namespace with the following command.
224+
192225
`kubectl create -f devwebapp.yaml -n devwebapp`
193226

227+
Check the status of the pods.
228+
194229
`kubectl get pods -n devwebapp`
195230

231+
Finally we can confirm that we have the correct credentials stored in our app.
232+
196233
`kubectl exec --stdin=true --tty=true devwebapp -n devwebapp -c devwebapp -- cat /vault/secrets/credentials.txt`
197234

235+
Confirmation of this can be seen below, but hopefully you are seeing the same output as I have got below.
236+
237+
![](images/day39-9.png)
238+
239+
See you on [Day 40](day40.md)

2023/day39/deployment-01-webapp.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

2023/images/day39-8.png

189 KB
Loading

2023/images/day39-9.png

433 KB
Loading

0 commit comments

Comments
 (0)