pub enum PrivilegeLevel {
Standard,
Elevated {
until: Instant,
},
}Expand description
The current privilege level of a session.
This implements a sudo-like model where all actors start with limited permissions and must explicitly elevate to perform privileged operations.
§Design Rationale
§Why Not Always Elevated?
Even human users operate in Standard mode by default:
- Prevents accidents:
git reset --hardrequires explicit elevation - Audit clarity: Elevated actions are intentional and logged
- Network safety: Compromised sessions have limited damage potential
§Time-Limited Elevation
Elevated privileges automatically expire to minimize the window of elevated access. This follows the principle of least privilege.
§Example
use orcs_auth::PrivilegeLevel;
use std::time::{Duration, Instant};
// Standard mode (default)
let standard = PrivilegeLevel::Standard;
assert!(!standard.is_elevated());
// Elevated mode (explicit, time-limited)
let until = Instant::now() + Duration::from_secs(300);
let elevated = PrivilegeLevel::Elevated { until };
assert!(elevated.is_elevated());Variants§
Standard
Normal operations only.
In this mode, the following are not allowed:
- Global signals (Veto)
- Destructive file operations (
rm -rf, overwrite without backup) - Destructive git operations (
reset --hard,push --force) - Modifying system configuration
This is the default mode for all principals.
Elevated
Elevated privileges with expiration.
Grants full access to all operations until the specified time. After expiration, the session automatically drops to Standard.
§Fields
until- When elevation expires (automatically serializes as duration from now)
Implementations§
Source§impl PrivilegeLevel
impl PrivilegeLevel
Sourcepub fn standard() -> PrivilegeLevel
pub fn standard() -> PrivilegeLevel
Creates a new Standard privilege level.
Sourcepub fn elevated_for(duration: Duration) -> PrivilegeLevel
pub fn elevated_for(duration: Duration) -> PrivilegeLevel
Creates a new Elevated privilege level with the given duration.
§Example
use orcs_auth::PrivilegeLevel;
use std::time::Duration;
let elevated = PrivilegeLevel::elevated_for(Duration::from_secs(60));
assert!(elevated.is_elevated());Sourcepub fn is_elevated(&self) -> bool
pub fn is_elevated(&self) -> bool
Returns true if currently elevated (and not expired).
§Example
use orcs_auth::PrivilegeLevel;
use std::time::Duration;
let standard = PrivilegeLevel::Standard;
assert!(!standard.is_elevated());
let elevated = PrivilegeLevel::elevated_for(Duration::from_secs(60));
assert!(elevated.is_elevated());Sourcepub fn is_standard(&self) -> bool
pub fn is_standard(&self) -> bool
Returns true if this is Standard mode or elevation has expired.
Sourcepub fn remaining(&self) -> Option<Duration>
pub fn remaining(&self) -> Option<Duration>
Returns the remaining elevation time, or None if not elevated.
§Example
use orcs_auth::PrivilegeLevel;
use std::time::Duration;
let elevated = PrivilegeLevel::elevated_for(Duration::from_secs(60));
let remaining = elevated.remaining();
assert!(remaining.is_some());
assert!(remaining.expect("elevated has remaining") <= Duration::from_secs(60));Trait Implementations§
Source§impl Clone for PrivilegeLevel
impl Clone for PrivilegeLevel
Source§fn clone(&self) -> PrivilegeLevel
fn clone(&self) -> PrivilegeLevel
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 PrivilegeLevel
impl Debug for PrivilegeLevel
Source§impl Default for PrivilegeLevel
impl Default for PrivilegeLevel
Source§fn default() -> PrivilegeLevel
fn default() -> PrivilegeLevel
Auto Trait Implementations§
impl Freeze for PrivilegeLevel
impl RefUnwindSafe for PrivilegeLevel
impl Send for PrivilegeLevel
impl Sync for PrivilegeLevel
impl Unpin for PrivilegeLevel
impl UnsafeUnpin for PrivilegeLevel
impl UnwindSafe for PrivilegeLevel
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more