Repository navigation
fix(controller): derive the model-gateway endpoint from config, drop the aperture default - #276
Merged
Merged
Conversation
…the aperture default The model-gateway URL was configurable in the models.json patch path but compiled into two other consumers, so a deployment that pointed KAPE_MODEL_GATEWAY_URL somewhere else patched one endpoint while the OPA policy allowed another (fail-closed: sandboxes lost model traffic) and the startup probe reported on a host the sandbox was never configured to reach. Consumers now share one value: - policy.go: modelGatewayRule(endpoint) derives host/port via endpointHostPort (explicit port > https 443 > http 80), rejects empty / no-host / non-http / out-of-range-port with an error instead of a silent fallback, and ApplyModelGatewayPolicy fails closed before any UpdateConfig call. - gateway.go: ProbeModelGateway GETs <configured-url>/models instead of a literal host. - config.go: DefaultConfig no longer carries a gateway default; Validate names the missing variable. The KapeAgentServer CR already owns the value and the operator already renders it as contract env. Remove the deployment-specific host from every other carrier too: the chart value becomes required (no system-specific default), the published pi-openshell sandbox policy stops pinning one namespace's gateway, and the controller README documents "required" instead of a compiled default. Test fixtures use neutral hosts. Tests: controller (go vet + go test) and operator unit tests pass; the chart render test supplies the URL and asserts that omitting it fails. New: policy_test.go pins endpoint derivation + rejection + fail-closed, and TestProbeModelGateway_UsesConfiguredEndpoint pins the probe target. BREAKING CHANGE: kape-controller now refuses to start without KAPE_MODEL_GATEWAY_URL, and `helm template/install` fails when agentServer.modelGateway.url is empty. Both are supplied by the existing KapeAgentServer CR (spec.modelGateway.url is required in the CRD), so an operator-managed install is unaffected; standalone controller runs and default chart renders must pass the value.
Owner
Author
|
CI note: the single failing check (
Both reproduce on every recent branch run (e.g. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
KAPE_MODEL_GATEWAY_URLwas consumed five ways but honoured by one. Themodels.json patch used the configured URL; the sandbox egress rule
(
policy.go) and the startup probe (gateway.go) used a compiled-inmodel-gateway-http.aperture.svc.cluster.local, andDefaultConfig()shippedthat host as the default.
Consequence: point the controller at any other gateway and it patches
models.jsonat the new endpoint while the OPA proxy still denies egress toit — fail-closed, so sandboxes silently lose model traffic — and the probe
reports on a host the sandbox was never configured to reach.
How the gateway is consumed (after)
Changes
controller/policy.go—modelGatewayRule(endpoint)+endpointHostPort():host and port derive from the configured URL (explicit port > https 443 >
http 80); empty / no-host / non-http / out-of-range port returns an error
instead of a silent fallback;
ApplyModelGatewayPolicyfails closed beforeany
UpdateConfig.controller/gateway.go—ProbeModelGatewaytargets<configured-url>/models.controller/config.go— no gateway default inDefaultConfig();Validate()reports the missing variable by name.
charts/kape—agentServer.modelGateway.urlbecomesrequiredwith nodefault; render test supplies it and asserts that omitting it fails.
openshell/agents/sandbox-policy.yaml— the published image policy no longerpins one namespace's gateway (controller sandboxes get the rule at runtime).
controller/README.mddocuments "required"; operator testfixtures and goldens use neutral hosts.
Verification
controller:go vet ./...,go test ./...→ ok (54s)operator:go vet ./...,go test ./domain/... ./infra/{k8s,openshell,toml}/... ./controller/→ okcharts/kape/tests/render-test.sh→ all assertions pass (incl. new case 0:render fails without the URL)
controller/policy_test.go(derivation matrix, rejection cases,fail-closed unusable URL) and
TestProbeModelGateway_UsesConfiguredEndpointPre-existing failures in
operator/infra/qdrantandoperator/controller/reconcilereproduce onmain(sandbox-blocked127.0.0.1dials) and are unrelated.Breaking change
kape-controllerrefuses to start withoutKAPE_MODEL_GATEWAY_URL.helm template/installfails whenagentServer.modelGateway.urlis empty.Both values come from the
KapeAgentServerCR (spec.modelGateway.urlisalready required in the CRD), so an operator-managed install is unaffected.
Standalone controller runs and default chart renders must pass the value.
Not in scope (follow-ups)
PI_PROVIDER=openrouterandproviders.openrouterin the models.json patch(
gateway.go:365,390) ignore the configurableDefaultProvider; fixing needsa provider-key contract, not a string swap.
kape-controller.openshell.svc.cluster.local:8081/SandboxNamespace: "openshell"(config.go:266).baseUrl: https://openrouter.ai/api/v1(vendor default, env-overridable).