|
2 | 2 |
|
3 | 3 | This guide covers how to configure GCP OAuth authentication for Headlamp when deploying to Google Kubernetes Engine (GKE). |
4 | 4 |
|
| 5 | +## Overview |
| 6 | + |
| 7 | +This implementation adds GCP OAuth 2.0 authentication support to Headlamp, replacing the deprecated Identity Service for GKE. Users authenticate with their Google Cloud account, and the authentication tokens are used to access Kubernetes resources with proper RBAC. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +### Authentication Flow |
| 12 | + |
| 13 | +1. **User Login**: User clicks "Sign in with Google" in Headlamp UI |
| 14 | +2. **OAuth Redirect**: User is redirected to Google's OAuth consent screen |
| 15 | +3. **Authorization**: User authorizes Headlamp to access their GCP account |
| 16 | +4. **Callback**: Google redirects back to Headlamp with authorization code |
| 17 | +5. **Token Exchange**: Headlamp exchanges code for access/refresh tokens |
| 18 | +6. **K8s API Access**: Tokens are used to authenticate with Kubernetes API |
| 19 | +7. **RBAC Authorization**: Kubernetes RBAC evaluates permissions based on user's GCP identity |
| 20 | + |
| 21 | +### Components |
| 22 | + |
| 23 | +#### Backend Changes |
| 24 | + |
| 25 | +1. **GCP Authenticator** (`backend/pkg/gcp/auth.go`) |
| 26 | + - Implements OAuth 2.0 flow with Google |
| 27 | + - PKCE (Proof Key for Code Exchange) support for enhanced security |
| 28 | + - Token refresh and caching mechanisms |
| 29 | + - GKE cluster detection |
| 30 | + |
| 31 | +2. **Route Handlers** (`backend/pkg/gcp/handlers.go`) |
| 32 | + - `/gcp-auth/login`: Initiates OAuth flow |
| 33 | + - `/gcp-auth/callback`: Handles OAuth callback |
| 34 | + - `/gcp-auth/refresh`: Refreshes expired tokens |
| 35 | + - `/gcp-auth/enabled`: Check if GCP OAuth is enabled |
| 36 | + |
| 37 | +3. **Configuration** (`backend/pkg/config/config.go`) |
| 38 | + - `GCPOAuthEnabled`: Enable/disable GCP OAuth |
| 39 | + - `GCPClientID`: OAuth 2.0 Client ID |
| 40 | + - `GCPClientSecret`: OAuth 2.0 Client Secret |
| 41 | + - `GCPRedirectURL`: Callback URL for OAuth flow |
| 42 | + |
| 43 | +#### Frontend Changes |
| 44 | + |
| 45 | +1. **GCP Login Button** (`frontend/src/components/cluster/GCPLoginButton.tsx`) |
| 46 | + - React component that renders "Sign in with Google" button |
| 47 | + - Automatically shown for GKE clusters or when backend OAuth is enabled |
| 48 | + |
| 49 | +2. **Auth Chooser** (`frontend/src/components/authchooser/index.tsx`) |
| 50 | + - Shows authentication options including GCP OAuth |
| 51 | + - Prevents auto-redirect to token page to allow users to choose auth method |
| 52 | + |
5 | 53 | ## Prerequisites |
6 | 54 |
|
7 | 55 | 1. GKE cluster up and running |
|
0 commit comments