- the download format follows the file's first bytes and manifest hints: plain SQL -> .sql.gz, tar -> .tar.gz, SQLite -> .sqlite.gz, hub filesystem archive -> .tessera-fs.gz, unknown -> .dump.gz; pg_dump -Fc stays .dump; gzip/zstd/xz/bzip2/zip pass through - gzip is streamed (async-compression) in 64 KiB frames; no Content-Encoding, no Content-Length on compressed bodies, application/gzip, nosniff, no-store; HEAD is 405 - order: authenticate, find, permission, then admission (export slots and free disk), so a caller without permission cannot use up the slots - the export directory, the slot and the audit end-of-download row live with the response body: finished, client disconnect, and a sweep of tessera-export-* at start after a crash - audit export.requested / ready / finished / disconnected Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
187 lines
5.9 KiB
Rust
187 lines
5.9 KiB
Rust
//! Server-derived identities and payload-free audit records.
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum Principal {
|
|
Emergency(String),
|
|
/// OIDC user, by stable `users.id` (never by a name supplied by the IdP).
|
|
Oidc(String),
|
|
Service(&'static str),
|
|
Outpost(Uuid),
|
|
Anonymous,
|
|
LocalDevelopment,
|
|
}
|
|
|
|
impl Principal {
|
|
pub fn fields(&self) -> (String, &'static str, &'static str) {
|
|
match self {
|
|
Self::Emergency(name) => (format!("emergency:{name}"), "user", "password"),
|
|
Self::Oidc(id) => (format!("oidc:{id}"), "user", "oidc"),
|
|
Self::Service(id) => (id.to_string(), "service", "api_token"),
|
|
Self::Outpost(id) => (id.to_string(), "outpost", "outpost_token"),
|
|
Self::Anonymous => ("anonymous".into(), "anonymous", "none"),
|
|
Self::LocalDevelopment => ("local-development".into(), "service", "development"),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub enum AuditAction {
|
|
Authentication,
|
|
Authorization,
|
|
Login,
|
|
Logout,
|
|
OutpostBind,
|
|
OutpostPair,
|
|
CredentialRotate,
|
|
CredentialRevoke,
|
|
GrantCreate,
|
|
GrantDelete,
|
|
UserState,
|
|
SessionsRevoke,
|
|
ExportRequested,
|
|
ExportReady,
|
|
ExportFinished,
|
|
ExportDisconnected,
|
|
}
|
|
|
|
impl AuditAction {
|
|
pub fn as_str(&self) -> &'static str {
|
|
match self {
|
|
Self::Authentication => "authentication.check",
|
|
Self::Authorization => "authorization.check",
|
|
Self::Login => "auth.login",
|
|
Self::Logout => "auth.logout",
|
|
Self::OutpostBind => "orbit.outpost_bind",
|
|
Self::OutpostPair => "outpost.pair",
|
|
Self::CredentialRotate => "outpost.credential_rotate",
|
|
Self::CredentialRevoke => "outpost.credential_revoke",
|
|
Self::GrantCreate => "access.grant_create",
|
|
Self::GrantDelete => "access.grant_delete",
|
|
Self::UserState => "access.user_state",
|
|
Self::SessionsRevoke => "access.sessions_revoke",
|
|
Self::ExportRequested => "export.requested",
|
|
Self::ExportReady => "export.ready",
|
|
Self::ExportFinished => "export.finished",
|
|
Self::ExportDisconnected => "export.disconnected",
|
|
}
|
|
}
|
|
}
|
|
|
|
pub enum AuditOutcome {
|
|
Allowed,
|
|
Denied,
|
|
Succeeded,
|
|
Failed,
|
|
}
|
|
|
|
impl AuditOutcome {
|
|
pub fn as_str(&self) -> &'static str {
|
|
match self {
|
|
Self::Allowed => "allowed",
|
|
Self::Denied => "denied",
|
|
Self::Succeeded => "succeeded",
|
|
Self::Failed => "failed",
|
|
}
|
|
}
|
|
}
|
|
|
|
pub enum AuditResource {
|
|
Api,
|
|
Session,
|
|
Orbit(Uuid),
|
|
Outpost(Uuid),
|
|
UploadSession(Uuid),
|
|
Grant(Uuid),
|
|
User(Uuid),
|
|
Snapshot(Uuid),
|
|
}
|
|
|
|
impl AuditResource {
|
|
pub fn fields(&self) -> (&'static str, Option<String>) {
|
|
match self {
|
|
Self::Api => ("api", None),
|
|
Self::Session => ("session", None),
|
|
Self::Orbit(id) => ("orbit", Some(id.to_string())),
|
|
Self::Outpost(id) => ("outpost", Some(id.to_string())),
|
|
Self::UploadSession(id) => ("upload_session", Some(id.to_string())),
|
|
Self::Grant(id) => ("grant", Some(id.to_string())),
|
|
Self::User(id) => ("user", Some(id.to_string())),
|
|
Self::Snapshot(id) => ("snapshot", Some(id.to_string())),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// What a signed-in user may do. Only the first four can be granted to a
|
|
/// non-administrator; everything else belongs to the configured administrators
|
|
/// (SSO admin mapping, the emergency operator, the legacy admin token). Names are
|
|
/// matched exactly, never by prefix.
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
|
pub enum Permission {
|
|
OrbitRead,
|
|
SnapshotRead,
|
|
CaptureRun,
|
|
SnapshotDownload,
|
|
OrbitManage,
|
|
OutpostManage,
|
|
RetentionManage,
|
|
SnapshotDelete,
|
|
RecoveryManage,
|
|
AccessManage,
|
|
}
|
|
|
|
impl Permission {
|
|
pub fn as_str(self) -> &'static str {
|
|
match self {
|
|
Self::OrbitRead => "orbit.read",
|
|
Self::SnapshotRead => "snapshot.read",
|
|
Self::CaptureRun => "capture.run",
|
|
Self::SnapshotDownload => "snapshot.download",
|
|
Self::OrbitManage => "orbit.manage",
|
|
Self::OutpostManage => "outpost.manage",
|
|
Self::RetentionManage => "retention.manage",
|
|
Self::SnapshotDelete => "snapshot.delete",
|
|
Self::RecoveryManage => "recovery.manage",
|
|
Self::AccessManage => "access.manage",
|
|
}
|
|
}
|
|
|
|
pub fn parse(text: &str) -> Option<Self> {
|
|
[
|
|
Self::OrbitRead, Self::SnapshotRead, Self::CaptureRun, Self::SnapshotDownload, Self::OrbitManage,
|
|
Self::OutpostManage, Self::RetentionManage, Self::SnapshotDelete, Self::RecoveryManage, Self::AccessManage,
|
|
]
|
|
.into_iter()
|
|
.find(|permission| permission.as_str() == text)
|
|
}
|
|
|
|
/// May be given to a non-administrator through a grant.
|
|
pub fn grantable(self) -> bool {
|
|
matches!(self, Self::OrbitRead | Self::SnapshotRead | Self::CaptureRun | Self::SnapshotDownload)
|
|
}
|
|
}
|
|
|
|
/// Named bundles that expand into individual grants. Every bundle includes
|
|
/// `orbit.read`: without it a resource is invisible and answers 404.
|
|
pub fn role(name: &str) -> Option<&'static [Permission]> {
|
|
use Permission::*;
|
|
match name {
|
|
"viewer" => Some(&[OrbitRead, SnapshotRead]),
|
|
"capturer" => Some(&[OrbitRead, SnapshotRead, CaptureRun]),
|
|
"downloader" => Some(&[OrbitRead, SnapshotRead, SnapshotDownload]),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
pub const ROLE_NAMES: [&str; 3] = ["viewer", "capturer", "downloader"];
|
|
|
|
/// Who is asking, as far as authorization is concerned.
|
|
#[derive(Clone, Debug)]
|
|
pub struct Subject {
|
|
/// `users.id` for signed-in users; `None` for the legacy token and local development.
|
|
pub user_id: Option<String>,
|
|
/// Groups verified at sign-in. Changes at the IdP apply at the next sign-in.
|
|
pub groups: Vec<String>,
|
|
/// Configured administrator: holds every permission everywhere.
|
|
pub admin: bool,
|
|
}
|