Workspace Proxy (ws-proxy) Component
Overview
The Workspace Proxy (ws-proxy) is a specialized component in Gitpod that handles routing and proxying of HTTP and WebSocket traffic to workspaces. It acts as an intermediary between the main Gitpod proxy and individual workspace pods, providing workspace-specific routing, port forwarding, and SSH gateway functionality.
Purpose
The primary purposes of the Workspace Proxy are:
Route requests to the appropriate workspace pods
Handle workspace-specific domain routing
Provide port forwarding functionality for workspace ports
Implement SSH gateway for direct SSH access to workspaces
Manage WebSocket connections to workspaces
Handle workspace-specific routing patterns
Provide health checks and metrics for workspace connectivity
Architecture
The Workspace Proxy operates as a specialized proxy service with several key components:
HTTP Proxy: Routes HTTP requests to workspace pods
WebSocket Proxy: Handles WebSocket connections to workspaces
SSH Gateway: Provides SSH access to workspaces
Workspace Info Provider: Retrieves workspace information from Kubernetes CRDs
Heartbeat Service: Monitors workspace connectivity
Router: Determines the appropriate workspace for incoming requests
The component is designed to efficiently route traffic to the correct workspace based on the hostname pattern, handling both HTTP and WebSocket protocols.
Key Files and Structure
main.go
: Entry point that calls the Execute function from the cmd packagecmd/root.go
: Defines the root command and basic service configurationcmd/run.go
: Implements the main proxy servicepkg/proxy/
: Core proxy implementationpkg/sshproxy/
: SSH gateway implementationpkg/config/
: Configuration handlingpkg/analytics/
: Analytics functionalitypublic/
: Static assets for built-in pages
Dependencies
Internal Dependencies
components/common-go:lib
: Common Go utilitiescomponents/gitpod-protocol/go:lib
: Gitpod protocol definitionscomponents/content-service-api/go:lib
: Content service API definitionscomponents/content-service:lib
: Content service clientcomponents/registry-facade-api/go:lib
: Registry facade API definitionscomponents/supervisor-api/go:lib
: Supervisor API definitionscomponents/ws-manager-api/go:lib
: Workspace manager API definitionscomponents/server/go:lib
: Server component library
External Dependencies
Kubernetes client libraries for CRD access
HTTP and WebSocket libraries
SSH libraries for SSH gateway
Prometheus for metrics
Controller-runtime for Kubernetes integration
Configuration
The Workspace Proxy is configured via a JSON configuration file that includes:
Ingress Configuration
HTTP/HTTPS settings
Listening address and port
Host header for routing
Proxy Configuration
Transport settings (timeouts, connection limits)
Gitpod installation details (hostname, workspace domain patterns)
Workspace pod configuration (ports for IDE and supervisor)
Built-in pages location
Workspace Manager Configuration
Connection details for the Workspace Manager
TLS settings for secure communication
SSH Gateway Configuration
CA key file for SSH certificate signing
Host keys for SSH server
Routing Logic
The Workspace Proxy implements sophisticated routing logic:
Workspace Routing: Routes requests to workspaces based on hostname patterns
Port Forwarding: Routes requests to specific ports in workspaces
WebSocket Routing: Handles WebSocket connections to workspaces
SSH Gateway: Routes SSH connections to workspaces
Hostname Patterns
The Workspace Proxy handles several hostname patterns:
Standard Workspace:
<workspace-id>.ws.<region>.<domain>
Port Forwarding:
<port>-<workspace-id>.ws.<region>.<domain>
Debug Workspace:
debug-<workspace-id>.ws.<region>.<domain>
Foreign Content: Special routes for VS Code webviews and webworkers
SSH Gateway
The Workspace Proxy includes an SSH gateway that allows direct SSH access to workspaces:
Listens on port 2200 for SSH connections
Uses host keys for server authentication
Authenticates users using Gitpod's authentication system
Routes SSH connections to the appropriate workspace
Provides heartbeat functionality to monitor workspace connectivity
Integration Points
The Workspace Proxy integrates with:
Kubernetes API: Retrieves workspace information from CRDs
Workspace Manager: Monitors workspace status
Workspace Pods: Routes traffic to workspace containers
Main Proxy: Receives traffic from the main Gitpod proxy
Security Considerations
Implements secure routing to workspaces
Handles TLS for secure communication
Provides SSH gateway with proper authentication
Validates workspace access permissions
Implements proper error handling and logging
Common Usage Patterns
The Workspace Proxy is typically used to:
Route HTTP requests to workspace pods
Handle WebSocket connections to workspaces
Provide port forwarding for workspace services
Enable SSH access to workspaces
Monitor workspace connectivity
Related Components
Proxy: Main Gitpod proxy that routes traffic to ws-proxy
Workspace Manager: Manages workspace lifecycle
Supervisor: Runs inside workspace containers
Server: Provides API for workspace operations