Skip to content

Network git of the code index can go through an operator's forward proxy, with an identity per repository - #933

Merged
zlareb1 merged 13 commits into
mainfrom
pufit/code-git-proxy
Nov 19, 2026
Merged

zlareb1 merged 13 commits into
mainfrom
pufit/code-git-proxy

Conversation

@pufit

@pufit pufit commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • New Feature

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The code index's network git (clone, fetch, ls-remote, submodule update) can go through an operator's forward proxy: LOOM_CODE_GIT_PROXY_URL, with LOOM_CODE_GIT_PROXY_TOKEN_FILE, LOOM_CODE_GIT_PROXY_CA_FILE and LOOM_CODE_GIT_PROXY_IDENTITY. A repository entry can present its own git_proxy_identity to the proxy; code.repo.add and code.repo.remote_branches take the field from a platform admin only.

Why

A deployment whose pods reach git hosts only through a forward proxy cannot run the code index today. Every repository job builds git's environment from scratch (auth_env) and reads no system or global git config, so no proxy variable and no http.proxy reaches git, and nothing in Loom sets one.

Such a proxy usually decides per caller what a request may reach and which credential it gets. One identity for the whole deployment is not enough for that, so an entry can name its own.

Design, with the alternatives and what each costs:

  • Where the proxy is added. In the plain-process branch of sandbox.run_job, for jobs the git helpers mark as git talking to a network remote (remote_access, compiler_tier.git(network=True)). The password is read from its file there, for that one job, into a copy of the environment. auth_env was the other candidate: build harnesses copy its git settings (git_config_env), so repository build code would get the password. The caller's env was the third: it is handed to the sandbox as it is, where repository code runs.
  • How git authenticates. http.proxy carries the user and password, each percent-encoded whole, and http.proxyAuthMethod=basic makes git send them on its first CONNECT. Without the second setting git's HTTP library sends a bare CONNECT first and waits for a 407, so every job would start with a request the proxy refuses. The cost is that only Basic is offered; git has no way to send another proxy header.
  • Fail closed. While the setting is set, a job that cannot go through the proxy is refused with a fixed reason, before any process starts: the password file gives no token, no identity is named, or the remote is not https://. Git's proxy setting carries no ssh, so the job also gets protocol.ssh.allow=never, and an ssh submodule fails as a refused transport instead of connecting directly. A deployment that set a proxy to control egress must not find Loom going around it.
  • Not with the sandbox. The sandbox's own egress proxy connects to the remote itself. Chaining it through the operator's proxy changes its guarantee (it connects to the address it vetted) and needs the CA bundle mounted into the sandbox; that is left to a later change. Until then a host that runs the sandbox refuses network git while the setting is set, and /v1/health and loom doctor report repo_git_proxy_sandboxed. The cost: a host uses the proxy or the sandbox, not both.
  • Who names an identity. The identity decides whose credential the proxy fetches with, and code.repo.add is open to every member of an org unless LOOM_CODE_SELF_SERVICE_PLATFORM_ADMIN_ONLY is set. So only a platform admin may name one in code.repo.add or code.repo.remote_branches, or add a branch of an index that carries one, which inherits it, whatever that setting says. The rule is the one that setting applies: a flat platform-admin token used by its own subject, and a call without a principal only where auth is off. Both gates ask one function, _is_platform_admin, and each keeps its own refusal sentence. Any other caller gets AUTH_INSUFFICIENT.
  • What a refusal by the proxy reads as. A fetch and a submodule update record git's own words, which the fetch tier reads as kind egress with a fix that names the proxy and says what a 407 means. A clone and the ls-remote before an add show a fixed reason in place of git's words (those can name host paths and the remote), so they name the proxy themselves: the operator's git proxy (LOOM_CODE_GIT_PROXY_URL) refused the connection (407), with the status the proxy answered. The fetch tier reads that sentence as the same kind with the same fix. Without it, an entry's first contact, where a wrong token or an unknown identity shows first, would read git clone failed (exit 128).
  • Masking. run_job masks the password in what git says (stderr, and stdout unless the caller parses it) as the file holds it, percent-encoded and in the Proxy-Authorization header's base64 form, so the three callers that surface git output (GitError, the clone's log line, a compiler tier's error) need no change. Stdout that a caller parses (ls-remote) is the remote's refs and is left as it is: git writes none of its own words there, and masking a ref that happens to spell a weak password would corrupt the listing.
  • Dependency downloads are not proxied. The TypeScript package install and the Go tier's go mod download run repository code, so they get neither the proxy nor its password. Loom's HTTP clients do not read these settings either.

Scope and risk

Touches the code index only: server/code/app/index/ (the new git_proxy.py, sandbox.py, gitrepo.py, bootstrap.py, pass_fetch.py, mirrors.py, repo_registry.py, compiler_tier.py), the repository handlers and wire models, the entry configuration, tier health, one health problem, four settings and one registry column. 52 files, +2154 −113: about 630 lines of server code (a third of it the identity threaded through some 20 call sites), 1,270 of tests, 175 of hand-written documentation, the rest generated.

_require_platform_admin, the gate of LOOM_CODE_SELF_SERVICE_PLATFORM_ADMIN_ONLY, now reads the predicate the identity gate reads. What it admits, what it refuses and its message are unchanged, and its tests pass as they were.

With LOOM_CODE_GIT_PROXY_URL unset nothing changes: no job gets a new setting in its environment, and the new network_git job option is ignored.

What could break:

  • Auth. The new field is refused for everyone but a platform admin; a caller that never names it is unaffected. code.repo.add_branch now refuses a maintainer who is not a platform admin when the source index carries an identity.
  • Stored data. One additive column on loom.code_repos. An access change and a removal copy the row whole, so they keep the value; a removed row reads it empty, like the token.
  • Shared mirrors. Branches of one repository share a mirror. The ingest pass batches their fetch only where remote, token and identity are the same; a host's own fetch round fetches the whole mirror as its first entry, as it already does with the token. With different identities on one mirror, that round goes out under the first entry's.
  • A job in flight keeps the token it read when it started. The proxy has to accept a token for as long as a git job may run after reading it (LOOM_CODE_GIT_FETCH_TIMEOUT_S, an hour by default).
  • The token file is within reach of build code where the proxy is used. The proxy works only where repository jobs run as plain processes. There a compiler tier's build runs as Loom's user: the password is not in its environment, but it can read the file. The guide says to run compiler tiers on such a host only for repositories you trust.
  • An http:// proxy URL carries the identity and the token in clear on every job. The guide says so and asks for a trusted path or an https:// URL.

Left alone: Loom's HTTP clients (the GitHub API, issuer keys, document sources), the sandbox's egress proxy, and the Helm chart, which takes the settings through env and the mounts through extraVolumes.

Compatibility, rollout and rollback

  • Wire: code.repo.add and code.repo.remote_branches gain the optional field git_proxy_identity (letters, digits and . _ ~ @ -, at most 128; default ''), refused with AUTH_INSUFFICIENT unless the caller is a platform admin. code.repo.add_branch refuses with AUTH_INSUFFICIENT for a caller who is not a platform admin when the source index carries an identity. A build before this one ignores the field and names it in ignored_args, so a client sends it only once every pod runs this build. No default changes.
  • Operator steps: none unless the proxy is wanted. To use it, roll this build to every pod first (a pod of the previous build ignores the settings, names them in one boot warning, and connects directly), then set LOOM_CODE_GIT_PROXY_URL and, as needed, the token file, the CA bundle and the default identity on every pod, web pods included, since each keeps its own mirrors. Keep the repository-job sandbox off on those pods. There code.repo.add works only with LOOM_CODE_SELF_SERVICE_GIT_UNSANDBOXED and the platform-admin rule it needs; an entry in LOOM_CODE_REPOS_JSON needs neither. Migration 112_code_repo_git_proxy_identity.sql is additive; a pod of the previous build reads the table by column name and copies a row whole, so it keeps working during the roll.
  • Rollback: reverting leaves the column and the values written to it; the previous build ignores both. With the settings still in the environment, the previous build warns once at boot and connects directly.

Tests

New unit tests (tests/unit/test_code_git_proxy.py, test_code_git_proxy_wire.py, test_code_git_proxy_settings.py; 39, 9 and 21 cases) and additions to the existing files for the handlers, the configured entries, tier health and the sandbox:

  • The child of a network git job gets http.proxy with the identity and the encoded password, http.proxyAuthMethod=basic, http.sslCAInfo and protocol.ssh.allow=never; its argv and the caller's mapping are unchanged. The entry's identity wins over the default. The file is read again for the next job. Git on a local mirror, a harness with network access and a local command get nothing.
  • Each refusal (no file, an empty file, no identity, an scp-style and an ssh:// remote, a host with the sandbox) raises before any process starts, and each caller reports it in its own shape: GitError, the clone's reason, the add's REMOTE_REFUSED, a tier's ToolOutputError.
  • A clone and the add's ls-remote that the proxy refused name the proxy and its status, for both phrasings git's HTTP library has for a refused CONNECT, with 403 and with 407; the fetch tier gives the clone the kind and the fix it gives a refused fetch.
  • With the real git binary against a forward proxy the test starts on a loopback port:
    • the first request is CONNECT <host>:443 with Proxy-Authorization: Basic that decodes to identity:password, the repository's own token is not in it, no argument of the git process holds the password, the error text does not either, and the mirror's stored config names no proxy (for a 403 and a 407 answer);
    • a real clone and a real ls-remote that the proxy refuses come back with the named reason and the status;
    • a proxy that terminates TLS with a certificate under an authority made in the test: git sends its request, with the repository's token and without the proxy's credentials, when the CA bundle holds that authority, and ends the handshake when it holds another;
    • git submodule update on a checkout whose .gitmodules names another host: the clone git starts goes to the proxy with the credentials, and an ssh submodule makes no request and fails as a refused transport;
    • a clone made with the proxy settings in the environment stores none of them.
  • A real child that prints the password in its three spellings comes back masked; a ref that spells a weak password in parsed ls-remote output is left alone.
  • Every call site of a network git helper under server/ passes the entry's identity (an AST scan), each helper hands it to run_job, branches of one mirror share a fetch only under one identity, and a host round fetches as its first entry.
  • code.repo.add, code.repo.remote_branches and code.repo.add_branch: a platform admin's identity is stored and every remote read is made under it; a member, an org admin, a scoped token and an admin acting for someone else are refused before any remote job or write.
  • The settings: a URL with credentials, a path, a query, another scheme or no port is refused at load, as is each of the other three without the URL.
  • tests/integration/test_code_repo_row_kind.py gains a test that writes a row with the identity, reads it back through the registry, changes its access and removes it.

What I ran locally (macOS, Python 3.12), on the branch merged with main:

  • make lint and make typecheck: pass. ruff format --check ., prettier --check "**/*.{md,yml,yaml}" and biome format .: clean.
  • Every generator's --check (sdk_py_gen, sdk_py_client_gen, sdk_py_admin_gen, sdk_ts_gen, agent_plugin_sync, settings_reference, settings_schema, settings_example, docs_reference, op_reach_census): current. Each generator and the settings-defaults snapshot update, run again after the last merge of main, change nothing.
  • The three new test files and 37 unit test files that name a changed helper or guard the tree: 1333 passed, 1 skipped (Linux-only), under three random seeds.
  • pytest tests/unit -n 8 -p randomly and pytest bench: the unit run fails on this machine only in tests that need Linux resource limits or a newer clickhouse binary than it has (1235 test ids in 132 files), and exactly those ids fail on main there; bench passes (251). The last commit adds one paragraph to a guide: after it the 188 unit test files that read docs/ were run again, with no other failure.
  • tests/integration/test_code_repo_row_kind.py against a private ClickHouse migrated from empty through migration 112: 5 passed.
  • pytest tests/analyzer -q (the statement corpus) against a private ClickHouse migrated the same way: 12 passed, none skipped. tests/analyzer/shapes.txt is regenerated with python -m tests.analyzer.corpus --write; its diff is the one entry of the schema dump, whose shape changes with the new column.
  • loom code init for an operator entry with the proxy set, in its own process, against a forward proxy on a loopback port: the proxy received CONNECT <host>:443 with the entry's identity and the token, the clone was refused, and the command's output did not hold the token.

Not run locally, CI runs them:

  • The hostile sandbox suite (tests/unit/test_repo_job_sandbox_hostile.py, real bubblewrap): needs Linux.
  • make test-mixed-version: needs Docker.
  • make schema-check on the release CI pins. schemas/schema.sql was not made by make schema-dump: no ClickHouse of that release was at hand, so the one-line change to loom.code_repos is the block a dump of an older release printed after every migration ran from empty. That dump differs from the committed file elsewhere only in what the older release prints differently, and none of that is in this change. CI's schema-check decides: if it is red, the diff it prints is applied as it stands.
  • make format-check as a whole (no shfmt here; no shell or TOML file changed), make test-unit-cov and the rest of the integration suite.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked by running, not by reading alone: with the real git binary against a forward proxy on a loopback port, that the first CONNECT carries the identity and the password, that the repository token stays inside the tunnel, that the remote is trusted by the CA bundle and by no other, that a submodule's clone goes through the proxy while an ssh submodule is refused, and that no git argument, error text, log line or stored config holds the password; every migration from empty through 112 on a ClickHouse server, and the registry statements against it; the unit suite's failures on the build machine against the same run on main. A second agent reviewed the diff, then the fixes its review asked for and the merges of main, and repeated the experiments with a proxy of its own on the merged tree.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

pufit added 13 commits November 18, 2026 13:54
A deployment that lets its pods reach git remotes only through a forward
proxy had no way to tell Loom: every repository job builds its environment
from scratch, so no proxy variable or git config reaches git.

LOOM_CODE_GIT_PROXY_URL names the proxy, LOOM_CODE_GIT_PROXY_TOKEN_FILE a
file with its password, LOOM_CODE_GIT_PROXY_CA_FILE the bundle git verifies
TLS with through it, and LOOM_CODE_GIT_PROXY_IDENTITY the user of an entry
that names none. An entry can present its own identity, so the proxy can
decide per repository: git_proxy_identity is a field of an operator entry,
a column of loom.code_repos (migration 111), and a field of code.repo.add
and code.repo.remote_branches that only a platform admin may set.
code.repo.add_branch inherits it under the same rule.

The proxy and its credentials are added in the plain-process branch of
run_job, for jobs the git helpers mark as git talking to a network remote:
a mirror's clone, fetch and ls-remote, the add's ls-remote and a checkout's
submodule update. The password is read from its file for each job and lives
in that child's environment only, so no argv, stored git config, build
harness or sandboxed job sees it, and run_job masks it in what git says.
http.proxyAuthMethod=basic makes git send the credentials on its first
CONNECT.

While the proxy is set git never connects directly. A job is refused with a
fixed reason when the password file gives no token, no identity is named,
the remote is not https, or the host runs the sandbox, whose egress proxy
is not chained through this one; /v1/health reports the last case as
repo_git_proxy_sandboxed. Tier health reads a 403 or 407 from the proxy,
and Loom's own refusal, as kind egress with a fix that names the proxy.

Signed-off-by: pufit <[email protected]>
…ntact

A clone and the ls-remote before an add show a fixed reason in place of
git's words, so a proxy that refused them read "git clone failed (exit
128)" and "git ls-remote failed": kind unknown on the fetch tier, with the
proxy's answer in the log only. That is where a wrong token audience or an
identity the proxy does not know shows first. Both now say "the operator's
git proxy (LOOM_CODE_GIT_PROXY_URL) refused the connection" with the status
the proxy answered, which the fetch tier reads as kind egress with the fix
a refused fetch gets.

The guide says three things it left out: where the proxy is used repository
jobs are plain processes, so a compiler tier's build can read the token
file; sandbox.required: false alone does not keep the sandbox off; and an
http:// proxy URL carries the identity and the token in clear.

Two tests with the real git cover what the suite asserted only as a config
key: git trusts the remote through the proxy by the CA bundle and by no
other, and the clone a submodule update starts goes through the proxy, an
ssh submodule being a refused transport. The test of a sandboxed harness
proved nothing and is gone.

Removed as not needed: the once-only log of a token-file failure, the size
bound on the token file, the emptied NO_PROXY variables (auth_env copies
none) and the test of the add's audit row.

Signed-off-by: pufit <[email protected]>
main added 111_connected_accounts.sql while this branch was open, so two files held
number 111. The file that adds loom.code_repos.git_proxy_identity moves to the next
free number; its content is unchanged.

Signed-off-by: pufit <[email protected]>
…rule

main gained LOOM_CODE_SELF_SERVICE_PLATFORM_ADMIN_ONLY while this branch was
open, with the rule this branch wrote for git_proxy_identity: the role counts
on a flat token used by its own subject, and a call without a principal passes
only where auth is off. Both gates now ask one function, _is_platform_admin.
Each keeps its own refusal sentence, and the identity gate applies whether or
not the setting is on.

A test double main added takes the proxy_identity keyword the remote reads now
pass, and the tests of the identity gate use the platform-admin principal the
module already builds: the merge left two helpers of one name, the later of
which replaced the earlier for every test.

The guides say how the two changes meet. The proxy is used where repository
jobs are plain processes, and there code.repo.add needs
LOOM_CODE_SELF_SERVICE_GIT_UNSANDBOXED; its git then goes through the proxy
under the entry's identity.

Signed-off-by: pufit <[email protected]>
The section on self-registered repositories without the sandbox says that
nothing vets where their git jobs connect. With LOOM_CODE_GIT_PROXY_URL those
jobs connect to the operator's proxy alone, and an ssh remote is refused. The
section now says so and points at the proxy's own section; the rules for
loading LOOM_CODE_SELF_SERVICE_GIT_UNSANDBOXED are as they were.

Signed-off-by: pufit <[email protected]>
The analyzer corpus issues schemas/schema.sql as one statement, so the shape
it lists for the dump changes whenever the dump does. Migration 112 added
loom.code_repos.git_proxy_identity to the dump, and tests/analyzer/shapes.txt
still listed the shape of the dump before it: the corpus test reported one
shape new and one gone.

The file is regenerated with python -m tests.analyzer.corpus --write. That one
entry is its whole diff.

Signed-off-by: pufit <[email protected]>
@zlareb1 zlareb1 self-assigned this Nov 19, 2026

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings. Checked proxy authentication and credential redaction, TLS, submodule transports, admin authorization, repository identity propagation and schema compatibility. Exact-head tests: 761 passed, one Linux-only skip. Combined with the current base: 441 tests and nine generator checks pass. CI covers the live integration, mixed-version and Linux sandbox paths.

@zlareb1
zlareb1 merged commit 8913338 into main Nov 19, 2026
89 of 90 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 19, 2026
6 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants