Challenge, Medium,  on  Kubernetes

Secure ServiceAccount Token Mounting Using Projected Volumes

Scenario

A Deployment manifest is located on dev-machine at:

/home/laborant/secure-app.yaml

It defines a Deployment named secure-app in the prod namespace using the ServiceAccount app-sa.

By default, Kubernetes automatically mounts a ServiceAccount token into every Pod at /var/run/secrets/kubernetes.io/serviceaccount/token. This token never expires — if the Pod is compromised, the token can be used indefinitely.

Cluster security policy requires this default behaviour to be disabled and replaced with a short-lived projected token mounted at a controlled path.


Task

Update the manifest at /home/laborant/secure-app.yaml and apply it to the cluster:

1. Disable automatic ServiceAccount token mounting on the Pod spec.

2. Add a projected volume with a ServiceAccount token that has:

  • audience: api
  • expiration: 3600 seconds
  • path: token

3. Mount the projected volume into app-container at /var/run/secrets/tokens.

  • Do not change the ServiceAccount name — app-sa must remain as the serviceAccountName in the Pod spec.
  • Ensure the old Pod is terminated and a new Pod is created successfully by the Deployment.

Hint

Set automountServiceAccountToken: false under spec.template.spec.

Use volumes[].projected.sources[].serviceAccountToken to define the token.

Mount it using volumeMounts in app-container.

See: Projected Volumes


Test Cases