Gateway
The gateway (gateway/) is a single Go binary and the only component users
talk to. It serves the dashboard and its REST API, runs the OIDC login, and
reverse-proxies the IDE and test-application traffic to workspace pods. It
holds no state of its own: workspaces, teams and profiles live in the
Kubernetes API, sessions live in encrypted cookies, and usage data comes from
Prometheus when it is configured.
Packages
| Package | Responsibility |
|---|---|
gateway/main.go | Configuration from the environment, OIDC client, session store, services, router, HTTP(S) server |
internal/server | Host-based routing, OIDC handlers (/auth/*), bridge redemption, the client-certificate gate and break-glass sign-in, the dashboard’s cross-site check, authentication and admin middleware |
internal/api | Tenant REST handlers under /api/v1 (thin: decode, call a service, encode) |
internal/admin | Admin REST handlers under /api/v1/admin, admin group membership (ADMIN_GROUPS) |
internal/services | Business logic shared by handlers: environments, workspace detail, logs, statistics, usage, audit |
internal/proxy | Dev and test reverse proxies, WebSocket tunnelling |
internal/auth | OIDC client (discovery retried in the background), encrypted session cookies, bridge tickets |
internal/clientcert | Client certificates: configuration, header dialects, certificate verification, CRL revocation checks, the break-glass mapping |
internal/domain | Typed identifiers (OwnerID, WorkspaceName, WorkspaceTarget) and claims |
internal/k8s | Workspace lookups, the restrictions in effect for a workspace, and the activity throttle |
internal/prom | A minimal Prometheus query client |
internal/tlsclient | mTLS client credentials with hot reload |
operator/api/v1alpha1/validation (in the operator tree) | Validation rules shared with the admission webhooks |
web/ | The dashboard, embedded into the binary |
Routing
Requests are dispatched on the Host header (the port is ignored):
flowchart LR
req[Incoming request] --> host{Host header}
host -->|dashboard| dash["/auth/* OIDC handlers and break-glass<br/>/api/v1/* REST API<br/>/ dashboard"]
host -->|dev| dev["/auth/bridge<br/>dev proxy"]
host -->|test| test["/auth/bridge<br/>test proxy"]
host -->|any other| nf[404]
Everything except the OIDC endpoints, /auth/break-glass and /auth/bridge
requires a session. Unauthenticated API calls get 401 JSON; browser
navigations are redirected to the login. On the dashboard host, every
state-changing request must carry the dashboard’s own Origin before anything
else runs (Cross-site request check).
With the client-certificate gate on (CLIENT_CERT_ENABLED), the router is
served only on a second listener, port 8444, which requires a TLS client
certificate from the ingress (issued by kornercode’s internal CA, DNS name
kornercode-ingress). In front of the host dispatch, the gate verifies the
person’s certificate forwarded in a header and checks its CN against the
session, on every request and every host. The plain listeners answer
/healthz and 404 for everything else, so they never read the certificate
header. With the gate off, the plain listeners serve the router and there is
no second listener. See
Client-certificate gate.
Authentication and sessions
- Identity provider availability. OIDC discovery runs in the background
and is retried until it succeeds, so the gateway starts and stays ready
while the provider is unreachable. Until then
/auth/loginand/auth/callbackanswer with an “identity provider is unavailable” page (with the break-glass button when break-glass is on), and existing sessions keep working: cookies are checked locally, with no call to the provider. - Login.
/auth/loginstarts an OIDC authorization-code flow with state and nonce, and remembers where the user was going (a validated path, or adev/testURL)./auth/callbackverifies the token, derives the user’s identity from thesubclaim, with the gate on requires the identity claim (OIDC_IDENTITY_CLAIM) to equal the certificate’s CN and binds the session to it, stores the claims in an encrypted session cookie, and sends the user back to the page they asked for. - Break-glass. With the gate on and a mapping,
POST /auth/break-glass(a button on the sign-in pages) opens a session for the mapping entry of the certificate’s CN, without contacting the identity provider. - Identity. A user is their OIDC
sub(theOwnerID); thepreferred_usernameis display-only and is stored on workspaces as thecode.kornercloud.dev/owner-nameannotation (ADR 0012). - Sessions. Cookies are encrypted and authenticated (AES-256-CTR with
HMAC-SHA256, keys derived from
SESSION_SECRETwith HKDF), host-only,SecureandHttpOnly, with sliding expiry. Each hostname holds its own session. - Bridge tickets. To open the IDE or the test application, the dashboard
requests a ticket (
POST /api/v1/bridge/ticket), valid for 30 seconds and bound to the target host, and the browser redeems it at<host>/auth/bridge, which sets that host’s session (ADR 0004). - Admins. A user is an administrator when their groups claim
(
OIDC_GROUPS_CLAIM, defaultgroups) contains a group listed inADMIN_GROUPS, or when they signed in through break-glass. See authentication for the details, including how quickly a demotion takes effect.
Proxies
The dev proxy resolves the signed-in user’s workspace (their team’s namespace,
their OwnerID) and forwards the request to its Service, over mTLS when it is
enabled. WebSocket upgrades, which code-server uses heavily, are tunnelled
after an Origin check against the gateway’s own hostnames. Client-supplied
X-Forwarded-* headers are replaced, and the gateway’s cookies and
Authorization header are stripped before the request leaves.
Every proxied request records activity (status.lastActivityTime), throttled
to one update per minute per user and replica, which drives the inactivity
timeout. A user with no workspace is redirected to the dashboard.
An administrator’s dev-host session can instead be pinned to another user’s workspace through a ticket that names it. The proxy then routes to that workspace, checks admin membership again on every request, and records no user activity (ADR 0010).
The test proxy works the same way for spec.testPort.
Both proxies apply the restrictions in effect for the workspace, read from its
Team and the platform’s PLATFORM_RESTRICTIONS on each request: with
blockAdminIDEAccess an admin-view request is refused with 403 and open admin
WebSocket connections are closed, and with disableTestEndpoint the test
proxy refuses everyone. A Team that can’t be read fails the request. The other
restrictions are code-server flags set by the operator (see
Restrictions).
REST API
All endpoints are under /api/v1 on the dashboard host and exchange JSON.
Request bodies reject unknown fields.
Tenant endpoints
| Method and path | Purpose |
|---|---|
GET /me | Identity, team, allowed profiles, mounts, dev/test hosts, whether Prometheus is configured, admin flag |
GET /templates | Workspace profiles the user may choose |
GET /environments | The user’s workspaces |
POST /environments | Create a workspace ({"profileRef", "testPort"}); one per user and team |
GET /environments/{name} | One workspace |
PATCH /environments/{name} | Extend the TTL ({"ttl": "48h"}), within the profile’s maxTTL |
POST /environments/{name}/restart | Ask the operator to replace the workspace pod |
DELETE /environments/{name} | Delete the workspace (volumes are kept) |
GET /workspace | Detail of the user’s workspace: pod, service, mounts, security, network policies, events |
GET /workspace/usage | Live CPU, memory and storage usage of the user’s workspace (Prometheus) |
GET /workspace/logs, GET /workspace/logs/stream | code-server logs (tail, or server-sent events) |
GET /storage, DELETE /storage/{name} | The user’s own volumes |
POST /bridge/ticket?target=dev|test | A bridge ticket for the dev or test host |
Admin endpoints
| Method and path | Purpose |
|---|---|
GET /admin/workspaces | All workspaces, each with a pod summary (phase, readiness, waiting reason) when its pod exists |
GET /admin/workspaces/{ns}/{name}/detail | Detail of any workspace |
GET /admin/workspaces/{ns}/{name}/logs/stream | Logs of any workspace |
PATCH /admin/workspaces/{ns}/{name} | Change the test port |
DELETE /admin/workspaces/{ns}/{name} | Delete any workspace |
GET, POST /admin/profiles, GET, PUT, DELETE /admin/profiles/{name} | Workspace profiles |
GET, POST /admin/teams, GET, PUT, DELETE /admin/teams/{name} | Teams |
GET, POST /admin/security-profiles, GET, PUT, DELETE /admin/security-profiles/{name} | Security profiles |
GET /admin/network-policies | The predefined NetworkPolicies available to security profiles |
GET /admin/storage, DELETE /admin/storage/{ns}/{name} | All volumes with their state (in-use, idle, orphaned); delete an unused one |
GET /admin/stats | Counts by phase, team and profile; reservations; activity |
GET /admin/usage | Usage per workspace and per team (Prometheus) |
GET /admin/metrics | Read-only Prometheus query proxy for the Statistics charts, when Prometheus is configured |
POST /bridge/ticket?target=dev&workspace={ns}/{name} | Open another user’s IDE (audited) |
Every admin request is audited with a structured log line and a metric. Tenant actions on a workspace (create, extend, restart, delete) and admin access to an IDE are also recorded as Kubernetes events on the workspace, which its owner sees in the dashboard.
Services
Handlers stay thin; the logic lives in internal/services, constructed once
at startup and shared by all requests:
| Service | Responsibility |
|---|---|
EnvironmentService | Create, list, extend, restart and delete the caller’s workspaces; ownership checks; audit events |
DetailService | The workspace detail view (resource, pod, service, mounts, security, events) |
LogsService | Log tail and streaming, independent of the transport |
StatsService | Cluster counts for the Statistics page |
UsageService | Usage against requests per workspace and team; volume state |
AuditService | Audit trail: structured logs, metrics, Kubernetes events |
Usage insights
When PROMETHEUS_URL is set, the gateway reads container CPU and memory from
cAdvisor and volume usage from the kubelet, and compares them with the
requests and limits in the pod specs. The dashboard flags workspaces that use
far less than they reserve (waste, under 25 % of the request) or more
(hog, above the request or above 90 % of the limit). The gateway builds all
queries itself from fixed templates and validated names; no client input is
ever passed into PromQL. Unknown values are reported as unknown, never as zero
(ADR 0011).
Dashboard
The dashboard is a single page built with Alpine.js
and plain CSS, embedded into the binary with go:embed and served without a
build step. Pure logic lives in web/js/lib/ (table sorting and filtering,
usage flags and formatting, durations, lifecycle limits, chart geometry,
spec editing) and is unit-tested with Node’s built-in test runner
(make test-web).
Configuration (environment variables and Helm values) is listed in the configuration reference.