Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript
52.1 KB
Raw Blame
apiVersion: v1
kind: ConfigMap
metadata:
  name: control-api-config
  namespace: control-plane
  labels:
    app: control-api
data:
  CONTROL_API_PORT: '8090'
  CONTROL_API_JSON_BODY_LIMIT: 150mb
  CONTROL_API_PG_CONNECTION_STRING: postgres://postgres:[email protected]:5432/profiles
  CONTROL_API_NAMESPACE: mcp-server
  CONTROL_API_HOSTS_NAMESPACE: mcp-host
  CONTROL_API_CONTEXTS_NAMESPACE: mcp-server
  CONTROL_API_MCP_SERVERS_NAMESPACE: mcp-server
  CONTROL_API_COMMUNICATION_CHANNELS_NAMESPACE: channels
  CONTROL_API_SECRETS_NAMESPACE: mcp-host
  CONTROL_API_JWT_ISSUER: control-api
  CONTROL_API_JWT_AUDIENCE: dev-profile-ui
  CONTROL_API_RPC_JWT_ISSUER: control-api
  CONTROL_API_RPC_JWT_AUDIENCE: rpc-proxy
  CONTROL_API_RPC_TOKEN_TTL_SECONDS: '300'
  CONTROL_API_ADMIN_JWT_ISSUER: control-api
  CONTROL_API_ADMIN_JWT_AUDIENCE: control-ui
  CONTROL_API_ADMIN_JWT_TTL_SECONDS: '3600'
  CONTROL_API_CODEX_SUBSCRIPTION_ENABLED: 'false'
  CONTROL_API_GROK_SUBSCRIPTION_ENABLED: 'false'
  # ClusterIP admin port only. NetworkPolicy admits Control API, not siblings.
  CODEX_LLM_PROXY_ADMIN_URL: http://codex-llm-proxy.control-plane.svc.cluster.local:8081
  GROK_LLM_PROXY_ADMIN_URL: http://grok-llm-proxy.control-plane.svc.cluster.local:8081
  CONTROL_API_ADMIN_BOOTSTRAP_USERNAME: admin
  CONTROL_API_ADMIN_BOOTSTRAP_EMAIL: ''
  CONTROL_API_ADMIN_AUTH_MAX_FAILURES: '5'
  CONTROL_API_ADMIN_AUTH_LOCK_MINUTES: '15'
  CONTROL_API_POLICY_AUTH_AUDIENCE: control-api
  TRACING_APPROVAL_PROMPT_HISTORY_ENABLED: 'false'
  TRACING_APPROVAL_PROMPT_HISTORY_MAX_BYTES: '16384'
  TRACING_APPROVAL_PROMPT_HISTORY_RETENTION_DAYS: '30'
  TRACING_APPROVAL_PROMPT_HISTORY_KEY_VERSION: 'v1'
  CONTROL_API_GOOGLE_CLIENT_ID: replace-with-google-client-id.apps.googleusercontent.com
  # member-registration-service runs as an extracted sibling in the `registration`
  # namespace locally (and centrally at https://registration.evenfire.ai — the
  # gcp overlays override this BASE_URL to the hub). control-api authenticates
  # with a per-tenant HMAC JWT (HMAC secret + kid + tenant id), so there is no
  # static SERVICE_TOKEN/SERVICE_NAME for this hop anymore.
  CONTROL_API_MEMBER_REGISTRATION_SERVICE_BASE_URL: http://member-registration-service.registration.svc.cluster.local:8092/api/v1
  CONTROL_API_DESKTOP_EXTERNAL_REST_API_BASE_URL: http://127.0.0.1:8091
  CONTROL_API_DESKTOP_RPC_PROXY_BASE_URL: http://127.0.0.1:8094
  CONTROL_API_DESKTOP_PROFILE_UI_BASE_URL: http://127.0.0.1:3001
  CONTROL_API_DESKTOP_APP_NAME: Evenfire
  # Inter-service tokens were removed from this ConfigMap on purpose: they now
  # live in the `control-api-internal-tokens` Secret (base canary + patched
  # out-of-band). The member-registration HMAC secret
  # (CONTROL_API_MEMBER_REGISTRATION_HMAC_SECRET) is patched there too.
  # Kustomize overlays no longer need to patch those token keys.
  # See `deploy/base/control-plane/secrets-canary.yaml`.
  WORKFLOW_APPROVAL_ACCESS_TTL_SEC: '600'
  WORKFLOW_APPROVAL_REFRESH_TTL_SEC: '3600'
  WORKFLOW_APPROVAL_DEFAULT_TTL_SEC: '86400'
  WORKFLOW_APPROVAL_NOTIFICATION_DELIVERY_ENABLED: "true"
  WORKFLOW_APPROVAL_NOTIFICATION_DELIVERY_INTERVAL_MS: "5000"
  WORKFLOW_APPROVAL_NOTIFICATION_DELIVERY_BATCH_SIZE: "10"
  APPROVAL_RL_REQUEST_PER_MIN: "600"
  APPROVAL_RL_REFRESH_PER_MIN: "100"
  APPROVAL_RL_REISSUE_PER_MIN: "25"
  CONTROL_API_OAUTH_BROKER_RL_PER_MIN: "300"
  CONTROL_API_HOST_WAKE_RL_PER_MIN: "150"
  # Plugin Workload SDK platform rate limits (issue #348). Per-run SDK quotas
  # (maxRequestsPerRun / maxNotificationsPerRun) are deprecated and ignored;
  # Method quotas use their existing trailing 60s window. Authenticated request
  # and edge budgets use the PG calendar minute; anonymous IP backstops retain
  # first-hit windows. Defaults below mirror control-api/src/config.ts.
  # Healthy static prompts cost three credential operations and six/seven SDK
  # API requests; the 1800/6000 defaults keep the prompt600 allowance reachable
  # without removing fresh capability proof, either Secret check or redemption.
  CONTROL_API_PLUGIN_SDK_NOTIFICATIONS_PER_MIN: "750"
  CONTROL_API_PLUGIN_SDK_PROMPTBRIDGE_PER_MIN: "600"
  CONTROL_API_PLUGIN_SDK_REQUEST_BUCKET_PER_MIN: "6000"
  CONTROL_API_PLUGIN_SDK_PREAUTH_PER_MIN: "600"
  CONTROL_API_PLUGIN_SDK_AUTHENTICATED_PREAUTH_PER_MIN: "6000"
  CONTROL_API_PLUGIN_SDK_ADMIN_PER_MIN: "600"
  CONTROL_API_PLUGIN_SDK_INTERNAL_PER_MIN: "600"
  CONTROL_API_PLUGIN_SDK_CREDENTIAL_PER_MIN: "1800"
  CONTROL_API_ADMIN_WORKFLOW_READ_PER_MIN: "300"
  CONTROL_API_ADMIN_WORKFLOW_GRANT_READ_PER_MIN: "300"
  CONTROL_API_ADMIN_WORKFLOW_GRANT_WRITE_PER_MIN: "100"
  CONTROL_API_ADMIN_WORKFLOW_TRIGGER_PER_MIN: "50"
  CONTROL_API_ADMIN_OUTPUTS_READ_PER_MIN: "150"
  CONTROL_API_LLM_PROVIDER_ATTEMPT_AUTHORIZE_PER_MIN: "300"
  CONTROL_API_LLM_PROVIDER_ATTEMPT_AUTHORIZE_ANONYMOUS_IP_PER_MIN: "60"
  CONTROL_API_ADMIN_REGISTRY_KEYS_PER_MIN: "150"
  CONTROL_API_ADMIN_REGISTRY_GRANTS_PER_MIN: "150"
  CONTROL_API_ADMIN_REGISTRY_CONNECT_STATUS_PER_MIN: "150"
  CONTROL_API_ADMIN_REGISTRY_CONNECT_REQUEST_PER_MIN: "15"
  CONTROL_API_ADMIN_REGISTRY_CONNECT_RECOVERY_PER_MIN: "50"
  CONTROL_API_ADMIN_CONNECTOR_DELETE_EDGE_PER_MIN: "300"
  CONTROL_API_ADMIN_CONNECTOR_DELETE_PER_MIN: "150"
  CONTROL_API_ADMIN_GFS_GRANTS_PER_MIN: "150"
  CONTROL_API_ADMIN_GFS_SHARES_PER_MIN: "150"
  CONTROL_API_ADMIN_GFS_LEGACY_GRANT_REPORT_PER_MIN: "150"
  # Hard ceiling for caller-provided ttlSeconds. Defaults to 48h so a client
  # asking for ttlSeconds=604800 (code default) can't freeze a workflow step
  # for a full week. Overlays may tighten further for stricter environments.
  WORKFLOW_APPROVAL_MAX_TTL_SEC: '172800'
  WORKFLOW_APPROVAL_EXPIRY_INTERVAL_MS: '60000'
  # Terminal approvals are retained in the live table for 180 days, then
  # copied to workflow_approval_requests_archive by the daily archive cron.
  APPROVAL_RETENTION_DAYS: '180'
  APPROVAL_ARCHIVE_BATCH_SIZE: '500'
  # TTL for mcpHostJwt control tokens used by runtime mcp-host workflow triggers.
  MCP_HOST_JWT_CONTROL_TTL_SEC: '600'
  CLERUM_WORKFLOW_MAX_WORKLOADS_PER_RECIPE: '25'
  CLERUM_WORKFLOW_UI_EGRESS_INTERNAL_MAX_ITEMS: '25'
  CLERUM_WORKFLOW_MAX_STEPS: '100'
  CLERUM_WORKFLOW_STEP_DEPENDS_ON_MAX_ITEMS: '100'
  CLERUM_WORKFLOW_STEP_ALLOWED_TOOLS_MAX_ITEMS: '50'
  CLERUM_WORKFLOW_STEP_MCP_SERVERS_MAX_ITEMS: '20'
  CLERUM_ATTACHMENT_MAX_BYTES: '52428800'
  # Plugin image-host allowlist (Phase 2.3) — audit mode by default. Base ships a
  # vendor-neutral default; environment overlays override this with the image
  # prefixes for their own registry.
  CONTROL_API_ALLOWED_IMAGE_PREFIXES: "ghcr.io/evenfire-ai/,mongodb/,mcr.microsoft.com/,clerum/"
  CONTROL_API_ENFORCE_IMAGE_ALLOWLIST: "false"
  # LLM catalog discovery sync cron (spec 09 Fase 4). Non-destructive; code
  # default off. Enabled here: the first sync runs a few seconds after
  # control-api starts (fills image_input evidence), then every interval.
  # Interval + plausibility floors keep their code defaults.
  LLM_CATALOG_SYNC_CRON_ENABLED: "true"
  # Subscription catalog reconciliation cron. A grant's catalog is written at
  # sign-in and never refreshed on its own, so a model the vendor publishes
  # afterwards stays invisible to that subscription until an operator syncs it
  # from the Hub. This cron re-runs that same per-connection sync periodically.
  # Off by default: unlike the discovery sync above (one call to models.dev per
  # tick), each tick calls the broker once PER CONNECTED GRANT, and a Grok
  # refresh inside the token skew rotates the refresh token. Turn it on
  # deliberately, per deployment.
  SUBSCRIPTION_CATALOG_SYNC_CRON_ENABLED: "false"
  # Floor is 15 minutes (control-api refuses to boot below it). The code default
  # is 6h; the key is declared here so the interval is visible where it is set.
  SUBSCRIPTION_CATALOG_SYNC_INTERVAL_MS: "21600000"
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: control-api-rpc-gateway
  namespace: control-plane
  labels:
    app: control-api-rpc-gateway
data:
  nginx.conf: |
    pid /tmp/nginx.pid;
    worker_processes auto;
    events {
      worker_connections 1024;
    }
    http {
      client_body_temp_path /tmp/client_temp;
      proxy_temp_path /tmp/proxy_temp;
      fastcgi_temp_path /tmp/fastcgi_temp;
      uwsgi_temp_path /tmp/uwsgi_temp;
      scgi_temp_path /tmp/scgi_temp;

      access_log /dev/stdout;
      error_log /dev/stderr warn;

      upstream control_api_upstream {
        server control-api.control-plane.svc.cluster.local:8090;
      }

      server {
        listen 8090;
        server_name _;

        location = /health {
          return 200 '{"status":"ok"}';
          add_header Content-Type application/json;
        }

        # G1-10 (#720): a 502 generated here means control-api produced no
        # valid response (connect refused, closed before a response, invalid
        # header). In the last two cases control-api may already have
        # processed the request, so the code means "no response", not "never
        # received". A 502 control-api returns passes through, because
        # `proxy_intercept_errors` is off. Only the redeem locations, whose
        # failure reaches the user, map it.
        location @control_plane_unavailable {
          default_type application/json;
          add_header Cache-Control "no-store, private" always;
          add_header Pragma "no-cache" always;
          add_header X-Content-Type-Options "nosniff" always;
          return 503 '{"error":"control_plane_unavailable"}';
        }

        # G1-12 (#820): nginx generates a 504 for a connect timeout and for a
        # read or send timeout. During a control-api restart the Service has
        # no endpoint and the SYN is dropped, so the connect times out. nginx
        # sets $upstream_connect_time only once the connection is made
        # (ngx_http_upstream_send_request), so "-" here means control-api
        # never received the request; only then is it mapped. A read or send
        # timeout keeps nginx's own 504: control-api may be alive and slow.
        location @control_plane_connect_timeout {
          default_type application/json;
          if ($upstream_connect_time = "-") {
            add_header Cache-Control "no-store, private" always;
            add_header Pragma "no-cache" always;
            add_header X-Content-Type-Options "nosniff" always;
            return 503 '{"error":"control_plane_unavailable"}';
          }
          return 504;
        }

        location ~ ^/api/v1/rpc/access/users/[^/]+/mcp-servers$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        # spec 11 U1: proactive connectors panel — tri-state read model.
        # rpc-proxy forwards the caller's rpc access token; control-api
        # authorizes via requireRpcTokenUserMatch. Must be allowlisted here or
        # rpc-proxy is 403'd at the edge (sibling of mcp-servers above).
        location ~ ^/api/v1/rpc/access/users/[^/]+/mcp-connectors$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        location ~ ^/api/v1/rpc/access/users/[^/]+/mcp-hosts/[^/]+$ {
          limit_except GET POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        # Stateless Agents — wake trigger for a suspended/draining host.
        # rpc-proxy forwards the caller's rpc access token; control-api
        # authorizes via requireRpcTokenHostMatch before any mutation.
        location ~ ^/api/v1/rpc/hosts/[^/]+/wake$ {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        # Spec §9.2 — sandbox-ui app picker (rpc-proxy fans out per-user
        # ACL lookup). control-api authenticates the call via
        # requireInternalService('rpc-proxy').
        location = /api/v1/internal/sandbox-ui/apps {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        # Spec §10 — sandbox-ui registry resolution; rpc-proxy hits
        # this on /session mint to resolve recipe → upstream Service.
        location ~ ^/api/v1/internal/sandbox-ui/registry/[^/]+/[^/]+$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        # Per-user OAuth background-consent bridge (rpc-proxy → control-api), all
        # gated server-side by requireInternalService('rpc-proxy'). The sandbox-ui
        # "Connect" embed POSTs authorize-url to start consent, POSTs token to
        # exchange the code, and DELETEs grant to disconnect. Each MUST be
        # allowlisted here or rpc-proxy is 403'd at the edge. The control-api test
        # `network/gateway intent` derives this list from the routes and fails CI
        # if a requireInternalService('rpc-proxy') route lacks a location.
        location = /api/v1/internal/sandbox-ui/oauth/authorize-url {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        location = /api/v1/internal/sandbox-ui/oauth/token {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        location = /api/v1/internal/sandbox-ui/oauth/grant {
          limit_except DELETE {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        # U5: mint a fresh authorize-URL for an OAuth mcp-server (reactive
        # consent). rpc-proxy is the sole caller; requireInternalService('rpc-proxy')
        # gates it at control-api.
        location = /api/v1/internal/mcp-oauth/authorize-url {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        location = /api/v1/internal/llm/provider-attempts/redeem {
          limit_except POST {
            deny all;
          }
          error_page 502 = @control_plane_unavailable;
          error_page 504 = @control_plane_connect_timeout;
          # Shorter than the proxy's 15 s redeem abort
          # (CONTROL_API_REQUEST_TIMEOUT_MS), so the proxy sees this answer.
          proxy_connect_timeout 5s;
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        # spec 11 U4: revoke an OAuth mcp-server grant (desktop "Disconnect").
        # rpc-proxy is the sole caller; requireInternalService('rpc-proxy') gates
        # it at control-api.
        location = /api/v1/internal/mcp-oauth/grant {
          limit_except DELETE {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        location = /api/v1/internal/llm/provider-attempts/finalize {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        location = /api/v1/internal/llm/grok/provider-attempts/redeem {
          limit_except POST {
            deny all;
          }
          error_page 502 = @control_plane_unavailable;
          error_page 504 = @control_plane_connect_timeout;
          # Shorter than the proxy's 15 s redeem abort
          # (CONTROL_API_REQUEST_TIMEOUT_MS), so the proxy sees this answer.
          proxy_connect_timeout 5s;
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        location = /api/v1/internal/llm/grok/provider-attempts/finalize {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        location / {
          return 403;
        }
      }
    }
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-workflow-approval-gateway
  namespace: control-plane
  labels:
    app: nginx-workflow-approval-gateway
data:
  nginx.conf: |
    pid /tmp/nginx.pid;
    worker_processes auto;
    events {
      worker_connections 1024;
    }
    http {
      client_body_temp_path /tmp/client_temp;
      proxy_temp_path /tmp/proxy_temp;
      fastcgi_temp_path /tmp/fastcgi_temp;
      uwsgi_temp_path /tmp/uwsgi_temp;
      scgi_temp_path /tmp/scgi_temp;

      log_format workflow_gateway_json escape=json
        '{"gateway":"workflow-approval","request_id":"$request_id","method":"$request_method","uri":"$uri","status":$status,"upstream_status":"$upstream_status","request_time":$request_time,"upstream_response_time":"$upstream_response_time"}';
      access_log /dev/stdout workflow_gateway_json;
      error_log /dev/stderr warn;

      upstream control_api_upstream {
        server control-api.control-plane.svc.cluster.local:8090;
      }

      server {
        listen 8092;
        server_name _;
        proxy_connect_timeout 5s;
        proxy_read_timeout 30s;
        proxy_send_timeout 30s;

        location = /health {
          return 200 '{"status":"ok"}';
          add_header Content-Type application/json;
        }

        # G1-10 (#720): a 502 generated here means control-api produced no
        # valid response (connect refused, closed before a response, invalid
        # header). In the last two cases control-api may already have
        # processed the request, so the code means "no response", not "never
        # received". A 502 control-api returns passes through, because
        # `proxy_intercept_errors` is off. Only the authorize location, whose
        # failure reaches the user, maps it.
        location @control_plane_unavailable {
          default_type application/json;
          add_header Cache-Control "no-store, private" always;
          add_header Pragma "no-cache" always;
          add_header X-Content-Type-Options "nosniff" always;
          return 503 '{"error":"control_plane_unavailable"}';
        }

        # G1-12 (#820): nginx generates a 504 for a connect timeout (this
        # server's proxy_connect_timeout) and for a read or send timeout.
        # During a control-api restart the Service has no endpoint and the SYN
        # is dropped, so the connect times out. nginx sets
        # $upstream_connect_time only once the connection is made
        # (ngx_http_upstream_send_request), so "-" here means control-api
        # never received the request; only then is it mapped. A read or send
        # timeout keeps nginx's own 504: control-api may be alive and slow.
        location @control_plane_connect_timeout {
          default_type application/json;
          if ($upstream_connect_time = "-") {
            add_header Cache-Control "no-store, private" always;
            add_header Pragma "no-cache" always;
            add_header X-Content-Type-Options "nosniff" always;
            return 503 '{"error":"control_plane_unavailable"}';
          }
          return 504;
        }

        # Runtime gateway only; provisioner issuance bypasses this route.

        location = /api/v1/workflow-approval-mediums/resolve {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/workflow-approval-mediums/link-sessions/confirm {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/workflow-approval-notifications/deliveries {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/workflow-approvals/pending/resolve {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/workflow-approval-mediums/telegram/challenges/confirm-provider-event {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location ~ ^/api/v1/workflow-approval-notifications/deliveries/[^/]+/(ack|fail)$ {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/workflow-auth/refresh {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
          proxy_set_header x-service-token $http_x_service_token;
        }

        # Runtime token recovery, not provisioner issuance.
        location = /api/v1/workflow-auth/reissue {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
          proxy_set_header x-service-token $http_x_service_token;
        }

        # OAuth mcp-server broker (mcp-host → control-api), spec 06 §5.1/§10.6
        # decision B: reach the broker by reusing THIS gateway instead of opening
        # a direct mcp-host → control-api:8090 egress. L7-scoped to POST-only on
        # this single path — the DENY-by-omission of every other control-api path
        # (incl. direct :8090) is preserved. mcp-host forwards its control JWT
        # (typ:service, scope oauth:user-token) in Authorization; no x-service-token.
        location = /api/v1/mcp-oauth/user-token {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # OAuth grant-existence sweep (mcp-host → control-api), spec 06 mini-spec 13.
        # mcp-host polls whether its live per-user OAuth partitions still have a
        # grant and evicts the revoked ones. Mirrors the user-token block: same
        # gateway, POST-only, L7-scoped to this single path (DENY-by-omission of
        # every other control-api path preserved). Same control JWT
        # (typ:service, scope oauth:user-token) in Authorization; no x-service-token.
        # Read-only: control-api answers booleans only, never a token.
        location = /api/v1/mcp-oauth/grants/exists {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/workflow-approvals/request {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
          proxy_set_header x-service-token $http_x_service_token;
        }

        location ~ ^/api/v1/workflow-approvals/[^/]+/status$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
          proxy_set_header x-service-token $http_x_service_token;
        }

        location ~ ^/api/v1/workflow-approvals/[^/]+/cancel$ {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
          proxy_set_header x-service-token $http_x_service_token;
        }

        location ~ ^/api/v1/workflow-approvals/[^/]+/provider-decision$ {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # ── LLM usage events ingest ──
        # mcp-host pods POST batched LLM usage events here. Same RS256
        # access JWT that the workflow-approvals endpoints accept.
        location = /api/v1/internal/usage/llm/events {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # ── Governed agent-run tracing ingest ──
        # Shared and workflow mcp-host pods POST bounded event batches here
        # using the same RS256 runtime access JWT as usage and approvals.
        location = /api/v1/internal/tracing/agent-run-events {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # ── Protected approval prompt-history capture ──
        # mcp-host pods POST one bounded prompt capture for an existing
        # approval using the same RS256 runtime access JWT as tracing ingest.
        location = /api/v1/internal/tracing/approval-prompt-history {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # ── Token budget check + reservation release ──
        # mcp-host pods POST here once per task (pre-task budget enforcement)
        # and to release danger-zone reservations on task terminal. Same RS256
        # runtime access JWT that the workflow-approvals + usage endpoints accept.
        location = /api/v1/internal/budgets/check {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/internal/budgets/release {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # ── Plugin Workload SDK runtime endpoints ──
        # Recipe mcp-host pods proxy plugin-workload SDK calls (promptBridge +
        # clientNotifications) to control-api through this gateway. Same RS256
        # runtime access JWT that the workflow-approvals endpoints accept;
        # control-api authorizes each call against the recipe grant.
        location = /api/v1/mcp-host/plugin-workload-sdk/capabilities {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/mcp-host/plugin-workload-sdk/prompt-bridge/v2 {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/mcp-host/plugin-workload-sdk/prompt-bridge {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # JIT credential tickets are issued immediately before each
        # provider attempt (including an ordered fallback target). Keep this
        # route on the same mcp-host JWT gateway as the initial authorization;
        # otherwise promptBridge authorizes successfully and then fails at
        # the gateway before the provider or credential broker is reached.
        location = /api/v1/mcp-host/plugin-workload-sdk/prompt-bridge/credential-ticket {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/mcp-host/plugin-workload-sdk/client-notification {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # Read-only: list the clientNotifications grant's allowed recipients so a
        # recipe sandbox UI can populate its notify dropdown. POST carries the
        # recipe binding in the body (same contract as the send path above).
        location = /api/v1/mcp-host/plugin-workload-sdk/client-notification/recipients {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location ~ ^/api/v1/mcp-host/plugin-workload-sdk/invocations/[^/]+/status$ {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # SDK-only promptBridge finalization is the atomic accounting boundary:
        # it closes the physical provider attempt, logical invocation, and
        # exact/unknown spend outcome in one control-api transaction. Keep it
        # behind the same mcp-host JWT gateway as invocation status; omitting
        # this route lets the provider execute while the runtime can only
        # surface provider_unavailable after the result is already billable.
        location ~ ^/api/v1/mcp-host/plugin-workload-sdk/invocations/[^/]+/finalize$ {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # Provider-attempt status is part of the promptBridge audit contract.
        # It must remain behind the same mcp-host JWT gateway as invocation
        # status; otherwise the provider call can be authorized and issued a
        # JIT ticket, but the runtime cannot close the attempt lease.
        location ~ ^/api/v1/mcp-host/plugin-workload-sdk/provider-attempts/[^/]+/status$ {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # ── Stateless lifecycle heartbeat ──
        # mcp-host pods POST D8 activity snapshots here. Same RS256 runtime
        # access JWT that the workflow-approvals endpoints accept; control-api
        # binds identity to the token's hostRefs[0] claim (never the path) and
        # answers {drain} from Host.status.lifecycle.
        location = /api/v1/mcp-host/hosts/heartbeat {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/mcp-host/llm/provider-attempts/authorize {
          # V2 carries bounded inline images; keep the larger body allowance
          # on this authenticated authorization route, not the whole gateway.
          # The route is shared by both providers, so the value is the larger
          # visual envelope: Grok 36700160 (#784) over Codex 25165824 (#660).
          # It also covers the #731 non-image request cap (8 MiB) plus
          # control-api's 16 KiB authorize envelope allowance, which nginx's
          # 1m default would refuse before control-api sees it. nginx refuses
          # to start when a location repeats this directive.
          client_max_body_size 36700160;
          limit_except POST {
            deny all;
          }
          error_page 502 = @control_plane_unavailable;
          error_page 504 = @control_plane_connect_timeout;
          # control-api answers queue_wait or authorize_timeout itself; the
          # server's 30 s would turn those answers into nginx's own 504. Each
          # timer bounds the gap between two writes or reads, not the whole
          # request: control-api pauses a queued body, so the send timer covers
          # the queue wait (40 s), and the read timer covers the work deadline
          # (30 s) once the body is sent.
          proxy_read_timeout 90s;
          proxy_send_timeout 90s;
          # This exact location matches the normalized URI, but a proxy_pass
          # without a URI part forwards the raw one. Aliases such as
          # %61uthorize or ./authorize would then reach control-api with the
          # 35 MiB allowance on a path its parser exemption does not know.
          # The URI part makes nginx send the canonical path (query kept).
          proxy_pass http://control_api_upstream/api/v1/mcp-host/llm/provider-attempts/authorize;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        # ── Workflow broker runtime endpoints ──

        location = /api/v1/workflows {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location = /api/v1/workflows/effective-targets/resolve {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location ~ ^/api/v1/workflows/[^/]+/[^/]+$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location ~ ^/api/v1/workflows/[^/]+/[^/]+/health$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location ~ ^/api/v1/workflows/runs/[^/]+/artifacts$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location ~ ^/api/v1/workflows/runs/[^/]+/artifacts/[^/]+/download$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location ~ ^/api/v1/workflows/[^/]+/[^/]+/runs/latest/artifacts$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location ~ ^/api/v1/workflows/[^/]+/[^/]+/runs/latest/artifacts/[^/]+/content$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location ~ ^/api/v1/workflows/[^/]+/[^/]+/runs/latest/artifacts/[^/]+/download$ {
          limit_except GET {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
        }

        location ~ ^/api/v1/workflows/[^/]+/[^/]+/trigger$ {
          limit_except POST {
            deny all;
          }
          proxy_pass http://control_api_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Authorization $http_authorization;
          proxy_set_header Idempotency-Key $http_idempotency_key;
        }

        location / {
          return 403;
        }
      }
    }
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: host-context-controller-api-gateway
  namespace: control-plane
  labels:
    app: host-context-controller-api-gateway
data:
  nginx.conf: |
    pid /tmp/nginx.pid;
    worker_processes auto;
    events {
      worker_connections 1024;
    }
    http {
      client_body_temp_path /tmp/client_temp;
      proxy_temp_path /tmp/proxy_temp;
      fastcgi_temp_path /tmp/fastcgi_temp;
      uwsgi_temp_path /tmp/uwsgi_temp;
      scgi_temp_path /tmp/scgi_temp;

      map $uri $hcc_route_class {
        default denied;
        ~^/health$ health;
        ~^/ready$ ready;
        ~^/api/v2/hosts/self/mcpservers$ host_inventory;
        ~^/api/v2/hosts/self/mcpservers/credential$ host_credential;
        ~^/api/v1/mcpservers$ legacy_system_inventory;
        ~^/api/v1/mcpservers/context/ legacy_host_tombstone;
        ~^/api/v1/mcpservers/[^/]+/auth$ legacy_host_tombstone;
        ~^/api/v1/desktop/ desktop;
      }
      log_format hcc_gateway_json escape=json
        '{"gateway":"hcc","request_id":"$request_id","route_class":"$hcc_route_class","method":"$request_method","status":$status,"upstream_status":"$upstream_status","request_time":$request_time,"upstream_response_time":"$upstream_response_time"}';
      access_log /dev/stdout hcc_gateway_json;
      error_log /dev/stderr warn;

      upstream host_context_controller_upstream {
        server host-context-controller.control-plane.svc.cluster.local:8081;
      }

      server {
        listen 8081;
        server_name _;
        default_type application/json;

        # Normalize errors generated by nginx itself. Upstream errors remain
        # HCC-owned (`proxy_intercept_errors` is off), preserving HCC's generic
        # WWW-Authenticate and authorization-unavailable semantics.
        error_page 400 = @hcc_bad_request;
        error_page 405 = @hcc_method_not_allowed;
        error_page 413 = @hcc_payload_too_large;

        location @hcc_bad_request {
          add_header Cache-Control "no-store, private" always;
          add_header Pragma "no-cache" always;
          add_header X-Content-Type-Options "nosniff" always;
          return 400 '{"error":"bad_request"}';
        }
        location @hcc_method_not_allowed {
          add_header Cache-Control "no-store, private" always;
          add_header Pragma "no-cache" always;
          add_header X-Content-Type-Options "nosniff" always;
          return 405 '{"error":"method_not_allowed"}';
        }
        location @hcc_payload_too_large {
          add_header Cache-Control "no-store, private" always;
          add_header Pragma "no-cache" always;
          add_header X-Content-Type-Options "nosniff" always;
          return 413 '{"error":"payload_too_large"}';
        }

        location = /health {
          add_header Content-Type application/json;
          return 200 '{"status":"ok"}';
        }

        location = /ready {
          proxy_pass http://host_context_controller_upstream;
          proxy_pass_request_headers off;
          proxy_set_header Host $host;
          proxy_set_header X-Request-ID $request_id;
        }

        location = /api/v1/mcpservers {
          proxy_pass http://host_context_controller_upstream;
          proxy_pass_request_headers off;
          proxy_set_header Host $host;
          proxy_set_header X-Request-ID $request_id;
        }

        # The retained proxy poller is the only PR 1 compatibility exception
        # above. Caller-selected legacy Context and credential routes are
        # closed locally so a stale mcp-host cannot bypass the v2 Host binding.
        location ~ ^/api/v1/mcpservers/context/[^/]+$ {
          add_header Cache-Control "no-store, private" always;
          add_header Pragma "no-cache" always;
          add_header X-Content-Type-Options "nosniff" always;
          return 410 '{"error":"gone"}';
        }

        location ~ ^/api/v1/mcpservers/[^/]+/auth$ {
          add_header Cache-Control "no-store, private" always;
          add_header Pragma "no-cache" always;
          add_header X-Content-Type-Options "nosniff" always;
          return 410 '{"error":"gone"}';
        }

        location = /api/v2/hosts/self/mcpservers {
          if ($request_method != GET) { return 405; }
          proxy_pass http://host_context_controller_upstream;
          proxy_pass_request_headers off;
          proxy_http_version 1.1;
          proxy_set_header Host $host;
          proxy_set_header Authorization $http_authorization;
          proxy_set_header X-Request-ID $request_id;
          proxy_set_header Connection "";
          add_header Cache-Control "no-store, private" always;
          add_header Pragma "no-cache" always;
          add_header X-Content-Type-Options "nosniff" always;
        }

        location = /api/v2/hosts/self/mcpservers/credential {
          if ($request_method != POST) { return 405; }
          client_max_body_size 1k;
          proxy_pass http://host_context_controller_upstream;
          proxy_pass_request_headers off;
          proxy_http_version 1.1;
          proxy_set_header Host $host;
          proxy_set_header Authorization $http_authorization;
          proxy_set_header Content-Type $http_content_type;
          proxy_set_header Content-Length $content_length;
          proxy_set_header X-Request-ID $request_id;
          proxy_set_header Connection "";
          add_header Cache-Control "no-store, private" always;
          add_header Pragma "no-cache" always;
          add_header X-Content-Type-Options "nosniff" always;
        }

        location ~ ^/api/v1/desktop/[^/]+$ {
          proxy_pass http://host_context_controller_upstream;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        }

        location / {
          return 403;
        }
      }
    }