Challenge
DifficultyEasy
Community stats58 solved of 75 attempts
Extracting and Decoding ServiceAccount Token from Kubernetes Secret
Find the Secret that holds a ServiceAccount's token, decode the token, and read the identity it carries.
Scenario
The mars-sa-v2 ServiceAccount in the mars namespace has a long-lived token stored in a Secret.
Task
- Find the Secret that holds the token of the
mars-sa-v2ServiceAccount in themarsnamespace. Write the name of that Secret to/home/laborant/secret-name. - Save the token from that Secret to
/home/laborant/token. The file must hold the token itself, not its Base64-encoded form. - Read the payload of the token saved in
/home/laborant/token. Write the value of itssub(subject) claim to/home/laborant/token-subject.
Hint 1 | How a token Secret is linked to a ServiceAccount
The name of a Secret proves nothing. A ServiceAccount token Secret has a specific type, and an annotation that names the ServiceAccount it belongs to:
kubectl get secrets -n <namespace>
kubectl describe secret <name> -n <namespace>
See: Manually create a long-lived API token for a ServiceAccount
Hint 2 | Getting one value out of a Secret
Every value under a Secret's data is Base64-encoded. A single field can be printed on its own and decoded:
kubectl get secret <name> -n <namespace> -o jsonpath='{.data.<key>}'
base64 --help
Hint 3 | Reading a JWT
A ServiceAccount token is a JSON Web Token: three parts separated by dots, header.payload.signature. The header and payload are Base64-encoded JSON, without the = padding at the end.