Repository navigation
fix(serve-api): --net-allow-domains and --net-timeout, shared with run - #2625
Merged
Merged
Conversation
serve-api gains --net-allow-domains / --net-timeout (and --stream-allow-domains), matching run. Before, serve-api --caps Net had neither: --net-allow-domains exited "flag provided but not defined" and every request ran under the fixed 30s timeout (Daneel, 2026-10-26). One path, not a copy: - registerNetDestFlags (cmd/ailang/net_flags.go) registers --net-allow-domains, --net-timeout, --net-max-bytes and --stream-allow-domains for both run and serve-api. - runner.SetupNet (SetupNetHandler + SetupNetLimit) is the one place the --net-* options reach the Net effect, for run, run --batch and serve-api. serve-api no longer sets Net/Stream fields by hand; its http/localhost/metadata defaults stay on, and an allowlist governs those destinations too. Tests: flag parsing, serve-api config, and end-to-end serve-api routes through a loopback forward proxy (no real network): with --net-allow-domains a.example, a.example is fetched and b.example is refused before any request; --net-timeout 200ms fails a 1s upstream that the default timeout serves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
ailang serve-apigains--net-allow-domains,--net-timeoutand--stream-allow-domains, matchingailang run. Before,serve-api --caps Net --net-allow-domains www.linkedin.com x.ailexited with "flag provided but not defined": a Net-granted route had no host allowlist and every request ran under the fixed 30s timeout (reported by Daneel, 2026-10-26).One path, not a copy
registerNetDestFlags(cmd/ailang/net_flags.go) registers--net-allow-domains,--net-timeout,--net-max-bytesand--stream-allow-domainsfor bothrunandserve-api. Names, help text and meaning can no longer drift.runner.SetupNet(SetupNetHandler+SetupNetLimit) is the one place the--net-*options reach the Net effect, forrun,run --batchandserve-api. serve-api used to setNet.AllowHTTP/AllowLocalhost/AllowMetadata(and the Stream equivalents) by hand. It now callsrunner.SetupNet/runner.SetupStreamHandlerand differs only in its defaults: http://, localhost and the metadata server stay on, so existing deployments don't change. With an allowlist set, those destinations are reachable only when they are listed too (the destination authorizer applies the allowlist before the loopback and metadata rules). Example:metadata.google.internalon Cloud Run.run, the allowlist and timeout are inert without--caps Net.--net-max-bytesis still refused without it.Commands that grant Net: audit
run(incl.--batch)--capsserve-api(HTTP,--mcp,--mcp-http,--a2a)--capsreplay--caps(re-execsailang run)select-best--caps(re-execsailang runvia bestof)[bin]shimscaps→ailang runrun_flags(only caps/entry/package-dir/quiet are reserved)test,check,ai-checkreplGrantCapability)replayandselect-bestare left as they are in this PR.Policy-file interplay
serve-api has no
--policy. Withrun --policy, the policy'snet_allowis the only authority:--net-allow-domainsand--stream-allow-domainsare refused by name. The result is neither an intersection nor precedence (refusedWithPolicyincmd/ailang/run_policy.go). The shared helper doesn't change this, because the refusal list matches flag names.Tests
TestNetDestFlags_Parse: the shared helper parses every flag intorunner.NetOptions.TestServeAPINetDestFlags_Defined: serve-api defines the flags, and a bad--net-timeoutis refused before the server listens.TestSetupServeAPINetStream_Config: Net allowlist and timeout plus the Stream allowlist land on the effect context, and serve-api's defaults are kept.TestServeAPINetAllowDomains_EndToEnd: the checkout binary's serve-api route goes through a loopback forward proxy (HTTP_PROXY), so no real network is used. With--net-allow-domains a.example, a.example is fetched and b.example getsDisallowedHostand never reaches the proxy. A control run without the allowlist shows b.example is reachable.TestServeAPINetTimeout_EndToEnd:--net-timeout 200msfails a 1s upstream, and the default timeout serves it.Mutation check: with serve-api reverted to the old Net setup (no allowlist, no timeout), all four serve-api tests fail.
Gates:
make test-changed,make lint,make check-file-sizes,make check-cli-docs,make check-changelog,make check-doc-samples.🤖 Generated with Claude Code