fix: harden the vault before release
Require a private passphrase and loopback-or-token admin auth. New vaults use Argon2id; existing PBKDF2 vaults still open, and new snapshot metadata is encrypted. Wormhole tokens survive restart, offset uploads seal into the vault, and client-certificate uploads are real. Reject the command provider and keep Postgres passwords off the process arguments. Keep the interruptible canvas motion.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
mod admin;
|
||||
mod api;
|
||||
mod db;
|
||||
mod mtls;
|
||||
mod scheduler;
|
||||
mod state;
|
||||
mod upload;
|
||||
|
||||
use anyhow::Result;
|
||||
use state::HubState;
|
||||
@@ -15,10 +18,22 @@ async fn main() -> Result<()> {
|
||||
.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(|_| "0.0.0.0:8787".into());
|
||||
let vault_pass = std::env::var("TESSERA_VAULT_PASSPHRASE").unwrap_or_else(|_| "dev-vault-key".into());
|
||||
let listen = std::env::var("TESSERA_LISTEN").unwrap_or_else(|_| "127.0.0.1:8787".into());
|
||||
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 state = HubState::bootstrap(&data_dir, &vault_pass).await?;
|
||||
let mut state = HubState::bootstrap(&data_dir, &vault_pass).await?;
|
||||
|
||||
if std::env::var("TESSERA_SEED_DEMO")
|
||||
.map(|v| v == "1" || v == "true")
|
||||
@@ -26,8 +41,9 @@ async fn main() -> Result<()> {
|
||||
{
|
||||
match tessera_demo::apply(std::path::Path::new(&data_dir), &vault_pass, false) {
|
||||
Ok(r) if !r.skipped => {
|
||||
tracing::info!(
|
||||
"demo seed: {} orbits, {} snapshots",
|
||||
tracing::warn!(
|
||||
"TESSERA_SEED_DEMO wrote demo backup history into {}: {} orbits, {} snapshots",
|
||||
data_dir,
|
||||
r.orbits,
|
||||
r.snapshots
|
||||
);
|
||||
@@ -41,11 +57,37 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
scheduler::start_orbit_scheduler(state.clone()).await?;
|
||||
state.admin.log_policy();
|
||||
|
||||
if let Some(wormhole) = mtls::from_env()? {
|
||||
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 admin_token_unset = state.admin.token.is_none();
|
||||
let app = api::router(state);
|
||||
let addr: SocketAddr = listen.parse()?;
|
||||
if addr.ip().is_unspecified() && admin_token_unset {
|
||||
tracing::warn!(
|
||||
"listening on {addr}; backup APIs reject non-loopback clients until TESSERA_ADMIN_TOKEN is set"
|
||||
);
|
||||
}
|
||||
tracing::info!("Tessera hub listening on {addr}");
|
||||
let listener = tokio::net::TcpListener::bind(addr).await?;
|
||||
axum::serve(listener, app).await?;
|
||||
axum::serve(
|
||||
listener,
|
||||
app.into_make_service_with_connect_info::<SocketAddr>(),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user