Repository navigation
feat(execution): system API ic0.is_subnet_admin - #12063
Open
pietrodimarco-dfinity wants to merge 1 commit into
Open
pietrodimarco-dfinity wants to merge 1 commit into
pietrodimarco-dfinity wants to merge 1 commit into
Conversation
`ic0.is_subnet_admin : (src : I, size : I) -> (result : i32)` returns 1 if the principal is a subnet admin of the subnet the canister runs on, and 0 otherwise. Admins count only on subnets that can have them (cloud engines and rented subnets), as in `ReplicatedState::get_own_subnet_admins`. Like `ic0.is_controller`, it traps on an invalid principal and is available in every context. It lets a canister opt in to trusting the subnet admins, who can already manage every canister on a cloud engine through the management canister, without changing what `ic0.is_controller` means. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
✅ No security or compliance issues detected. Reviewed everything up to f7cd32e. Security OverviewDetected Code Changes
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change adding subnet-admin authorization.
No open issues 🎉
What changed in this PR
Adds ic0.is_subnet_admin so canisters can opt into subnet-admin authorization without changing ic0.is_controller. Membership follows the existing eligibility rules for cloud engines and rented subnets.
Changes:
- Reads admin membership from the sandbox’s existing network topology.
- Adds Wasm32/Wasm64 validation and runtime linking, with the same instruction cost as
ic0.is_controller. - Tests membership, invalid principals, execution-context availability, and Wasm64 compatibility; records the call in query-cache coverage.
| File | Description |
|---|---|
rs/interfaces/src/execution_environment.rs |
Declares the system API and tracking identifier. |
rs/execution_environment/tests/hypervisor.rs |
Tests membership through updates and queries, plus invalid-principal trapping. |
rs/execution_environment/src/query_handler/query_cache/tests.rs |
Includes the API in query-cache dependency classification. |
rs/embedders/tests/wasmtime_embedder.rs |
Tests the Wasm64 import signature and invocation. |
rs/embedders/tests/system_api.rs |
Tests context availability and invalid-principal errors. |
rs/embedders/src/wasmtime_embedder/system_api/sandbox_safe_system_state.rs |
Checks eligible own-subnet admin membership. |
rs/embedders/src/wasmtime_embedder/system_api.rs |
Implements principal parsing, membership lookup, and tracing. |
rs/embedders/src/wasmtime_embedder/system_api_complexity.rs |
Defines the 1,000-instruction overhead. |
rs/embedders/src/wasmtime_embedder/linker.rs |
Links the API and charges overhead plus input size. |
rs/embedders/src/wasm_utils/validation.rs |
Registers the import signature for both memory modes. |
Review effort: Balanced
This branch has not been deployed
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
New system API:
It returns 1 if the principal at
src/sizeis a subnet admin of the subnet the canister runs on, and 0 otherwise. Likeic0.is_controller, it traps if the bytes are not a valid principal and can be called from every entry point.Why. Since #11835, a cloud engine's subnet admins can manage every canister on the engine through the management canister. A canister's own code can't recognize them:
ic0.is_controllerreads only the canister's controller list, and subnet admins are not on it.OpenCloud runs into this. Its engine-operator canister is a subnet admin of its engine, and it writes
/.well-known/ic-domainsand/.well-known/ii-alternative-originsinto the certified-assets canisters of the engine's apps. certified-assets accepts writes only from controllers, so today the operator adds itself to each app's controller list withupdate_settings. Owners then see an extra controller, and if they remove it, the operator can no longer write the files.With this API, certified-assets (or any canister) can accept subnet admins alongside its controllers.
Why a separate call rather than changing
ic0.is_controller. Martin suggested this on Slack.ic0.is_controllerkeeps its literal meaning, and canisters opt in: an app's controller-only methods stay closed to subnet admins unless its code asks.Behavior
can_have_subnet_admins): cloud engines and rented subnets, both on the free cost schedule. This is the same rule asReplicatedState::get_own_subnet_admins, which the management canister uses. On every other subnet it returns 0, so a canister can call it anywhere.NetworkTopologythat the sandbox already receives.ic0.is_controller: 1,000 instructions plus the size of the principal.query_cache_max_expiry_time(10 minutes), asic0.subnet_self_node_countcan after a membership change. Replicated execution always sees the current set.Open questions
get_own_subnet_admins, even though on rented subnets they get fewer management rights than on cloud engines. If it should count cloud engines only, that is a one-line change.ic0.is_subnet_admin : (src : I, size : I) -> (result : i32)checks whether the principal identified bysrc/sizeis one of the subnet admins of the subnet the canister is running on. If yes, it returns 1, otherwise 0. Only cloud engines and rented subnets have subnet admins; on any other subnet it returns 0. It traps ifsrc/sizedoes not identify a valid principal. Available in every context, likeic0.is_controller.Testing
hypervisor.rs, 4 new tests. Each call goes through both an update and a non-replicated query, which must agree.CanisterContractViolation.embedders:ic0.is_controller(system_api_availability);InvalidPrincipalId;wasm64_import_system_api_functions).query_cache_future_proof_testlists the new call.Run locally with cargo, not bazel:
ic-embedders:system_api,wasmtime_embedderandsandbox_safe_system_stateall pass (145 tests).ic-execution-environmenthypervisor: 335 pass. 3 fail (call_perform_checks_freezing_threshold_in_update,ic0_canister_version,ic0_msg_caller_size_works_in_heartbeat) and fail the same way on master: cargo gave them a universal canister I built locally rather than the bazel one.query_cache_future_proof_testpasses.cargo clippy --no-deps -D warningson the three touched crates is clean.🤖 Generated with Claude Code