The Public API Server is a component in Gitpod that provides a versioned, stable, and managed API for programmatic access to Gitpod functionality. It serves as the gateway for external integrations, automation, and third-party tools to interact with Gitpod's core services. The API is designed to be backward compatible, well-documented, and follows modern API design principles.
The primary purposes of the Public API Server component are:
- Provide a stable, versioned API for programmatic access to Gitpod
- Enable third-party integrations and community-built tools
- Offer a consistent interface for automation and orchestration
- Support authentication and authorization for API access
- Serve as the canonical way to access Gitpod functionality programmatically
- Enable richer integrations with IDEs and development platforms
- Provide OpenID Connect (OIDC) authentication capabilities
- Support identity provider functionality
The Public API Server is built as a Go service with several key components:
- gRPC API: Core API implementation using gRPC and Connect
- Authentication: Handles API tokens, session verification, and OIDC flows
- Proxy Layer: Routes requests to internal Gitpod services
- Metrics & Logging: Collects and exposes metrics and logs
- Validation: Ensures request data meets API requirements
- Webhooks: Handles external service webhooks (e.g., Stripe)
The component is designed to be the primary entry point for all programmatic interactions with Gitpod, abstracting away internal implementation details and providing a stable interface.
main.go
: Entry point for the applicationcmd/root.go
: Command-line interface setupcmd/run.go
: Main server run commandpkg/server/server.go
: Core server implementationpkg/apiv1/
: API service implementationspkg/auth/
: Authentication and authorizationpkg/oidc/
: OpenID Connect implementationpkg/identityprovider/
: Identity provider functionalitypkg/proxy/
: Request proxying to internal servicespkg/webhooks/
: Webhook handlers
The Public API Server provides several services:
- Workspaces Service: Manage workspaces (create, start, stop, delete)
- Teams Service: Manage teams and team membership
- User Service: User information and management
- SCM Service: Source code management integrations
- Editor Service: IDE and editor configuration
- IDE Client Service: IDE client interactions
- Projects Service: Project management
- OIDC Service: OpenID Connect authentication
- Identity Provider Service: Identity provider functionality
- Tokens Service: Personal access token management
The component supports multiple authentication methods:
- Personal Access Tokens: Long-lived tokens for API access
- Session Authentication: Browser session-based authentication
- OIDC Authentication: OpenID Connect flows for third-party authentication
- Webhook Signatures: Verification of webhook payloads
Authentication is implemented using JSON Web Signatures (JWS) with both RSA-256 and HMAC-SHA256 algorithms.
The Public API Server is configured through a JSON configuration file:
{
"server": {
"port": 3000,
"address": "0.0.0.0"
},
"gitpodServiceURL": "https://gitpod.io/api",
"publicURL": "https://api.gitpod.io",
"sessionServiceAddress": "session-service:3000",
"databaseConfigPath": "/etc/gitpod/db",
"redis": {
"address": "redis:6379"
},
"auth": {
"pki": {
"privateKeyPath": "/etc/gitpod/auth/private-key.pem",
"publicKeyPath": "/etc/gitpod/auth/public-key.pem"
},
"session": {
"cookieName": "gp:session",
"maxAgeMs": 259200000
}
},
"personalAccessTokenSigningKeyPath": "/etc/gitpod/auth/pat-key",
"stripeWebhookSigningSecretPath": "/etc/gitpod/stripe/webhook-secret",
"billingServiceAddress": "billing-service:3000"
}
components/common-go
: Common Go utilitiescomponents/public-api
: API definitionscomponents/usage-api
: Usage API definitionscomponents/gitpod-protocol
: Gitpod protocol definitionscomponents/gitpod-db
: Database access
- gRPC and Connect for API implementation
- Redis for caching and session management
- GORM for database access
- Chi router for HTTP routing
- Prometheus for metrics
The Public API Server integrates with:
- Gitpod Server: For core Gitpod functionality
- Database: For persistent storage
- Redis: For caching and session management
- Billing Service: For billing-related operations
- Session Service: For session management
- External Identity Providers: For authentication
The component implements several security measures:
- Token Signing: Secure signing of personal access tokens
- Session Verification: Validation of user sessions
- Webhook Signature Verification: Ensures webhook payloads are authentic
- CORS Protection: Controls cross-origin requests
- Encryption: Database encryption for sensitive data
- Logging: Comprehensive logging for security auditing
The component exposes various metrics:
- Request counts and latencies
- Error rates
- Authentication failures
- Proxy performance
- OIDC flow completions
The Public API Server is typically used to:
- Create and manage workspaces programmatically
- Integrate Gitpod with CI/CD pipelines
- Build custom dashboards and management tools
- Automate workspace provisioning
- Implement custom authentication flows
- Integrate with third-party services
- Server: Provides the core functionality that the Public API exposes
- Database: Stores user, workspace, and other data
- Proxy: Routes incoming traffic to appropriate services
- Billing Service: Handles billing-related operations
- Session Service: Manages user sessions