Resolve ssh.<forge> remotes to their web/API host #343

Merged
stephen merged 6 commits from fix/ssh-host-api-host into main 2026-11-30 21:11:13 +00:00
Owner

Closes #342.

parse_remote returned the git transport host as the API host. On a Fjord forge the git SSH endpoint is a separate ssh.<forge> name while the web and API live at the parent <forge>, so a repo cloned over ssh.<forge> resolved to ssh.<forge> and every API or web request hit a host that does not serve them.

For SSH transports only (an ssh:// URL, or the scp form git@ssh.<forge>:owner/name), a leading ssh. label now resolves to its parent when the config establishes that relationship. An https://ssh.example/... remote is a real web host and keeps its name, and a bare ssh host with no dot is left alone. authority already drops the port for SSH transports, so the resolved host is portless.

Scope change since the first version (read before merging). The first version stripped ssh. from every SSH remote. Review showed that can send an independent forge's clone to the wrong host. Now ssh.<host> maps to <host> only when <host> is a configured Fjord Account instance URL (the destination route() already matches). Nothing else maps:

  • PAT-only hosts with an ssh.<host> remote no longer auto-map. They keep the name the remote has. An explicit --host or -R still works as before.
  • A host configured as ssh.<name> keeps its own name, even beside a Fjord instance at <name>.
  • If <host> also has a PAT host entry, the pairing is ambiguous (route() prefers the PAT entry over the gateway), so the remote keeps its name.
  • A host key, a PAT web_url and --host are not treated as evidence of the ssh relationship.

Tests: parse-level cases for ssh:// and scp remotes (known and unknown parent, web port, configured ssh. host, https ssh. host, bare ssh), and a discovery test that runs discover() over a real temporary git repository and hosts.toml for the Fjord Account, PAT-only, web_url, nothing-configured, --host, other-instance, stale-PAT and ssh.<name> cases. The Fjord-instance case fails when the instance URLs are dropped from the known set.

Closes #342. `parse_remote` returned the git transport host as the API host. On a Fjord forge the git SSH endpoint is a separate `ssh.<forge>` name while the web and API live at the parent `<forge>`, so a repo cloned over `ssh.<forge>` resolved to `ssh.<forge>` and every API or web request hit a host that does not serve them. For SSH transports only (an `ssh://` URL, or the scp form `git@ssh.<forge>:owner/name`), a leading `ssh.` label now resolves to its parent when the config establishes that relationship. An `https://ssh.example/...` remote is a real web host and keeps its name, and a bare `ssh` host with no dot is left alone. `authority` already drops the port for SSH transports, so the resolved host is portless. **Scope change since the first version (read before merging).** The first version stripped `ssh.` from every SSH remote. Review showed that can send an independent forge's clone to the wrong host. Now `ssh.<host>` maps to `<host>` only when `<host>` is a configured Fjord Account instance URL (the destination `route()` already matches). Nothing else maps: - PAT-only hosts with an `ssh.<host>` remote no longer auto-map. They keep the name the remote has. An explicit `--host` or `-R` still works as before. - A host configured as `ssh.<name>` keeps its own name, even beside a Fjord instance at `<name>`. - If `<host>` also has a PAT host entry, the pairing is ambiguous (`route()` prefers the PAT entry over the gateway), so the remote keeps its name. - A host key, a PAT `web_url` and `--host` are not treated as evidence of the ssh relationship. Tests: parse-level cases for `ssh://` and scp remotes (known and unknown parent, web port, configured `ssh.` host, https `ssh.` host, bare `ssh`), and a discovery test that runs `discover()` over a real temporary git repository and `hosts.toml` for the Fjord Account, PAT-only, `web_url`, nothing-configured, `--host`, other-instance, stale-PAT and `ssh.<name>` cases. The Fjord-instance case fails when the instance URLs are dropped from the known set.
fix: resolve ssh.<forge> remotes to their web/API host
All checks were successful
ci / check (pull_request) Successful in 15m21s
ci / live-e2e (pull_request) Successful in 3m21s
ci / coverage (pull_request) Successful in 3m50s
2545cb257f
Fjord forges serve git SSH on a separate ssh.<forge> name while the web
and API live at the parent <forge>. parse_remote returned the SSH
transport host verbatim, so API and web requests against a repo cloned
over ssh.<forge> hit the wrong host and failed.

For SSH transports only (scp form, always SSH; ssh:// URLs), strip a
leading ssh. label so the parsed host is the web/API host. A https://
URL to an ssh.-prefixed host is a real web host and keeps its name; a
bare ssh host with no dot is left alone. Doing this inside parse_remote
keeps discover's preferred-host match comparing web hosts on both sides.

Closes #342
gerri requested changes 2026-11-29 21:45:03 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head 2545cb257f.

  • Medium src/git/remote.rs:144 . Invariant: Repository inference must preserve the actual forge identity unless there is evidence that the SSH endpoint maps to a different web host. Both SSH URL and scp remotes unconditionally remove ssh. for every Forgejo or Gitea server, although fj supports independent self-hosted forges. For a forge serving both SSH and web traffic at ssh.example.com, git@ssh.example.com:owner/repo.git now selects example.com. Commands can fail authentication or act on a same-named repository on that other host; --host ssh.example.com also fails remote discovery. This regression belongs in this PR because the new mapping causes it. Restrict the mapping to known Fjord destinations or an explicit configured mapping, and preserve the original host when the relationship is unknown. Test both SSH forms and preferred-host discovery for an independent forge.

BLOCKING: 1

Reviewed head 2545cb257f at 2026-11-29T21:45:02Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 2545cb257ff0567c2a51b7534f81437fd2969222. - **Medium** `src/git/remote.rs:144` . **Invariant:** Repository inference must preserve the actual forge identity unless there is evidence that the SSH endpoint maps to a different web host. Both SSH URL and scp remotes unconditionally remove `ssh.` for every Forgejo or Gitea server, although `fj` supports independent self-hosted forges. For a forge serving both SSH and web traffic at `ssh.example.com`, `git@ssh.example.com:owner/repo.git` now selects `example.com`. Commands can fail authentication or act on a same-named repository on that other host; `--host ssh.example.com` also fails remote discovery. This regression belongs in this PR because the new mapping causes it. Restrict the mapping to known Fjord destinations or an explicit configured mapping, and preserve the original host when the relationship is unknown. Test both SSH forms and preferred-host discovery for an independent forge. BLOCKING: 1 --- Reviewed head 2545cb257ff0567c2a51b7534f81437fd2969222 at 2026-11-29T21:45:02Z by codex exec (read-only sandbox).
An ssh.<host> remote is mapped to <host> only when <host> is a configured
host or the explicit --host. Any other ssh.<name> keeps its own identity,
since it may be a different forge. A host configured as ssh.<name> itself
keeps its name. Tests cover known, unknown, configured and port cases for
both ssh:// and scp-style remotes.
Count configured instance URLs as known forges, and test discovery end to end
All checks were successful
ci / check (pull_request) Successful in 17m51s
ci / live-e2e (pull_request) Successful in 4m13s
ci / coverage (pull_request) Successful in 5m17s
e0b5441e58
A Fjord Account host key is the gateway, so the forge an ssh.<name> remote
belongs to is the cached instance URL. Known forges now also cover a PAT
host's web URL and every account's instance URL, the same destinations
route() matches an inferred host against. A discovery test runs discover()
over a real temporary repository and hosts.toml for both URL forms.
gerri requested changes 2026-11-30 20:06:22 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head e0b5441e58.

  • Medium src/config/hosts.rs: Invariant: a resolved clone host must route to the configuration and credentials that established it. forge_destinations treats a PAT host’s web_url as evidence for stripping ssh., but metadata::route does not match PAT web_url values. For a supported PAT configuration whose stored key differs from its web URL, a clone at git@ssh.forge.example:o/r.git now resolves to forge.example, then routes to a default, unconfigured host instead of the PAT entry. Repository commands can fail authentication or use the wrong configuration. This is newly reachable through both discovery and pinned-remote parsing in this PR. Route PAT web URLs to their owning configuration with ambiguity checks, and test through the command routing boundary.

  • Medium src/git/remote.rs: Invariant: inferred repository identity must not change merely because an unrelated forge is configured. Knowing that example is a forge does not establish that ssh.example is its SSH endpoint. A user with a configured example forge who clones a separate forge hosted at ssh.example will have commands directed to example; a matching owner and repository slug can cause mutations on the wrong repository. The same inference applies to discovery and pinned remotes. Require an authoritative SSH-to-web mapping, or restrict the transform to an established Fjord relationship, and test the distinct-forge case when only the parent is configured.

  • Low src/git/remote.rs: Invariant: a configuration read failure must not be treated as an empty configuration. If the second Hosts::load fails after a command has loaded its configuration, discovery silently keeps the SSH hostname and can route differently from the command’s existing snapshot. This is an edge case involving a concurrent configuration change or read failure. Pass the already loaded configuration into discovery and propagate read errors at entry points that lack a snapshot.

BLOCKING: 2

Reviewed head e0b5441e58 at 2026-11-30T20:06:21Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head e0b5441e58e2b57d3131636ff6fd293414e32cbf. - **Medium** [src/config/hosts.rs](/home/dev/work/reviews/rasterstate-fj-343/src/config/hosts.rs:183): **Invariant: a resolved clone host must route to the configuration and credentials that established it.** `forge_destinations` treats a PAT host’s `web_url` as evidence for stripping `ssh.`, but `metadata::route` does not match PAT `web_url` values. For a supported PAT configuration whose stored key differs from its web URL, a clone at `git@ssh.forge.example:o/r.git` now resolves to `forge.example`, then routes to a default, unconfigured host instead of the PAT entry. Repository commands can fail authentication or use the wrong configuration. This is newly reachable through both discovery and pinned-remote parsing in this PR. Route PAT web URLs to their owning configuration with ambiguity checks, and test through the command routing boundary. - **Medium** [src/git/remote.rs](/home/dev/work/reviews/rasterstate-fj-343/src/git/remote.rs:191): **Invariant: inferred repository identity must not change merely because an unrelated forge is configured.** Knowing that `example` is a forge does not establish that `ssh.example` is its SSH endpoint. A user with a configured `example` forge who clones a separate forge hosted at `ssh.example` will have commands directed to `example`; a matching owner and repository slug can cause mutations on the wrong repository. The same inference applies to discovery and pinned remotes. Require an authoritative SSH-to-web mapping, or restrict the transform to an established Fjord relationship, and test the distinct-forge case when only the parent is configured. - **Low** [src/git/remote.rs](/home/dev/work/reviews/rasterstate-fj-343/src/git/remote.rs:50): **Invariant: a configuration read failure must not be treated as an empty configuration.** If the second `Hosts::load` fails after a command has loaded its configuration, discovery silently keeps the SSH hostname and can route differently from the command’s existing snapshot. This is an edge case involving a concurrent configuration change or read failure. Pass the already loaded configuration into discovery and propagate read errors at entry points that lack a snapshot. BLOCKING: 2 --- Reviewed head e0b5441e58e2b57d3131636ff6fd293414e32cbf at 2026-11-30T20:06:21Z by codex exec (read-only sandbox).
A host key, a PAT web URL or --host shows that a forge exists, not that
ssh.<forge> is its git endpoint, and route() does not match PAT web URLs
at all. Only a Fjord Account's cached instance URL, which route() does
match, now lets an ssh remote resolve to its parent forge. Discovery
tests cover the PAT-only, web_url, nothing-configured and --host cases.
Leave an ssh remote alone when a PAT entry already holds its parent host
All checks were successful
ci / check (pull_request) Successful in 22m44s
ci / live-e2e (pull_request) Successful in 3m44s
ci / coverage (pull_request) Successful in 4m5s
22e75c213f
route() prefers an exact PAT host entry over the Fjord gateway, so mapping
ssh.<forge> to a parent that also has a stale PAT entry could send the
clone to the wrong credentials. That pairing is ambiguous and is left to
--host or -R. A Fjord Account keyed by the instance host itself is not.
Author
Owner

Follow-up, not in this PR: KnownForges::configured() reads hosts.toml again inside discover and pinned_remote, while resolve_repo already holds a loaded Hosts snapshot. If the file changes between the two reads (another terminal switching the selected instance), inference and routing could disagree, and a read failure silently falls back to "nothing configured", which keeps the ssh name. The fix is to pass the loaded Hosts into both discovery paths and propagate read errors where no snapshot exists. Gerri and self-review both raised it as a Low.

Follow-up, not in this PR: `KnownForges::configured()` reads `hosts.toml` again inside `discover` and `pinned_remote`, while `resolve_repo` already holds a loaded `Hosts` snapshot. If the file changes between the two reads (another terminal switching the selected instance), inference and routing could disagree, and a read failure silently falls back to "nothing configured", which keeps the ssh name. The fix is to pass the loaded `Hosts` into both discovery paths and propagate read errors where no snapshot exists. Gerri and self-review both raised it as a Low.
gerri approved these changes 2026-11-30 20:33:53 +00:00
gerri left a comment

Automated Codex review (read-only) of head 22e75c213f.

No actionable findings found.

BLOCKING: 0

Reviewed head 22e75c213f at 2026-11-30T20:33:52Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 22e75c213faa758ae7afba8762127b9bc4b74b90. No actionable findings found. BLOCKING: 0 --- Reviewed head 22e75c213faa758ae7afba8762127b9bc4b74b90 at 2026-11-30T20:33:52Z by codex exec (read-only sandbox).
stephen deleted branch fix/ssh-host-api-host 2026-11-30 21:11:13 +00:00
Sign in to join this conversation.
No description provided.