feat: require authentication and own uploads per Outpost (auth M0)
- auth is mandatory by default, including loopback and local proxies; startup refuses a hub with no credentials; TESSERA_LOCAL_DEVELOPMENT is explicit and loopback-only - legacy uploads are bound to an owning Outpost (PUT /api/v1/orbits/:id/outpost); unowned orbits and sessions fail closed - typed Principal and payload-free audit_events table - endpoint authorization contract with tests comparing it to the router - A00 compatibility spike (tests/auth-compat) and library research - archive the superseded A00-A25 plan Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
mod jobs;
|
||||
mod restore;
|
||||
mod audit;
|
||||
pub(crate) use restore::restore_target_mismatch;
|
||||
|
||||
use anyhow::Result;
|
||||
@@ -94,6 +95,7 @@ impl Db {
|
||||
"INTEGER NOT NULL DEFAULT 0",
|
||||
)?;
|
||||
ensure_column(&conn, "orbits", "retention", "TEXT")?;
|
||||
ensure_column(&conn, "orbits", "outpost_id", "TEXT REFERENCES outposts(id)")?;
|
||||
conn.execute(
|
||||
"INSERT OR IGNORE INTO outposts(id, name, pairing_state)
|
||||
SELECT outpost_id, outpost_name, 'active' FROM wormhole_tokens WHERE state = 'active'",
|
||||
@@ -101,6 +103,7 @@ impl Db {
|
||||
)?;
|
||||
jobs::migrate(&conn)?;
|
||||
restore::migrate(&conn)?;
|
||||
audit::migrate(&conn)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -217,16 +220,38 @@ impl Db {
|
||||
&self,
|
||||
id: &str,
|
||||
orbit_id: &str,
|
||||
outpost_id: Uuid,
|
||||
total: Option<i64>,
|
||||
) -> Result<()> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO upload_sessions (id, orbit_id, offset, total, sealed, created_at) VALUES (?1, ?2, 0, ?3, 0, datetime('now'))",
|
||||
params![id, orbit_id, total],
|
||||
let inserted = conn.execute(
|
||||
"INSERT INTO upload_sessions (id, orbit_id, outpost_id, offset, total, sealed, created_at)
|
||||
SELECT ?1, id, ?3, 0, ?4, 0, datetime('now') FROM orbits
|
||||
WHERE id = ?2 AND outpost_id = ?3 AND provider = 'wormhole' AND dry_run = 0",
|
||||
params![id, orbit_id, outpost_id.to_string(), total],
|
||||
)?;
|
||||
anyhow::ensure!(inserted == 1, "Outpost assignment changed during upload initialization");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn bind_legacy_outpost(&self, orbit: Uuid, outpost: Uuid) -> Result<bool> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
Ok(conn.execute(
|
||||
"UPDATE orbits SET outpost_id=?2 WHERE id=?1 AND provider='wormhole' AND dry_run=0
|
||||
AND NOT EXISTS (SELECT 1 FROM capture_profiles WHERE orbit_id=?1)
|
||||
AND EXISTS (SELECT 1 FROM outposts WHERE id=?2 AND pairing_state='active')",
|
||||
params![orbit.to_string(), outpost.to_string()],
|
||||
)? == 1)
|
||||
}
|
||||
|
||||
pub fn legacy_upload_owned_by(&self, orbit: Uuid, outpost: Uuid) -> Result<bool> {
|
||||
Ok(self.conn.lock().unwrap().query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM orbits WHERE id=?1 AND outpost_id=?2
|
||||
AND provider='wormhole' AND dry_run=0)",
|
||||
params![orbit.to_string(), outpost.to_string()], |row| row.get(0),
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn insert_wormhole_token(
|
||||
&self,
|
||||
token: &str,
|
||||
@@ -303,7 +328,7 @@ impl Db {
|
||||
pub fn upload_session(&self, id: &str) -> Result<Option<UploadSession>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT orbit_id, total, sealed FROM upload_sessions WHERE id = ?1",
|
||||
"SELECT orbit_id, total, sealed, outpost_id FROM upload_sessions WHERE id = ?1",
|
||||
)?;
|
||||
let mut rows = stmt.query(params![id])?;
|
||||
let Some(row) = rows.next()? else {
|
||||
@@ -316,6 +341,7 @@ impl Db {
|
||||
orbit_id: Uuid::parse_str(&orbit_id).map_err(|e| anyhow::anyhow!(e))?,
|
||||
total: total.unwrap_or(0).max(0) as u64,
|
||||
sealed: sealed != 0,
|
||||
outpost_id: row.get(3)?,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -385,6 +411,7 @@ impl Db {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UploadSession {
|
||||
pub orbit_id: Uuid,
|
||||
pub outpost_id: Option<String>,
|
||||
pub total: u64,
|
||||
pub sealed: bool,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user