Course contentsShow
← Cloud and Infrastructure
Lesson 1401 of 2,98928. Kubernetes SecurityFree lesson

Service Account Token Projection

Configure time-limited and audience-scoped service account tokens to improve authentication security.

Service Account Token Projection

What you'll learn: How to configure time-limited and audience-scoped service account tokens to strengthen authentication security in your Kubernetes clusters.

By default, Kubernetes service accounts receive long-lived tokens that don't expire and aren't scoped to specific audiences. This creates security risks if tokens are compromised. Service Account Token Projection solves this by allowing you to request tokens with explicit lifetimes and intended audiences.

How Token Projection Works

Think of traditional service account tokens like a lifetime museum pass—once issued, it never expires. Token projection is more like requesting a temporary, single-exhibition pass that expires after a few hours and only works for specific exhibits you're visiting.

When you configure token projection in your Pod spec, Kubernetes mounts a token that:

  • Expires after a defined duration (e.g., 1 hour)
  • Refreshes automatically before expiration
  • Targets a specific audience (like your API server or external service)

This follows the principle of least privilege by limiting token validity windows and scope.

Configuring Token Projection

You enable this feature in your Pod's serviceAccount volume definition:

volumes:
  - name: token
    projected:
      sources:
        - serviceAccountToken:
            path: token
            expirationSeconds: 3600
            audience: my-api-audience

The token is mounted into your container at the specified path and automatically rotated before expiration.

Why This Matters

Short-lived, scoped tokens reduce your attack surface. If a token leaks, it's only valid for a limited time and specific purposes—not indefinitely across your entire cluster.

Key Takeaway: Service Account Token Projection enhances security by replacing long-lived tokens with time-bound, audience-specific credentials that automatically refresh, minimizing the impact of token compromise.