Skip to content

fix(sync): fail a run whose stored host POST /repos refuses - #907

Open
ThomasK33 wants to merge 2 commits into
mainfrom
sync-stored-host-check
Open

ThomasK33 wants to merge 2 commits into
mainfrom
sync-stored-host-check

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Since #903, POST /repos refuses an upstream host that a sync run cannot use as given. A link stored before that keeps such a host, and every pull and push run still handed it to git. The result depended on the host, and so did the failure class. The new test on main (allow-private egress policy, the test fixture's default) shows it:

Stored host Pull and push run on main
bücher.example, https://bücher.example failed to clone repository / failed to push to upstream: this host's curl refused the URL (URL using bad/illegal format)
http://2130706433:<port>, http://0x7f.1:<port>, http://127.0.0.1:<port>? the request reached the loopback upstream: curl dialed 127.0.0.1
http://127.0.0.1:<port>/a b, forge.example:65536 curl refused the URL
HTTP://127.0.0.1:<port> git refused the transport (transport 'HTTP' not allowed)
https://[fe80::1%25eth0] upstream repository unreachable: the egress dial failed

Now each run checks the stored host with the rule of POST /repos before git starts. A host that fails it fails the run as repository configuration error. The cause in the server's WARN line for the run is the reason that POST /repos gives, upstream host is not a valid host, and it does not repeat the host.

A stored link that synced before can now fail every run. With the allow-private policy, a http://2130706433:<port> link reached a git server on 127.0.0.1 and could sync from it; a bücher.example link could sync where the server's curl and locale convert the name (I did not verify this; this host's curl refuses it). This is the intended change, and it goes into the release notes with #903's. The docs tell operators to link such an upstream again with the host in its ASCII form.

Changes

  • ValidUpstreamHost and its helpers (dialableAuthority, dialableHostname, resolverName, curlIPv4Name, curlIPv4Part) move unchanged from internal/api/handlers_sync.go to internal/sync/upstreamhost.go, because api imports sync and not the reverse. InvalidUpstreamHostReason (is not a valid host) is the reason both packages give. TestValidUpstreamHost moves with them.
  • upstreamURLFailure, which both lanes call before git starts, checks the host before the URL length. A file:// host is exempt: only the tests' fixtures store one, POST /repos never has, and GIT_ALLOW_PROTOCOL refuses it in production.
  • Docs: docs/reference/http-api.md ("Upstream sync") says how such a run fails and how to link the upstream again; the READMEs of internal/api and internal/sync.
  • worker.go and handlers_sync.go are covered by the lane-schedule model, so the fingerprints are re-recorded. The host rule's functions leave the record with handlers_sync.go: the model describes lanes, not hosts.

Evidence

  • Test: TestRunRefusesStoredInvalidHost (internal/sync) stores the nine hosts above, at least one per class that POST /repos refuses, and runs each through the pull lane and the push lane. Each run must return exactly repository configuration error: upstream host is not a valid host, emit a failed event with repository configuration error, send no request to the loopback upstream, and log that cause without the host.
  • Red on main: with main's worker.go, all 18 cases fail as in the table.
  • Lanes: go test -race -tags=openstorage_viewcheck of ./internal/sync/... (91 s) and ./internal/api/... without pg (373 s) passes at d75a879. PostgreSQL and S3-WAL rely on CI.
  • lint, vet (linux and darwin), gofmt, the docs gate and both fingerprint gates pass.

Found by the reviews of #903 (desk follow-up).


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

as given: a name with letters outside ASCII, a number that curl reads as
an IPv4 address, a port outside 1-65535, an IPv4 literal with a zone, or
a base URL with `?`, `#`, a space or an upper-case scheme. A link stored
before that keeps its host, and every run handed it to git. Depending on
the host, git or curl refused the URL, or curl dialed an address that the
registration check never saw (2130706433 is 127.0.0.1), and the failure
class varied.

Each pull and push run now checks the stored host with the rule of
POST /repos before git starts. A host that fails it fails the run as
`repository configuration error`, and the cause is the reason that
POST /repos gives, `upstream host is not a valid host`, without the
host.

ValidUpstreamHost and its helpers move from internal/api to
internal/sync, because api imports sync and not the reverse, and
InvalidUpstreamHostReason is the shared reason. A file:// host stays
exempt: only the tests' fixtures store one, and GIT_ALLOW_PROTOCOL
refuses it in production. The docs tell operators to link such an
upstream again with the host in its ASCII form.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

Change-Id: I4bd9c08939f72be8e5b3a5c90bda11244103b1ae
Signed-off-by: Thomas Kosiewski <tk@coder.com>
worker.go and handlers_sync.go are covered code: upstreamURLFailure checks
the stored host, and the host rule moves to internal/sync.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_

Change-Id: I52a372967181736ba269cb6f75dbde8513212b8b
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T02:06:30.412618Z d75a879 Manual request
🔒 Security Review ✅ Completed 2026-11-17T02:07:36.750434Z d75a879 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: d75a8793f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: d75a8793f5

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

This branch has not been deployed

No deployments
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.

1 participant