Gateway Auto-Registration Guide
This guide explains how to configure and deploy STOA gateways with automatic registration to the Control Plane.
This feature is defined in ADR-036: Gateway Auto-Registration.
Overviewβ
STOA gateways can automatically register with the Control Plane at startup, eliminating the need for manual registration via API calls. This provides an "Apple ecosystem" experience where gateways appear in the Console UI within seconds of deployment.
Key benefits:
- Zero-config deployment (2 environment variables)
- Automatic re-registration on restart
- Real-time health visibility via heartbeat
- Self-healing (gateway recovery is automatic)
Architectureβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Control Plane API β
β β
β βββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββ β
β β Gateway Internal β β Gateway Health Worker β β
β β /v1/internal/gateways β Marks stale gateways OFFLINE β β
β β - /register β β (90s timeout) β β
β β - /{id}/heartbeat β ββββββββββββββββββββββββββββββββββ β
β β - /{id}/config β β
β βββββββββββ¬ββββββββββββ β
ββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β HTTPS (X-Gateway-Key header)
β
ββββββββββ΄βββββββββ ββββββββββββββββββ
β STOA Gateway β β STOA Sidecar β
β (edge-mcp) β β + Kong β
β β β β
β 1. Register β β ext_authz β
β 2. Heartbeat β β β β
β (30s) β β Policy/Meter β
βββββββββββββββββββ ββββββββββββββββββ
Quick Startβ
Tier 1: STOA Native Gatewayβ
Deploy a STOA gateway with automatic registration:
# Minimal registration configuration (not a complete Ready deployment)
export STOA_CONTROL_PLANE_URL="https://api.<YOUR_DOMAIN>"
export STOA_CONTROL_PLANE_API_KEY="<GATEWAY_API_KEY>"
# Start the gateway
./stoa-gateway
The two variables above configure registration only. STOA_POLICY_BOOT_TENANTS defaults to an empty list, so this example leaves /ready returning HTTP 503 even if registration succeeds. Before starting a gateway that must become Ready, also set STOA_POLICY_BOOT_TENANTS="<TENANT_ID>" (comma-separated for multiple existing tenants) and configure policy-loading dependencies: reachable Control Plane and Keycloak services, a Keycloak service client using private_key_jwt with a mounted signing key, and authorization to read the tenants' tool permissions. The registration API key or a Keycloak client secret alone cannot authenticate these policy reads. A complete, fresh tool policy must load, and a configured policy trust set must load successfully. See Startup Policy and Readiness for the Helm extraEnv setting and signing-key configuration. All other readiness checks must also pass.
The gateway will:
- Derive identity from hostname + mode + environment
- Call
POST /v1/internal/gateways/register - Start heartbeat loop (every 30 seconds)
- Appear in Console UI at
/gateways
Tier 2: Sidecar modeβ
A same-pod companion is a second container that answers POST /authz. Registration uses the same Control Plane variables as any other STOA process. The repository does not ship a Kong, Envoy, or webMethods plugin, and KONG_PLUGINS / KONG_EXT_AUTHZ_URL are not a demonstrated Kong configuration. The host must send the JSON body in Companion usage.
# Illustrative co-location only. The host container must call
# POST http://127.0.0.1:8081/authz itself. Pin the image digest
# your release uses; do not rely on a floating tag.
apiVersion: apps/v1
kind: Deployment
metadata:
name: host-with-stoa-sidecar
spec:
selector:
matchLabels:
app: host-with-stoa-sidecar
template:
metadata:
labels:
app: host-with-stoa-sidecar
spec:
containers:
- name: gateway
image: <your-gateway-image>
- name: stoa-sidecar
image: ghcr.io/stoa-platform/stoa-gateway
env:
- name: STOA_GATEWAY_MODE
value: "sidecar"
- name: STOA_PORT
value: "8081"
- name: STOA_CONTROL_PLANE_URL
value: "https://api.<YOUR_DOMAIN>"
- name: STOA_CONTROL_PLANE_API_KEY
valueFrom:
secretKeyRef:
name: stoa-sidecar-secrets
key: STOA_CONTROL_PLANE_API_KEY
ports:
- containerPort: 8081
/authz trusts the JSON user and does not validate a token. The process binds 0.0.0.0 and STOA_PORT. Putting the containers in one pod does not, by itself, prove the host calls localhost. See Companion usage. GitOps sync to the gateway admin API is stoa-connect.
Control Plane Configurationβ
1. Create Gateway API Keysβ
Configure the Control Plane to accept gateway registrations:
# Create Kubernetes secret with API keys
kubectl create secret generic stoa-gateway-api-keys \
--namespace stoa-system \
--from-literal=GATEWAY_API_KEYS="<GATEWAY_API_KEY>,<SECOND_GATEWAY_API_KEY>"
Key format: Any string, but we recommend the format gw_{environment}_{random}.
Key rotation: Multiple keys are supported (comma-separated). Add a new key before removing the old one.
2. Deploy Control Plane with Keysβ
Patch the Control Plane deployment:
kubectl patch deployment stoa-control-plane-api -n stoa-system \
--type='json' \
-p='[{"op": "add", "path": "/spec/template/spec/containers/0/env/-", "value": {"name": "GATEWAY_API_KEYS", "valueFrom": {"secretKeyRef": {"name": "stoa-gateway-api-keys", "key": "GATEWAY_API_KEYS"}}}}]'
The stoa-platform chart does not deploy the Control Plane API or expose a controlPlane.env setting. Configure GATEWAY_API_KEYS in your existing Control Plane deployment.
Gateway Configuration Referenceβ
Environment Variablesβ
| Variable | Required | Default | Description |
|---|---|---|---|
STOA_CONTROL_PLANE_URL | Yes | - | Control Plane API URL |
STOA_CONTROL_PLANE_API_KEY | Yes | - | Shared secret for authentication |
STOA_GATEWAY_MODE | No | edge-mcp | Gateway mode: edge-mcp, sidecar, proxy, shadow |
STOA_ENVIRONMENT | No | dev | Environment identifier for grouping |
The chart comment also lists connect, but the Rust runtime does not accept it for STOA_GATEWAY_MODE. Use edge-mcp, sidecar, proxy, or shadow for stoaGateway.mode.
The Rust gateway registers with tenant_id: null (platform-wide); STOA_TENANT_ID is not a supported runtime setting and does not provide tenant isolation.
Registration Payloadβ
The gateway sends this payload at startup:
{
"hostname": "<GATEWAY_HOSTNAME>",
"mode": "edge-mcp",
"version": "0.1.0",
"environment": "prod",
"capabilities": ["rest", "mcp", "sse", "oidc", "rate_limiting"],
"admin_url": "http://<GATEWAY_HOSTNAME>:8080",
"tenant_id": null
}
Heartbeat Payloadβ
Every 30 seconds:
{
"uptime_seconds": 3600,
"routes_count": 15,
"policies_count": 5,
"requests_total": 10000,
"error_rate": 0.01
}
Identity Derivationβ
Gateway identity is deterministic: {hostname}-{mode_normalized}-{environment}
Mode normalization removes underscores only; the hyphen in edge-mcp is preserved.
| Hostname | Mode | Environment | Derived Name |
|---|---|---|---|
stoa-gw-abc123 | edge-mcp | prod | stoa-gw-abc123-edge-mcp-prod |
kong-sidecar-xyz | sidecar | staging | kong-sidecar-xyz-sidecar-staging |
This enables:
- Idempotent registration: Same gateway restarts update rather than duplicate
- Clear naming: Easy to identify in Console UI
- Environment filtering: Group gateways by environment
Helm Chart Configurationβ
STOA Gateway (Tier 1)β
Set stoaGateway.secretName to an existing Kubernetes Secret. To populate it from Vault instead, enable the optional ExternalSecret as shown below; this requires External Secrets Operator and an existing ClusterSecretStore named vault-backend:
# values.yaml
stoaGateway:
enabled: true
replicas: 2
# Control Plane connection
controlPlaneUrl: "http://stoa-control-plane-api.stoa-system.svc.cluster.local:80"
# Secret keys: STOA_CONTROL_PLANE_API_KEY, STOA_KEYCLOAK_CLIENT_SECRET
# STOA_CONTROL_PLANE_API_KEY is required for auto-registration.
# Without it, the gateway skips registration and runs in standalone mode.
secretName: stoa-gateway-secrets
# ExternalSecret (Vault-backed) β syncs secrets from Vault into K8s Secret
externalSecret:
enabled: true
refreshInterval: 1h
secretStoreRef: vault-backend
vaultPath: "<VAULT_GATEWAY_PATH>" # Must contain both STOA_* properties listed above
The deployment template injects the secret as an environment variable:
- name: STOA_CONTROL_PLANE_API_KEY
valueFrom:
secretKeyRef:
name: stoa-gateway-secrets
key: STOA_CONTROL_PLANE_API_KEY
optional: true # Gateway runs standalone if missing
Replace <VAULT_GATEWAY_PATH> with a Vault path containing STOA_CONTROL_PLANE_API_KEY and STOA_KEYCLOAK_CLIENT_SECRET. The ExternalSecret uses those exact names for both Vault properties and Kubernetes Secret keys. Missing properties prevent successful secret synchronization; without STOA_CONTROL_PLANE_API_KEY, the gateway skips auto-registration.
STOA sidecar (Tier 2)β
The platform chart renders the same-pod pod only when both flags below are true. stoaSidecar.enabled defaults to false. The chart appends EXT_AUTHZ_URL=http://localhost:8081/authz on the target container. It reads secret key STOA_CONTROL_PLANE_API_KEY (optional: true). stoaSidecar.image is ghcr.io/stoa-platform/stoa-gateway pinned by digest in values.yaml, which is the published gateway image. The unpublished light build profile is not what the chart runs.
stoaSidecar:
enabled: true
mainGateway:
enabled: true
image:
repository: "<your-gateway-repository>"
digest: "<your-gateway-digest>"
The chart also injects Keycloak variables and policyEnabled. POST /authz does not validate tokens and does not evaluate Control Plane or OPA policies. Supply the target image yourself. This documentation does not name a webMethods image. Details and limits: Companion usage and webMethods and the companion.
Console UIβ
After registration, gateways appear at Console > Gateways with automatic 30-second polling (via TanStack React Query). No manual refresh needed.
| Column | Description |
|---|---|
| Name | Derived instance name |
| Type | stoa, stoa_sidecar, webmethods, etc. |
| Status | ONLINE, OFFLINE, DEGRADED |
| Environment | dev, staging, prod |
| Live Indicator | Pulsing green dot if heartbeat received within 90s |
| Capabilities | Feature badges |
Status Indicatorsβ
| Status | Meaning | Visual |
|---|---|---|
| ONLINE | Heartbeat received within 90s | Pulsing green dot |
| OFFLINE | No heartbeat for > 90s | Gray dot |
| DEGRADED | Instance status reported as degraded by the Control Plane | Yellow status badge |
Gateway Detail Panelβ
Click a gateway card to open the detail panel showing heartbeat metrics:
| Metric | Source | Example |
|---|---|---|
| Uptime | health_details.uptime_seconds | 1h 30m |
| Routes | health_details.routes_count | 15 |
| Policies | health_details.policies_count | 5 |
| Requests | health_details.requests_total | 10,000 |
| Error Rate | health_details.error_rate | 2.0% |
| Registered At | health_details.registered_at | 2026-02-06 |
Each accepted heartbeat sets the instance status to ONLINE. An error rate above 5% highlights the Error Rate metric in the detail panel; it does not set the instance status to DEGRADED.
Deep Readiness Probeβ
The gateway's /ready endpoint checks required policy state, Control Plane connectivity when configured, and OIDC provider reachability when authentication is enabled before reporting readiness.
If a check fails, the endpoint returns 503 SERVICE UNAVAILABLE with a descriptive message:
NOT READY: Control Plane unreachableNOT READY: OIDC provider unreachable
This prevents Kubernetes from routing traffic to gateways that cannot enforce policies or validate tokens.
Config Fetchβ
The Control Plane exposes a configuration endpoint for registered gateways:
GET /v1/internal/gateways/{id}/config
Header: X-Gateway-Key: <GATEWAY_API_KEY>
The response includes:
- pending_deployments β API deployments targeted at this gateway
- pending_policies β Rate limiting, access control, and governance policies
The Rust gateway registration lifecycle registers the instance and sends heartbeats. It does not automatically poll this endpoint or apply its pending deployments and policies.
Troubleshootingβ
Gateway Not Appearing in Consoleβ
-
Check gateway logs for registration errors:
kubectl logs -n stoa-system deployment/stoa-gateway | grep -i register -
Verify Control Plane has API keys configured:
kubectl describe secret stoa-gateway-api-keys -n stoa-system -
Check Control Plane logs:
kubectl logs -n stoa-system deployment/stoa-control-plane-api | grep -i gateway -
Test registration endpoint manually:
curl -X POST "${STOA_CONTROL_PLANE_URL}/v1/internal/gateways/register" \
-H "X-Gateway-Key: <GATEWAY_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"hostname": "<GATEWAY_HOSTNAME>",
"mode": "edge-mcp",
"version": "0.1.0",
"environment": "dev",
"capabilities": ["rest"],
"admin_url": "http://<GATEWAY_HOSTNAME>:8080"
}'
Gateway Shows OFFLINEβ
-
Check heartbeat is being sent:
kubectl logs -n stoa-system deployment/stoa-gateway | grep heartbeat -
Verify network connectivity to Control Plane:
kubectl exec -n stoa-system deployment/stoa-gateway -- \
curl --fail --silent --show-error http://stoa-control-plane-api.stoa-system.svc.cluster.local:80/health/live
Registration Returns 503β
Cause: GATEWAY_API_KEYS not configured in Control Plane.
Fix:
kubectl create secret generic stoa-gateway-api-keys \
--namespace stoa-system \
--from-literal=GATEWAY_API_KEYS="<GATEWAY_API_KEY>"
kubectl patch deployment stoa-control-plane-api -n stoa-system \
--type='json' \
-p='[{"op": "add", "path": "/spec/template/spec/containers/0/env/-", "value": {"name": "GATEWAY_API_KEYS", "valueFrom": {"secretKeyRef": {"name": "stoa-gateway-api-keys", "key": "GATEWAY_API_KEYS"}}}}]'
kubectl rollout status deployment/stoa-control-plane-api -n stoa-system
Registration Returns 401β
Cause: Gateway API key doesn't match any key in GATEWAY_API_KEYS.
Fix: Check that the Secret contains GATEWAY_API_KEYS, then compare its value with the gateway credential through your secret manager without printing either value:
kubectl describe secret stoa-gateway-api-keys -n stoa-system
Security Considerationsβ
API Key Managementβ
- Never commit keys to Git: Use Kubernetes Secrets or external secrets manager
- Use environment-specific keys: Different keys for dev, staging, prod
- Rotate keys periodically: Add new key β update gateways β remove old key
- Audit registrations: Check Control Plane logs for unexpected registrations
Network Securityβ
- Internal endpoints (
/v1/internal/*) should NOT be exposed via public ingress - Use Kubernetes NetworkPolicies to restrict which pods can call the internal API
- Consider mTLS for high-security deployments (future enhancement)
Key Rotation Procedureβ
- Add new key to Control Plane (comma-separated)
- Restart Control Plane to pick up new key
- Update gateways to use new key
- Remove old key after all gateways updated
Related Documentationβ
- ADR-036: Gateway Auto-Registration β Architecture decision record
- ADR-024: Unified Gateway Architecture β Gateway modes
- ADR-035: Gateway Adapter Pattern β How CP orchestrates gateways
- Companion usage β Allow/deny companion, application callout, and mesh limits
- webMethods and the companion β Why a live webMethods sidecar is not demonstrated