feat: make root key optional for connected networks#639
Draft
lwshang wants to merge 3 commits into
Draft
Conversation
The root key for a connected network is now optional and resolved by trust scope when the network is accessed: - explicit key (manifest `root-key` / `--root-key`) -> used as-is - omitted + loopback URL -> fetched from the network status endpoint - omitted + remote URL -> hard error, fail fast Previously `--network <URL>` required `--root-key`, and an omitted manifest key silently defaulted to the mainnet key. A local (loopback) network never had a stable key to hardcode, so connecting by URL meant pasting a 266-char key. Fetching on loopback is safe (no meaningful MITM surface); refusing on remote surfaces a clear error early instead of a cryptic certificate-verification failure on the first certified call. The built-in `ic` network is unchanged: still the hardcoded mainnet key, non-overridable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`status_connected_network` defined a connected network at a remote URL (https://ic0.app) with no root key and expected success. Under the new contract a remote connected network must specify its root key, so the manifest now includes the mainnet root key. Also adds a test asserting that a keyless remote connected network fails fast with a clear message. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates how connected networks handle root keys by making the runtime Connected.root_key optional and resolving it at access time: fetch automatically for loopback URLs, and fail fast with a clear error for remote URLs. This improves ergonomics for local networks while avoiding the previous (misleading) default-to-mainnet behavior.
Changes:
- Changed runtime
Connected.root_keyfromVec<u8>toOption<Vec<u8>>and stopped defaulting missing manifest keys to the mainnet key. - Centralized root-key resolution in
get_connected_network_access()viaresolve_root_key()(loopback fetch vs remote error). - Updated CLI parsing/docs and added tests covering loopback fetch and remote-without-key failure.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| docs/reference/cli.md | Updates --root-key option documentation to reflect loopback-fetch vs remote-required behavior. |
| crates/icp/src/project.rs | Updates default mainnet connected network construction to wrap the root key in Some(...). |
| crates/icp/src/network/mod.rs | Makes Connected.root_key optional, adds serde helper for optional hex encoding, and removes mainnet defaulting during manifest conversion. |
| crates/icp/src/network/access.rs | Resolves optional root keys at access time (fetch on loopback; error on remote) and introduces new error variants. |
| crates/icp/src/lib.rs | Updates mock project loader’s connected mainnet network to use Some(IC_ROOT_KEY...). |
| crates/icp/src/context/mod.rs | Makes URL-based network selection carry an optional root key and propagates it into the connected network config. |
| crates/icp-cli/tests/network_status_tests.rs | Updates/extends status tests to require explicit key for remote connected networks and assert failure without it. |
| crates/icp-cli/tests/canister_call_root_key_tests.rs | Adds end-to-end loopback fetch test and a remote URL missing-key error test. |
| crates/icp-cli/src/options.rs | Makes --root-key optional for URL networks at CLI parse time and defers remote/loopback enforcement to access-time resolution. |
| CHANGELOG.md | Documents the behavioral change, including the new error on raw mainnet-by-URL without a key. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Makes the root key optional for connected networks, resolved by trust scope when the network is accessed:
root-key/--root-key)The built-in
icnetwork is unchanged — still the hardcoded mainnet key, non-overridable.Motivation
Previously
--network <URL>required--root-key, and an omitted manifest key silently defaulted to the mainnet key. A local (loopback) network has no stable key to hardcode, so connecting to one by URL meant pasting a 266-char hex key.--root-key, or use--network icfor mainnet) instead of a cryptic certificate-verification failure on the first certified call. A genuine remote network never shares mainnet's key, so the old mainnet-default only deferred the failure — this is a diagnostics improvement, not a security change (both are fail-safe).Implementation
Connected.root_key:Vec<u8>→Option<Vec<u8>>(runtime type only; the manifest field was already optional). The manifest→runtime conversion no longer defaults to the mainnet key.get_connected_network_access→resolve_root_key(crates/icp/src/network/access.rs) — which loopback-checks the URL, then fetches (anonymous agent →fetch_root_key→read_root_key) or fails withRootKeyRequiredForRemote. Runs before any RPC, so it covers both the CLI and manifest paths.NetworkAccess.root_keystaysVec<u8>, so identity/delegation andset_root_keydownstream are untouched.--network <URL>no longer forces--root-key; a named network still rejects it.Notable consequence
Connecting to actual mainnet by raw URL without a key now errors instead of silently working — the message points users to
--network icor--root-key.Testing
--root-keycall against a running local network tocanister_call_with_url_and_root_key(exercises the loopback-fetch path end-to-end).canister_call_remote_url_without_root_key_errors(fast, no live server — the loopback check short-circuits before any request).cargo fmt --checkclean,cargo clippyzero warnings, full-workspacecargo test --no-runcompiles.docs/reference/cli.md) regenerated.🤖 Generated with Claude Code