Skip to content

Commit 0ebcb9c

Browse files
committed
fixing and adding day39 brief steps
1 parent f669aac commit 0ebcb9c

5 files changed

Lines changed: 47 additions & 88 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

2023/day39.md

Lines changed: 28 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -131,122 +131,67 @@ We must now exec into our vault-0 pod to enable the secret engine.
131131

132132
`kubectl exec --stdin=true --tty=true vault-0 -n vault -- /bin/sh`
133133

134-
We will now have to authenticate and login using `vault login` and provide the token we discovered with root_token in a previous step.
135-
136134
![](images/day39-7.png)
137135

138-
We will now run the following commands the first will enable the secret engine and the second will create secret at the path.
139-
140-
```
141-
vault secrets enable -path=secret kv-v2
142-
143-
vault kv put secret/webapp/config username="static-user" password="static-password"
144-
```
145136

146-
You can then verify with the following command
137+
`vault secrets enable -path=secret kv-v2`
147138

148-
`vault kv get secret/webapp/config`
149139

150-
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.
140+
`vault kv put secret/devwebapp/config username='giraffe' password='salsa'`
151141

152-
You should still be in your vault-0 pod. We are going to enable the Kubernetes authentication method with the following command:
142+
`vault kv get secret/devwebapp/config`
153143

154144
`vault auth enable kubernetes`
155145

156-
***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.***
157-
158-
Next we need to configure the Kubernetes authentication method to use the location of the Kubernetes API.
159-
160146
```
161147
vault write auth/kubernetes/config \
162148
kubernetes_host="https://$KUBERNETES_PORT_443_TCP_ADDR:443"
163149
```
164-
165-
## Creating a Vault Policy
166-
167-
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.
168-
169150
```
170-
vault policy write webapp - <<EOF
171-
path "secret/data/webapp/config" {
151+
vault policy write devwebapp - <<EOF
152+
path "secret/data/devwebapp/config" {
172153
capabilities = ["read"]
173154
}
174155
EOF
175156
```
176157

177-
Our Application shortly will be defined as webapp
178-
179-
With the following command we will create a kubernetes authentication role
180-
181158
```
182-
vault write auth/kubernetes/role/webapp \
183-
bound_service_account_names=vault \
184-
bound_service_account_namespaces=webapp \
185-
policies=webapp \
159+
vault write auth/kubernetes/role/devweb-app \
160+
bound_service_account_names=internal-app \
161+
bound_service_account_namespaces=default \
162+
policies=devwebapp \
186163
ttl=24h
187164
```
188165

189-
now `exit` from the vault-0 pod and back to the local machine.
166+
`exit`
190167

191-
## Deploying our Application
168+
`kubectl create ns webdevapp`
192169

193-
I am again going to be using the web app that is used in the HashiCorp tutorial mentioned earlier.
194-
195-
We will create a deployment yaml that looks like the following.
170+
`kubectl create sa internal-app -n devwebapp`
196171

197172
```
173+
cat > devwebapp.yaml <<EOF
198174
---
199175
apiVersion: v1
200-
kind: ServiceAccount
201-
metadata:
202-
name: vault
203-
---
204-
apiVersion: apps/v1
205-
kind: Deployment
176+
kind: Pod
206177
metadata:
207-
name: webapp
178+
name: devwebapp
208179
labels:
209-
app: webapp
180+
app: devwebapp
181+
annotations:
182+
vault.hashicorp.com/agent-inject: "true"
183+
vault.hashicorp.com/role: "devweb-app"
184+
vault.hashicorp.com/agent-inject-secret-credentials.txt: "secret/data/devwebapp/config"
210185
spec:
211-
replicas: 1
212-
selector:
213-
matchLabels:
214-
app: webapp
215-
template:
216-
metadata:
217-
labels:
218-
app: webapp
219-
spec:
220-
serviceAccountName: vault
221-
containers:
222-
- name: app
223-
image: hashieducation/simple-vault-client:latest
224-
imagePullPolicy: Always
225-
env:
226-
- name: VAULT_ADDR
227-
value: 'http://vault.vault.svc.cluster.local:8200/'
228-
- name: JWT_PATH
229-
value: '/var/run/secrets/kubernetes.io/serviceaccount/token'
230-
- name: SERVICE_PORT
231-
value: '8080'
186+
serviceAccountName: internal-app
187+
containers:
188+
- name: devwebapp
189+
image: jweissig/app:0.0.1
190+
EOF
232191
```
192+
`kubectl create -f devwebapp.yaml -n devwebapp`
233193

234-
Create the webapp namespace
235-
236-
`kubectl create ns webapp`
237-
238-
Our YAML consists of our simple web app and the service account.
194+
`kubectl get pods -n devwebapp`
239195

240-
`kubectl create -f deployment-01-webapp.yml -n webapp`
241-
242-
I also want to note that the helm chart for vault will deploy
243-
244-
You can check that the authentication has worked by checking pods in the webapp namespace, if they are not in a running state or not there at all then something is not right as this is communicating with vault to make sure that this service is running.
245-
246-
Once the pod is running, we need to port forward our webapp
247-
Find the pod name and then port forward that.
248-
```
249-
kubectl get pods -n webapp
250-
kubectl port-forward <PODNAME> -n webapp 8080:8080
251-
```
196+
`kubectl exec --stdin=true --tty=true devwebapp -n devwebapp -c devwebapp -- cat /vault/secrets/credentials.txt`
252197

2023/day39/cluster-keys.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"unseal_keys_b64": [
3-
"qZiqjl0/r8zgnoCU8j9tdr5eN8W56rXb6xFpGmGumUs="
3+
"s/zg7van3BR5U55FXJchQCZrA5IRA2mLAwVklF/lExM="
44
],
55
"unseal_keys_hex": [
6-
"a998aa8e5d3fafcce09e8094f23f6d76be5e37c5b9eab5dbeb11691a61ae994b"
6+
"b3fce0eef6a7dc1479539e455c972140266b03921103698b030564945fe51313"
77
],
88
"unseal_shares": 1,
99
"unseal_threshold": 1,
1010
"recovery_keys_b64": [],
1111
"recovery_keys_hex": [],
1212
"recovery_keys_shares": 0,
1313
"recovery_keys_threshold": 0,
14-
"root_token": "hvs.SyXEwWlOzmBnQxe4xr6r337P"
14+
"root_token": "hvs.p1rm1RK7193dXelo4q3wSjDu"
1515
}

2023/day39/deployment-01-webapp.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ apiVersion: v1
33
kind: ServiceAccount
44
metadata:
55
name: vault
6-
namespace: webapp
76
---
87
apiVersion: apps/v1
98
kind: Deployment
109
metadata:
1110
name: webapp
12-
namespace: webapp
1311
labels:
1412
app: webapp
1513
spec:

2023/day39/devwebapp.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
apiVersion: v1
3+
kind: Pod
4+
metadata:
5+
name: devwebapp
6+
labels:
7+
app: devwebapp
8+
annotations:
9+
vault.hashicorp.com/agent-inject: "true"
10+
vault.hashicorp.com/role: "devweb-app"
11+
vault.hashicorp.com/agent-inject-secret-credentials.txt: "secret/data/devwebapp/config"
12+
spec:
13+
serviceAccountName: internal-app
14+
containers:
15+
- name: devwebapp
16+
image: jweissig/app:0.0.1

0 commit comments

Comments
 (0)