feat: per-orbit access grants and an Access console (auth M5)
Authorization - one gate for every human endpoint: authenticate, resolve the resource, then admin_only / scoped / visible; require_admin* removed so each handler must choose - grants (user or IdP group; global or one orbit; optional end date) read live on every request; only orbit.read, snapshot.read, capture.run and snapshot.download can be granted, everything else stays with configured administrators - an orbit without orbit.read is 404, a visible one without the permission is 403, a caller with nothing to see gets 403 on lists; job history is filtered before LIMIT - jobs and audit record the stable principal id, not the IdP display name - restore targets and restore history are admin-only until self-service (M6) - sessions keep the groups verified at sign-in Administration - /api/v1/access grants and users (enable, disable, sign out everywhere), validated and audited by id; admins cannot disable themselves or the emergency operator - Access console with the shared Select and a themed DatePicker; non-administrators only see Vault and Activity and never call administrator endpoints - the Window/Radar view is stored per account (/api/v1/me/preferences) - UI tolerates older hubs and mocks (missing admin/grants) and a console that fails to render no longer blanks the app Tests: a matrix generated from the endpoint contract exercises every human route against real resources in two orbits for each kind of caller. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -176,14 +176,20 @@ impl Db {
|
||||
application: Option<Uuid>,
|
||||
status: Option<&str>,
|
||||
limit: u16,
|
||||
orbits: Option<&[String]>,
|
||||
) -> Result<Vec<CaptureJob>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
// The orbit restriction is part of the query, before LIMIT, so a restricted
|
||||
// caller still gets a full page of their own jobs.
|
||||
let mut stmt = conn.prepare(&format!(
|
||||
"{JOB_VIEW} WHERE (?1 IS NULL OR j.application_id = ?1) AND (?2 IS NULL OR j.status = ?2)
|
||||
AND (?4 IS NULL OR j.application_id IN (
|
||||
SELECT application_id FROM capture_profiles WHERE orbit_id IN (SELECT value FROM json_each(?4))))
|
||||
ORDER BY j.created_at DESC, j.rowid DESC LIMIT ?3"
|
||||
))?;
|
||||
let restriction = orbits.map(|ids| serde_json::to_string(ids)).transpose()?;
|
||||
let rows = stmt.query_map(
|
||||
params![application.map(|id| id.to_string()), status, limit],
|
||||
params![application.map(|id| id.to_string()), status, limit, restriction],
|
||||
read_job,
|
||||
)?;
|
||||
Ok(rows.collect::<rusqlite::Result<_>>()?)
|
||||
@@ -633,17 +639,17 @@ mod tests {
|
||||
}
|
||||
let tick = crate::scheduler::tick_capture_schedules;
|
||||
tick(&db, registered).unwrap();
|
||||
assert!(db.capture_jobs(None, None, 100).unwrap().is_empty());
|
||||
assert!(db.capture_jobs(None, None, 100, None).unwrap().is_empty());
|
||||
let now = Utc.with_ymd_and_hms(2026, 11, 8, 19, 5, 0).unwrap();
|
||||
tick(&db, now).unwrap();
|
||||
drop(db);
|
||||
let db = Db::connect(&path).await.unwrap();
|
||||
db.migrate().await.unwrap();
|
||||
tick(&db, now).unwrap();
|
||||
let all = db.capture_jobs(None, Some("queued"), 100).unwrap();
|
||||
let all = db.capture_jobs(None, Some("queued"), 100, None).unwrap();
|
||||
assert_eq!(all.len(), 4);
|
||||
let history = db
|
||||
.capture_jobs(Some(a.application_id), Some("queued"), 100)
|
||||
.capture_jobs(Some(a.application_id), Some("queued"), 100, None)
|
||||
.unwrap();
|
||||
assert_eq!(history.len(), 2);
|
||||
assert!(history.iter().all(|job| job.actor == "scheduler"));
|
||||
@@ -669,7 +675,7 @@ mod tests {
|
||||
.unwrap());
|
||||
}
|
||||
let failed = db
|
||||
.capture_jobs(Some(a.application_id), Some("failed"), 100)
|
||||
.capture_jobs(Some(a.application_id), Some("failed"), 100, None)
|
||||
.unwrap();
|
||||
assert_eq!(failed.len(), 1);
|
||||
let events = db.capture_events(first.job_id).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user