Files
tessera/crates/tessera-hub/src/main.rs
Adnan Zahir 54abd02250 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>
2026-11-14 14:06:18 +07:00

109 lines
3.9 KiB
Rust

mod admin;
mod auth;
mod api;
mod db;
mod limits;
mod mtls;
mod oidc;
mod scheduler;
mod state;
mod upload;
use anyhow::Result;
use state::HubState;
use std::net::SocketAddr;
use tracing_subscriber::EnvFilter;
#[tokio::main]
async fn main() -> Result<()> {
if std::env::args().nth(1).as_deref() == Some("--hash-operator-password") {
return admin::print_operator_hash();
}
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env().add_directive("tessera_hub=info".parse()?))
.init();
let data_dir = std::env::var("TESSERA_DATA_DIR").unwrap_or_else(|_| "./data".into());
let listen = std::env::var("TESSERA_LISTEN").unwrap_or_else(|_| "127.0.0.1:8787".into());
let addr: SocketAddr = listen.parse()?;
let admin = admin::AdminGate::from_env()?;
admin.validate_listener(addr)?;
let wormhole = mtls::from_env()?;
if let Some(config) = &wormhole {
admin.validate_listener(config.listen)?;
}
let vault_pass = std::env::var("TESSERA_VAULT_PASSPHRASE")
.ok()
.filter(|value| !value.is_empty())
.ok_or_else(|| {
anyhow::anyhow!(
"TESSERA_VAULT_PASSPHRASE is required and must be non-empty. Tessera does not ship a default passphrase."
)
})?;
if vault_pass == "dev-vault-key" {
tracing::warn!(
"TESSERA_VAULT_PASSPHRASE is the old published example. New vaults refuse it; set a private passphrase."
);
}
let mut state = HubState::bootstrap(&data_dir, &vault_pass).await?;
anyhow::ensure!(state.sessions.enabled() || state.admin.token_active() || state.admin.local_development,
"configure a named emergency operator and/or TESSERA_ADMIN_TOKEN; anonymous local access requires explicit TESSERA_LOCAL_DEVELOPMENT=true");
if std::env::var("TESSERA_SEED_DEMO")
.map(|v| v == "1" || v == "true")
.unwrap_or(false)
{
match tessera_demo::apply(std::path::Path::new(&data_dir), &vault_pass, false) {
Ok(r) if !r.skipped => {
tracing::warn!(
"TESSERA_SEED_DEMO wrote demo backup history into {}: {} orbits, {} snapshots",
data_dir,
r.orbits,
r.snapshots
);
let vault_path = std::path::Path::new(&data_dir).join("vault");
let vault = tessera_store::Vault::open(&vault_path, &vault_pass)?;
*state.vault.write().await = vault;
}
Ok(r) => tracing::info!("demo seed skipped (already applied, {} orbits)", r.orbits),
Err(e) => tracing::warn!("demo seed failed: {e}"),
}
}
state.configure_offsite()?;
state.reconcile_capture_catalog().await?;
state.start_offsite_worker();
scheduler::start_orbit_scheduler(state.clone()).await?;
if state.sessions.enabled() {
tracing::info!("operator sessions enabled; CLI access uses a separate admin token");
} else {
state.admin.log_policy();
}
if let Some(wormhole) = wormhole {
state.wormhole_mtls = true;
state.accept_plain_upload = false;
let mut tls_state = state.clone();
tls_state.accept_plain_upload = true;
let listen_addr = wormhole.listen;
let tls_app = api::router(tls_state);
tokio::spawn(async move {
if let Err(error) = mtls::serve(wormhole, tls_app).await {
tracing::error!("wormhole mTLS stopped: {error:#}");
}
});
tracing::info!("plain HTTP uploads are closed; wormhole clients use {listen_addr}");
}
let app = api::router(state);
tracing::info!("Tessera hub listening on {addr}");
let listener = tokio::net::TcpListener::bind(addr).await?;
axum::serve(
listener,
app.into_make_service_with_connect_info::<SocketAddr>(),
)
.await?;
Ok(())
}