Skip to content

feat(common): validate-time relay URL parse check (#818) - #828

Merged
thiras merged 3 commits into
mainfrom
feat/818-config-validate-relay-urls
Jun 6, 2026
Merged

thiras merged 3 commits into
mainfrom
feat/818-config-validate-relay-urls

Conversation

@thiras

@thiras thiras commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

What

Scope 2 of #818. Adds a fail-fast parse check for network.relay_urls at config-resolution time so decdn config validate rejects a malformed relay URL up front and names the offending entry, instead of the failure only surfacing later at node bring-up.

Before

parse_relay_urls (node runtime) rejects a bad entry at bring-up, but decdn config validate reported the same config as valid — the operator only discovered the typo when the daemon failed to start.

After

resolve_network_into parse-checks each resolved relay URL with url::Url::parse and records an indexed network.relay_urls[i] problem into the shared ConfigErrorBag, so it:

  • fails config validate immediately and names the bad entry,
  • aggregates with every other config problem in a single pass (configuration has N problem(s):),
  • mirrors how S3 endpoint/bucket fields are already validated.

Why a url::Url subset (and not iroh's RelayUrl)

The check is a deliberate subset of bring-up's iroh::RelayUrl parse. RelayUrl wraps a url::Url, so anything url::Url::parse rejects, RelayUrl rejects too. Consequences:

  • No false positives — e.g. a relay://host scheme (which RelayUrl accepts, per the runtime test at runtime/mod.rs:2930) passes the validate-time check too.
  • Bring-up's RelayUrl parse stays the authoritative gate for relay-specific shape.
  • No iroh dependency is pulled into the common crate (the issue's stated constraint).

The offending entry is echoed verbatim in the error, consistent with the existing config validate summary which already prints relay URLs verbatim.

Tests (TDD)

  • resolve_network_accepts_well_formed_relay_urls — happy path, incl. a non-http(s) relay:// scheme.
  • resolve_network_records_problem_for_malformed_relay_url — names the indexed field + entry.
  • resolve_network_reports_each_malformed_relay_entry_by_index — only bad indices reported, in order.
  • resolve_config_errors_on_malformed_relay_url — end-to-end through resolve_config (temp TOML).
  • validate_fails_for_malformed_relay_url — end-to-end through the decdn config validate CLI command.

All 490 decdn-common/decdn-cli tests pass; cargo fmt --check, cargo clippy --all-targets -- -D warnings, and pre-commit hooks (fmt/clippy/doc/deny) are clean.

Scope

This is scope 2 of #818 (the small config validate fix from the #817 review). Scope 1 — self-hosted discovery replacing the n0 DNS/pkarr leg — remains open under #818.

🤖 Generated with Claude Code

Scope 2 of #818. A malformed `network.relay_urls` entry was only rejected
at node bring-up (`parse_relay_urls` in the node runtime); `decdn config
validate` reported such a config as valid, deferring the failure to
startup.

Validate each resolved relay URL with `url::Url::parse` in
`resolve_network_into`, recording an indexed `network.relay_urls[i]`
problem into the shared `ConfigErrorBag` so `config validate` fails fast
and names the offending entry — matching how S3 endpoint/bucket fields are
validated, and aggregating with every other config problem in one pass.

The check is deliberately a *subset* of bring-up's `iroh::RelayUrl` parse:
`RelayUrl` wraps a `url::Url`, so anything `url::Url::parse` rejects
`RelayUrl` rejects too. This means no false positives (e.g. a `relay://`
scheme passes both), bring-up's `RelayUrl` parse stays authoritative for
relay-specific shape, and no `iroh` dependency is pulled into `common`.

Scope 1 (self-hosted discovery, replacing the n0 DNS/pkarr leg) remains
open under #818.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 6, 2026 13:43

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces early validation for relay URLs during configuration resolution, ensuring malformed entries are caught upfront during configuration validation rather than later at node bring-up. It also adds comprehensive unit and integration tests to verify this behavior. The reviewer provided valuable feedback suggesting that the error label should distinguish between singular and plural relay URL configurations to avoid misleading operators, and recommended omitting the raw URL from error messages to prevent potential credential leakage.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/common/src/config/mod.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR implements scope 2 of #818 by adding validate-time parsing for network.relay_urls during config resolution, so decdn config validate fails fast and pinpoints malformed relay URL entries by index instead of only failing later during node bring-up.

Changes:

  • Add resolve_network_into(..., &mut ConfigErrorBag) and parse-check each resolved relay_urls[i] with url::Url::parse, recording indexed errors.
  • Add unit tests covering valid relay URL schemes and multiple malformed entries with indexed diagnostics.
  • Add CLI integration test asserting decdn config validate fails and names the offending network.relay_urls[i] entry.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/common/src/config/mod.rs Adds validate-time relay URL parsing/diagnostics in config resolution and corresponding unit tests.
crates/cli/tests/config_validate.rs Adds an end-to-end CLI test that config validate fails on malformed network.relay_urls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/common/src/config/mod.rs Resolved
@github-actions

github-actions Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 87.46% (was 87.41%, ▲ +0.05%) — 29823/34099 lines

File Coverage Lines Δ
crates/common/src/config/mod.rs 96.55% 5263/5451 ▲ +0.07%
crates/common/src/redact.rs 100.00% 32/32 new
crates/node/src/runtime/mod.rs 52.66% 782/1485 ▼ 1.00%
History
Commit Total Δ vs base
f1a49fb 87.43% ▲ +0.03%
dc5da60 87.45% ▲ +0.05%
1291747 (HEAD) 87.46% ▲ +0.05%

thiras and others added 2 commits June 6, 2026 16:53
Addresses PR #828 review: the validate-time relay-URL check echoed the
offending entry verbatim (`{entry:?}`), while bring-up's `parse_relay_urls`
deliberately redacts `user:pass@` userinfo with the invariant "relay
userinfo never reaches a log/error". A credential-bearing typo such as
`relay://user:pass@bad host` fails `url::Url::parse` and so hit the error
arm, leaking credentials into `decdn config validate` output.

- Lift `redact_userinfo` from the `node` runtime into a shared
  `decdn_common::redact` module (with its unit test) so both gates use one
  implementation and the redaction invariant cannot drift between copies.
  `parse_relay_urls` now calls the shared helper.
- Redact the entry in `resolve_network_into` before echoing it.
- Fix the doc comment: the prior "no iroh dependency is pulled into
  common" claim was false (common already depends on iroh via identity);
  reworded to the accurate, narrower claim (this check needs no iroh
  import). Drop the inline justification that papered over the redaction
  divergence.
- Guard the `#[cfg(test)] resolve_network` shim with a `debug_assert` so a
  future caller that feeds a malformed URL trips loudly instead of silently
  dropping the discarded bag's problem.
- Add tests: validate-time credential redaction, and validation of the
  deprecated singular `relay_url` alias source path.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Addresses PR #828 bot review (gemini, copilot): when a malformed relay URL
came from the deprecated singular `network.relay_url` or the CLI
`--relay-url` flag, the validate error was reported under the indexed
`network.relay_urls[i]` label — pointing an operator at an array they never
wrote. Label by the source the operator actually used: the indexed array
field only when the `relay_urls` list branch was taken, otherwise the
singular `network.relay_url` (both singular sources always resolve to a
one-element vec). Matches the resolver's canonical-field labelling
convention.

Tests for both singular branches (alias + CLI flag) assert the singular
label and that no array index is emitted.

The credential-leakage point both bots raised was already resolved in the
prior commit (redaction via the centralized `decdn_common::redact`).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras merged commit d32660e into main Jun 6, 2026
19 checks passed
@thiras
thiras deleted the feat/818-config-validate-relay-urls branch June 6, 2026 14:06
thiras added a commit that referenced this pull request Jun 9, 2026
* feat(node): operator-configurable self-hosted discovery (#818)

Replace the n0-hosted DNS/pkarr address-lookup leg with operator-configurable
discovery (scope 1 of #818; scope 2 landed in #828). Two operator-selectable,
combinable mechanisms:

- Custom pkarr + DNS: `network.discovery.pkarr_url` (publish this node's signed
  address record) + `network.discovery.dns_origin` (resolve peers via DNS TXT).
- Static peer map: `network.discovery.peers.<NodeId>` -> {relay_url, addrs}
  seeded into a `MemoryLookup` for fully n0-independent, offline networks.

Wiring follows the discovery-provider seam (adr/appendix-poc-production-seams.md):
`common` config holds plain shape-validated Strings; the `node` runtime parses
them into iroh providers. `build_endpoint` keeps `presets::N0` when no discovery
is configured (back-compat) and builds on `presets::Minimal` + the configured
`address_lookup` legs otherwise, restoring the n0 relay default when no custom
relay map is set (relay and discovery are orthogonal seams).

Config resolution shape-validates every entry with the same parsers the node
uses at bring-up — peer NodeId via `iroh::PublicKey`, pkarr URL via `url::Url`,
socket addrs via `SocketAddr` — so `decdn config validate` fails fast and names
the offending field with credentials redacted, never deferring to a late
startup failure. `pkarr_url` without `dns_origin` is rejected (publish with no
resolver); `dns_origin` alone is valid.

Surfaces the knob across the config schema, resolver+validation, `config
validate` summary (pkarr_url redacted, peer entries shown only as a count), and
the DEFAULT_CONFIG template. Adds an appendix note for the seam.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* refactor(config): address PR review on discovery (#818)

- Validate-summary: redact only the pkarr_url userinfo via redact_userinfo
  (keeping the host visible for diagnostics) instead of fully hiding it — a
  pkarr relay's only credential vector is `user:pass@`, unlike rpc_url whose
  secret commonly lives in the path/query. Update the summary test to a
  credential-bearing URL asserting host-preservation + userinfo redaction.
- Sort resolved peers with sort_unstable_by (node_ids are unique HashMap keys,
  so stable ordering is unnecessary and this avoids the aux allocation).
- Fix stale "64-hex NodeId" doc wording (resolved peer field, resolve_discovery
  doc, DEFAULT_CONFIG template, ADR appendix): validation accepts any iroh
  NodeId — lowercase hex or z-base-32 — since it parses with iroh::PublicKey.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(config): correct NodeId form wording + pkarr redaction comment (#818)

Second-pass review fixes:

- The peer NodeId accepted form was documented as "lowercase hex or z-base-32",
  but `iroh::PublicKey::from_str` decodes lowercase hex (HEXLOWER) or RFC-4648
  base32 — NOT z-base-32 (a separate to_z32/from_z32 path FromStr never calls).
  The canonical Display form is lowercase hex, which is what operators copy and
  what the validator round-trips. Correct all sites in this PR to the canonical
  lowercase-hex wording (types.rs, resolved.rs, mod.rs doc + error string,
  DEFAULT_CONFIG, ADR appendix).

- Soften the pkarr_url summary-redaction comment: drop the "only credential
  vector" overclaim and the misleading "same treatment the relay path uses"
  (the relay summary line prints unredacted; redaction is on the error-echo
  path). State the path/query caveat of redact_userinfo explicitly. Behavior
  (userinfo-redacted, host visible) is unchanged — appropriate for an infra
  relay endpoint whose auth is the signed packet, and stricter than the
  relay-URL summary precedent.

- Add two summary test guards: pkarr_url label is emitted; no discovery.* lines
  appear when discovery is unset.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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