Question 12 | Hack Secrets - part 3
How to build the environment in home lab and mimic below results?
/ # curl https://kubernetes.default/api/v1/namespaces/restricted/secrets -H "Authorization: Bearer $(cat /run/secrets/kubernetes.io/serviceaccount/token)" -k
...
{
"metadata": {
"name": "secret3",
"namespace": "restricted",
...
}
]
},
"data": {
"password": "cEVuRXRSYVRpT24tdEVzVGVSCg=="
},
"type": "Opaque"
}
This is how I attempted with failures:
sa.yaml
-------------------------------------------------
apiVersion: v1
kind: ServiceAccount
metadata:
name: backend-sa
automountServiceAccountToken: true
sa-pod.yaml
------------------------------------------------
apiVersion: v1
kind: Pod
metadata:
name: backend
spec:
serviceAccountName: backend-sa
containers:
- image: nginx:1.9
imagePullPolicy: IfNotPresent
name: backend
verification
-------------------------------------------------
candidate@node01:~$ kubectl exec secret -- curl -k https://kubernetes.default/api/v1/namespaces/default/secrets -H "Authorization:Bearer {cat /run/secrets/kubernetes.io/serviceaccount/token}"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 157 100 157 0 0 4575 0{--:--:-- --:--:-- --:--:-- 0
"kind": "Status",
"apiVersion": "v1",
"metadata": {},
"status": "Failure",
"message": "Unauthorized",
"reason": "Unauthorized",
"code": 401
} --:--:-- --:--:-- --:--:-- 4757