Skip to main content

Overview

The Auth module is a lightweight Go application responsible for handling authentication to the Kubernetes API. It provides secure login endpoints and manages user sessions through token validation.
The Auth module acts as an authentication gateway, validating credentials before granting access to Dashboard features.

Module Architecture

Entry Point

The module starts in modules/auth/main.go:
Reference: modules/auth/main.go:33-49

Package Structure

Core Responsibilities

1. User Authentication

The Auth module validates user credentials against the Kubernetes API Server.

Login Request Flow

2. CSRF Token Generation

Provides CSRF tokens for state-changing operations:
Reference: modules/auth/pkg/routes/csrftoken/handler.go

3. User Information

Returns authenticated user details:
Reference: modules/auth/pkg/routes/me/handler.go

Authentication Methods

The Auth module supports multiple authentication strategies:

Token-Based Authentication

Users provide a Kubernetes service account token or user token:

Token Validation Process

  1. Receive token from login request
  2. Create TokenReview request to Kubernetes API
  3. Validate response from TokenReview API
  4. Extract user info (username, UID, groups)
  5. Generate session token or cookie
  6. Return authentication response

Kubeconfig-Based Authentication

Users can upload kubeconfig files containing:
  • Client certificates
  • Bearer tokens
  • Username/password credentials
Kubeconfig authentication should only be used in trusted environments. Tokens are preferred for production.

API Routes

The Auth module exposes three primary endpoints:

POST /api/v1/login

Authenticates a user and returns session information. Request:
Response:
Reference: modules/auth/pkg/routes/login/handler.go:27-48

GET /api/v1/csrftoken/

Generates a CSRF token for the specified action. Parameters:
  • action (path): Action name (e.g., “deploy”, “scale”)
Response:

GET /api/v1/me

Returns information about the currently authenticated user. Response:

Security Features

CSRF Protection

The Auth module generates CSRF tokens using a shared secret:
The CSRF key is:
  • Shared between Auth and API modules via Kubernetes Secret
  • Base64-encoded 256-byte random string
  • Auto-generated if not provided in Helm values

Session Management

Authentication sessions are managed through:
  1. JWE Tokens: Encrypted JSON Web Tokens
  2. HTTP-only Cookies: Secure session cookies
  3. Token Refresh: Automatic token refresh mechanism

TLS/HTTPS

The Auth module supports both HTTP and HTTPS:
In typical deployments, the Auth module runs HTTP behind Kong Gateway, which handles TLS termination.

Request Flow

Login Flow

Token Review API

The Auth module uses Kubernetes TokenReview API:

Configuration Arguments

Key command-line arguments: Reference: modules/auth/pkg/args/args.go

Router Setup

The Auth module uses Gin web framework:
Reference: modules/auth/pkg/router/setup.go

Route Registration

Routes are registered via init() functions:
Reference: modules/auth/main.go:27-31

Error Handling

Consistent error responses:
HTTP status codes:
  • 200 OK - Successful authentication
  • 400 Bad Request - Malformed request
  • 401 Unauthorized - Invalid credentials
  • 500 Internal Server Error - Server error

Integration with Other Modules

With API Module

The API module validates CSRF tokens generated by Auth module:

With Kong Gateway

Kong routes authentication requests to Auth module:

Deployment

Helm chart configuration:
Reference: charts/kubernetes-dashboard/templates/deployments/auth.yaml

Testing

Run Auth module tests:

Manual Testing

Logging

The Auth module uses structured logging:
Log levels:
  • 0 - Info and errors
  • 1 - Verbose info
  • 2+ - Debug information

Security Best Practices

  • Never log authentication tokens
  • Clear tokens from memory after use
  • Use secure session storage
  • Rotate CSRF keys regularly
  • Use different tokens for different actions
  • Validate token expiration
  • Always use HTTPS in production
  • Use strong cipher suites
  • Enable certificate validation
  • Implement login attempt limiting
  • Block suspicious IP addresses
  • Monitor failed authentication attempts

Troubleshooting

Common Issues

Cause: Invalid or expired tokenSolution:
  • Verify token is valid: kubectl get secret
  • Check token hasn’t expired
  • Ensure service account exists
Cause: Auth and API modules using different CSRF keysSolution:
  • Check kubernetes-dashboard-csrf secret
  • Restart both Auth and API pods
  • Verify secret is mounted correctly
Cause: Invalid API server configurationSolution:
  • Check --apiserver-host argument
  • Verify RBAC permissions
  • Check network connectivity

API Module

How API module validates CSRF tokens

Security

Dashboard security documentation

RBAC Configuration

Setting up proper permissions

Kubernetes TokenReview

Kubernetes TokenReview API documentation