Repository navigation
feat(execution): system API ic0.is_subnet_admin - #12063
Draft
pietrodimarco-dfinity wants to merge 1 commit into
Draft
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>
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