pub struct RoleBasedAccessControl;Expand description
Role-based access control (RBAC) for account components.
RBAC provides fine-grained access control on top of Ownable2Step. Instead of having
one account holding every privilege, privileges are split into named roles (for example
MINTER, BURNER, PAUSER), and each procedure is guarded against the caller’s role
membership. It allows role assignment with domain isolation to minimize the scope of
damage from a compromised role.
§Relation to Ownable2Step
RBAC is a superset of Ownable2Step and depends on it: the top-level authority is
the Ownable2Step owner of the account. Build the pair via
AccessControl::Rbac passed to
AccountBuilder::with_components.
This avoids duplicated state, duplicated 2-step transfer logic, and duplicated notes
for owner transfers. If you only need single-account control, use Ownable2Step
alone.
§Owner management
The owner can grant and revoke any role, configure the delegated admin of any role via
set_role_admin, and transfer or renounce its own position. Owner transfer and
renouncement go through Ownable2Step (transfer_ownership, accept_ownership,
renounce_ownership).
§Role hierarchy
Every role may optionally have a delegated admin role. Accounts holding a role’s admin
role are authorized to grant and revoke that role without going through the owner.
For example, accounts holding MINTER_ADMIN can manage the MINTER role but have no
authority over BURNER or PAUSER. This lets responsibilities be distributed so that
compromise of one domain does not spill into the others.
Combined with owner renouncement, this supports a fully decentralized configuration: once every role has its own admin role populated, the owner can renounce and the system continues to operate with each role managed only by its designated admin role.
The delegated admin of a role can itself be any role, including one that it admins. Circular relationships are possible but should be designed with care, since each role can then revoke the other.
§Role semantics
A role is considered to exist when it has at least one member. Granting the first
member creates the role; revoking the last member removes it. As a consequence,
set_role_admin(A, B) stores the admin relationship in storage but does not make role
A exist until a member is granted. Once the last member of A is revoked,
get_role_member_count(A) returns 0, though the admin configuration is retained and
will apply the next time a member is granted.
§Membership lookup
has_role procedure is the primary guard used by procedures that assert the caller’s
role membership. get_role_member_count returns the number of accounts holding a role.
§Role symbol format
A RoleSymbol encodes up to 12 uppercase ASCII characters with underscores into a
single field element using the same packing as the token symbol type. Examples:
MINTER, MINTER_ADMIN, PAUSER. The zero field element is reserved and cannot be
used as a role symbol; attempting to do so panics with ERR_ROLE_SYMBOL_ZERO.
§Usage
Guarding a procedure in MASM so that only members of MINTER can call it:
pub proc mint
push.MINTER_ROLE_SYMBOL
exec.::miden::standards::access::rbac::assert_sender_has_role
# add mint logic
endImplementations§
Source§impl RoleBasedAccessControl
impl RoleBasedAccessControl
pub const NAME: &'static str = "miden::standards::components::access::rbac"
Sourcepub const fn name() -> AccountComponentName
pub const fn name() -> AccountComponentName
Returns the canonical AccountComponentName of this component.
Sourcepub fn code() -> &'static AccountComponentCode
pub fn code() -> &'static AccountComponentCode
Returns the AccountComponentCode of this component.
Sourcepub fn empty() -> RoleBasedAccessControl
pub fn empty() -> RoleBasedAccessControl
Returns an empty RBAC component. Roles are populated at runtime via the
grant_role, set_role_admin, etc. procedures exposed by the component.
Sourcepub fn role_config_slot() -> &'static StorageSlotName
pub fn role_config_slot() -> &'static StorageSlotName
Returns the storage slot name for the per-role config map.
Sourcepub fn role_membership_slot() -> &'static StorageSlotName
pub fn role_membership_slot() -> &'static StorageSlotName
Returns the storage slot name for the per-role membership map.
Sourcepub fn role_config_slot_schema() -> (StorageSlotName, StorageSlotSchema)
pub fn role_config_slot_schema() -> (StorageSlotName, StorageSlotSchema)
Returns the schema entry for the per-role config map.
Sourcepub fn role_membership_slot_schema() -> (StorageSlotName, StorageSlotSchema)
pub fn role_membership_slot_schema() -> (StorageSlotName, StorageSlotSchema)
Returns the schema entry for the per-role membership map.
Sourcepub fn component_metadata() -> AccountComponentMetadata
pub fn component_metadata() -> AccountComponentMetadata
Returns the AccountComponentMetadata describing this component.
Trait Implementations§
Source§impl Clone for RoleBasedAccessControl
impl Clone for RoleBasedAccessControl
Source§fn clone(&self) -> RoleBasedAccessControl
fn clone(&self) -> RoleBasedAccessControl
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RoleBasedAccessControl
impl Debug for RoleBasedAccessControl
Source§impl Default for RoleBasedAccessControl
impl Default for RoleBasedAccessControl
Source§fn default() -> RoleBasedAccessControl
fn default() -> RoleBasedAccessControl
impl Eq for RoleBasedAccessControl
Source§impl From<RoleBasedAccessControl> for AccountComponent
impl From<RoleBasedAccessControl> for AccountComponent
Source§fn from(_rbac: RoleBasedAccessControl) -> AccountComponent
fn from(_rbac: RoleBasedAccessControl) -> AccountComponent
Source§impl PartialEq for RoleBasedAccessControl
impl PartialEq for RoleBasedAccessControl
Source§fn eq(&self, other: &RoleBasedAccessControl) -> bool
fn eq(&self, other: &RoleBasedAccessControl) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for RoleBasedAccessControl
Auto Trait Implementations§
impl Freeze for RoleBasedAccessControl
impl RefUnwindSafe for RoleBasedAccessControl
impl Send for RoleBasedAccessControl
impl Sync for RoleBasedAccessControl
impl Unpin for RoleBasedAccessControl
impl UnsafeUnpin for RoleBasedAccessControl
impl UnwindSafe for RoleBasedAccessControl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more