pub struct AuthService { /* private fields */ }Expand description
Centralized credential management service (Factotum pattern).
- Credentials are registered once, encrypted at rest.
- Agents request scoped tokens; raw credentials are never exposed.
- Token issuance and access are audited.
- SHA-256 hashed credentials support agent authentication.
Implementations§
Source§impl AuthService
impl AuthService
Sourcepub fn new(encryption_key: [u8; 32]) -> Self
pub fn new(encryption_key: [u8; 32]) -> Self
Create a new AuthService with the given encryption key.
Sourcepub fn new_default() -> Self
pub fn new_default() -> Self
Create with a default (zero) encryption key (testing only).
Sourcepub fn register_credential(
&self,
name: &str,
credential_type: CredentialType,
value: &[u8],
allowed_agents: Vec<String>,
) -> Result<(), KernelError>
pub fn register_credential( &self, name: &str, credential_type: CredentialType, value: &[u8], allowed_agents: Vec<String>, ) -> Result<(), KernelError>
Register a new credential.
Sourcepub fn rotate_credential(
&self,
name: &str,
new_value: &[u8],
) -> Result<(), KernelError>
pub fn rotate_credential( &self, name: &str, new_value: &[u8], ) -> Result<(), KernelError>
Update an existing credential’s value (rotation).
Sourcepub fn request_token(
&self,
request: &CredentialRequest,
) -> Result<IssuedToken, KernelError>
pub fn request_token( &self, request: &CredentialRequest, ) -> Result<IssuedToken, KernelError>
Request a scoped, time-limited token.
Sourcepub fn validate_token(&self, token_id: &str) -> Result<IssuedToken, KernelError>
pub fn validate_token(&self, token_id: &str) -> Result<IssuedToken, KernelError>
Validate an issued token. Returns Err if expired or not found.
Sourcepub fn revoke_token(&self, token_id: &str) -> bool
pub fn revoke_token(&self, token_id: &str) -> bool
Revoke an active token.
Sourcepub fn active_token_count(&self) -> usize
pub fn active_token_count(&self) -> usize
List all active (non-expired) tokens.
Sourcepub fn register_hashed_credential(
&self,
agent_id: &str,
raw_credential: &[u8],
scopes: Vec<String>,
) -> Result<(), KernelError>
pub fn register_hashed_credential( &self, agent_id: &str, raw_credential: &[u8], scopes: Vec<String>, ) -> Result<(), KernelError>
Register a hashed credential for an agent.
The raw credential is never stored; only its SHA-256 hash is kept.
Sourcepub fn authenticate(
&self,
agent_id: &str,
raw_credential: &[u8],
) -> Result<AuthToken, KernelError>
pub fn authenticate( &self, agent_id: &str, raw_credential: &[u8], ) -> Result<AuthToken, KernelError>
Authenticate an agent by verifying its raw credential against the stored hash.
On success, issues a scoped AuthToken valid for one hour.
Sourcepub fn validate_auth_token(
&self,
token_id: &str,
) -> Result<AuthToken, KernelError>
pub fn validate_auth_token( &self, token_id: &str, ) -> Result<AuthToken, KernelError>
Validate an auth token. Returns Err if expired or not found.
Sourcepub fn revoke_auth_token(&self, token_id: &str) -> bool
pub fn revoke_auth_token(&self, token_id: &str) -> bool
Revoke an auth token. Returns true if it existed.
Sourcepub fn check_scope(&self, token_id: &str, required_scope: &str) -> bool
pub fn check_scope(&self, token_id: &str, required_scope: &str) -> bool
Check whether an auth token has a specific scope.
Sourcepub fn audit_log(&self) -> Vec<AuditEntry>
pub fn audit_log(&self) -> Vec<AuditEntry>
Get the audit log.
Trait Implementations§
Source§impl SystemService for AuthService
impl SystemService for AuthService
Source§fn service_type(&self) -> ServiceType
fn service_type(&self) -> ServiceType
Source§fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = HealthStatus> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = HealthStatus> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl !Freeze for AuthService
impl !RefUnwindSafe for AuthService
impl Send for AuthService
impl Sync for AuthService
impl Unpin for AuthService
impl UnsafeUnpin for AuthService
impl UnwindSafe for AuthService
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> 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