Skip to main content

Overview

The Kubernetes Dashboard API uses Bearer token authentication to authenticate requests. The API acts as a proxy to the Kubernetes API server, forwarding authentication credentials to ensure proper authorization.

Authentication Methods

Bearer Token Authentication

The primary authentication method is Bearer token authentication using Kubernetes service account tokens or OIDC tokens.

Request Header

Example

Token Extraction

The API extracts Bearer tokens from the Authorization header:

Token Validation

The Dashboard does not validate tokens directly. Instead, it forwards them to the Kubernetes API server, which performs validation and authorization.

Client Initialization

The API supports two client modes:

In-Cluster Client

Used for cluster-wide operations with the Dashboard’s service account:

Per-Request Client

Created for each user request with their Bearer token:

Authorization

RBAC Integration

The Dashboard respects Kubernetes RBAC policies. User permissions are determined by:
  1. The service account associated with their token
  2. Roles and ClusterRoles bound to that service account
  3. RoleBindings and ClusterRoleBindings

Permission Checking

The API provides a permission checking endpoint:
endpoint
Check if the authenticated user has permission to perform an action

Request Body

Response

Self-Subject Access Review

The API uses Kubernetes SelfSubjectAccessReview to check permissions:

Service Accounts

Dashboard Service Account

The Dashboard typically runs with its own service account:

Creating User Service Accounts

Create a service account for API access:

Extracting Service Account Token

Kubernetes 1.24+

Create a token manually:

Kubernetes < 1.24

Extract from the secret:

TLS/SSL Configuration

Certificate Management

The Dashboard API supports TLS with automatic certificate generation:
string
Path to the TLS certificate file
string
Path to the TLS private key file
boolean
default:"false"
Enable automatic certificate generation using ECDSA P-256
string
default:"/certs"
Directory for auto-generated certificates

TLS Configuration

Minimum TLS version is set to TLS 1.2:

API Server Connection

Configuration Options

string
The address of the Kubernetes API server (overrides in-cluster config)
string
Path to kubeconfig file (for out-of-cluster development)
boolean
default:"false"
Skip TLS verification for the API server connection
string
Path to custom CA bundle for API server verification

Connection Verification

On startup, the API verifies connectivity to the Kubernetes API server:

Proxy Mode

For development, the Dashboard can run in proxy mode:
boolean
default:"false"
Enable proxy mode (disables in-cluster client connections)
In proxy mode:
  • In-cluster client is disabled
  • All requests use per-request authentication
  • Metrics integration is disabled

Security Headers

Authorization Header Handling

The API checks for the Authorization header:

Setting Authorization Headers

For internal requests, the API sets authorization headers:

Client Caching

The API supports client caching for improved performance:
boolean
default:"false"
Enable client-side caching
When enabled, the API caches Kubernetes client instances per token.

User Agent

The Dashboard identifies itself to the API server:

Error Responses

401 Unauthorized

Returned when no valid Bearer token is provided:

403 Forbidden

Returned when the token is valid but lacks permissions:

Example: Complete Authentication Flow

Step 1: Create Service Account

Step 2: Create Role Binding

Step 3: Get Token

Step 4: Make Authenticated Request

Response

Best Practices

Security Recommendations

  1. Use RBAC: Always use role-based access control with minimal required permissions
  2. Token Rotation: Regularly rotate service account tokens
  3. TLS Only: Always use HTTPS in production
  4. Token Scope: Create service accounts with specific namespace or resource access
  5. Avoid admin: Don’t bind service accounts to cluster-admin unless absolutely necessary

Example: Read-Only Access

Example: Namespace-Specific Access