feat: store Outpost credentials as digests and rate limit public endpoints (auth M4)
Credentials - pairing codes and Outpost upload tokens are stored only as SHA-256 digests; the token is minted at claim (256-bit OsRng) and returned once - the old clear-text wormhole_tokens table is migrated in place and dropped with secure_delete; active tokens keep working with a fresh lifetime - admin rotate (with grace window) and revoke endpoints, audited; a revoked Outpost is refused on its next request - optional end date for the shared admin token (TESSERA_ADMIN_TOKEN_EXPIRES) Limits - governor per-source limits for emergency login, pairing claim and SSO start/callback; X-Forwarded-For only from TESSERA_TRUSTED_PROXIES; IPv6 by /64 - at most two concurrent Argon2 verifications, refused immediately when busy - denials audited at most once a minute per source - the mTLS listener now supplies the peer address to handlers Existing hubs: rotate every Outpost token after upgrading; old database copies still contain the clear-text tokens. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ mod restore;
|
||||
mod audit;
|
||||
pub mod sessions;
|
||||
pub(crate) mod oidc_login;
|
||||
pub(crate) mod credentials;
|
||||
pub(crate) use restore::restore_target_mismatch;
|
||||
|
||||
use anyhow::Result;
|
||||
@@ -75,14 +76,6 @@ impl Db {
|
||||
total INTEGER,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS wormhole_tokens (
|
||||
token TEXT PRIMARY KEY,
|
||||
outpost_id TEXT NOT NULL,
|
||||
code TEXT NOT NULL,
|
||||
state TEXT NOT NULL,
|
||||
expires_at TEXT NOT NULL,
|
||||
outpost_name TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS upload_ranges (
|
||||
session_id TEXT NOT NULL,
|
||||
start_off INTEGER NOT NULL,
|
||||
@@ -98,11 +91,7 @@ impl Db {
|
||||
)?;
|
||||
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'",
|
||||
[],
|
||||
)?;
|
||||
credentials::migrate(&conn)?;
|
||||
jobs::migrate(&conn)?;
|
||||
restore::migrate(&conn)?;
|
||||
audit::migrate(&conn)?;
|
||||
@@ -256,49 +245,6 @@ impl Db {
|
||||
)?)
|
||||
}
|
||||
|
||||
pub fn insert_wormhole_token(
|
||||
&self,
|
||||
token: &str,
|
||||
outpost_id: &str,
|
||||
code: &str,
|
||||
expires_at: &str,
|
||||
) -> Result<()> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO wormhole_tokens (token, outpost_id, code, state, expires_at) VALUES (?1, ?2, ?3, 'code_shown', ?4)",
|
||||
params![token, outpost_id, code, expires_at],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn claim_wormhole_code(
|
||||
&self,
|
||||
code: &str,
|
||||
outpost_name: &str,
|
||||
now: &str,
|
||||
) -> Result<Option<(String, String)>> {
|
||||
let mut conn = self.conn.lock().unwrap();
|
||||
let tx = conn.transaction()?;
|
||||
let claimed: Option<(String, String)> = tx.query_row(
|
||||
"UPDATE wormhole_tokens SET state = 'active', outpost_name = ?2
|
||||
WHERE token = (SELECT token FROM wormhole_tokens
|
||||
WHERE code = ?1 AND state = 'code_shown' AND expires_at > ?3
|
||||
ORDER BY expires_at DESC LIMIT 1)
|
||||
RETURNING token, outpost_id",
|
||||
params![code, outpost_name, now],
|
||||
|row| Ok((row.get(0)?, row.get(1)?)),
|
||||
).optional()?;
|
||||
if let Some((_, outpost)) = &claimed {
|
||||
tx.execute(
|
||||
"INSERT INTO outposts(id, name, last_seen, pairing_state) VALUES (?1, ?2, ?3, 'active')
|
||||
ON CONFLICT(id) DO UPDATE SET name = excluded.name, last_seen = excluded.last_seen, pairing_state = 'active'",
|
||||
params![outpost, outpost_name, now],
|
||||
)?;
|
||||
}
|
||||
tx.commit()?;
|
||||
Ok(claimed)
|
||||
}
|
||||
|
||||
pub fn list_outposts(&self) -> Result<Vec<OutpostSummary>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let mut stmt = conn.prepare("SELECT id, name, last_seen, pairing_state FROM outposts ORDER BY name, id")?;
|
||||
@@ -321,14 +267,6 @@ impl Db {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn upload_token_outpost(&self, token: &str) -> Result<Option<String>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
Ok(conn.query_row(
|
||||
"SELECT outpost_id FROM wormhole_tokens WHERE token = ?1 AND state = 'active' LIMIT 1",
|
||||
params![token], |row| row.get(0),
|
||||
).optional()?)
|
||||
}
|
||||
|
||||
pub fn upload_session(&self, id: &str) -> Result<Option<UploadSession>> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
let mut stmt = conn.prepare(
|
||||
|
||||
Reference in New Issue
Block a user