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:
2026-11-14 14:06:18 +07:00
parent 618681fa7f
commit 54abd02250
22 changed files with 1376 additions and 164 deletions

View File

@@ -78,7 +78,7 @@ pub async fn serve(mtls: WormholeMtls, app: Router) -> Result<()> {
mtls.listen
);
loop {
let (tcp, _) = listener.accept().await.context("accept wormhole mTLS")?;
let (tcp, peer) = listener.accept().await.context("accept wormhole mTLS")?;
let acceptor = acceptor.clone();
let app = app.clone();
tokio::spawn(async move {
@@ -86,7 +86,7 @@ pub async fn serve(mtls: WormholeMtls, app: Router) -> Result<()> {
return;
};
let io = TokioIo::new(tls);
let service = TowerToHyperService::new(HyperApp(app));
let service = TowerToHyperService::new(HyperApp(app, peer));
let _ = hyper::server::conn::http1::Builder::new()
.serve_connection(io, service)
.await;
@@ -95,7 +95,7 @@ pub async fn serve(mtls: WormholeMtls, app: Router) -> Result<()> {
}
#[derive(Clone)]
struct HyperApp(Router);
struct HyperApp(Router, SocketAddr);
impl Service<Request<Incoming>> for HyperApp {
type Response = Response;
@@ -108,9 +108,13 @@ impl Service<Request<Incoming>> for HyperApp {
fn call(&mut self, request: Request<Incoming>) -> Self::Future {
let app = self.0.clone();
let mut request = request.map(Body::new);
// The TLS listener has no `into_make_service_with_connect_info`; supply the peer here
// so handlers that rate limit by source see the real address.
request.extensions_mut().insert(axum::extract::ConnectInfo(self.1));
Box::pin(async move {
Ok(app
.oneshot(request.map(Body::new))
.oneshot(request)
.await
.unwrap_or_else(|error| match error {}))
})
@@ -138,3 +142,78 @@ pub fn load_ca(path: &Path) -> Result<RootCertStore> {
}
Ok(roots)
}
#[cfg(test)]
mod tests {
use super::*;
use rcgen::{BasicConstraints, CertificateParams, DnType, ExtendedKeyUsagePurpose, IsCa, KeyPair};
/// Agents reach pairing and upload routes over mTLS. Those handlers rate limit
/// by source, which needs the peer address; this proves it is supplied on that
/// listener (without it every agent request would fail in the extractor).
#[tokio::test]
async fn agent_requests_over_mtls_carry_their_peer_address() {
let ca_key = KeyPair::generate().unwrap();
let mut ca_params = CertificateParams::new(vec![]).unwrap();
ca_params.is_ca = IsCa::Ca(BasicConstraints::Unconstrained);
ca_params.distinguished_name.push(DnType::CommonName, "tessera-test-ca");
let ca = ca_params.self_signed(&ca_key).unwrap();
let server_key = KeyPair::generate().unwrap();
let server = CertificateParams::new(vec!["localhost".into()]).unwrap().signed_by(&server_key, &ca, &ca_key).unwrap();
let client_key = KeyPair::generate().unwrap();
let mut client_params = CertificateParams::new(vec!["agent".into()]).unwrap();
client_params.extended_key_usages = vec![ExtendedKeyUsagePurpose::ClientAuth];
let client = client_params.signed_by(&client_key, &ca, &ca_key).unwrap();
let dir = tempfile::tempdir().unwrap();
let write = |name: &str, pem: String| {
let path = dir.path().join(name);
std::fs::write(&path, pem).unwrap();
path
};
let port = {
let probe = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
probe.local_addr().unwrap().port()
};
let mtls = WormholeMtls {
listen: SocketAddr::from(([127, 0, 0, 1], port)),
cert: load_certs(&write("server.pem", server.pem())).unwrap(),
key: load_key(&write("server.key", server_key.serialize_pem())).unwrap(),
client_ca: load_ca(&write("ca.pem", ca.pem())).unwrap(),
};
let mut state = crate::state::HubState::bootstrap(dir.path().join("hub").to_str().unwrap(), "synthetic-vault").await.unwrap();
state.admin.token = Some("synthetic-admin".into());
tokio::spawn(mtls_serve(mtls, crate::api::router(state)));
let identity = openidconnect::reqwest::Identity::from_pem(format!("{}{}", client.pem(), client_key.serialize_pem()).as_bytes()).unwrap();
let trusted = openidconnect::reqwest::Certificate::from_pem(ca.pem().as_bytes()).unwrap();
let with_cert = openidconnect::reqwest::Client::builder()
.add_root_certificate(trusted.clone())
.identity(identity)
.build()
.unwrap();
// `pairing` requires `ConnectInfo<SocketAddr>` (no fallback), so a 200 proves the peer is supplied.
let url = format!("https://localhost:{port}/api/v1/wormhole/pairing");
let body = serde_json::json!({});
let mut answer = None;
for _ in 0..50 {
match with_cert.post(&url).header("x-tessera-admin-token", "synthetic-admin").header("content-type", "application/json").body(body.to_string()).send().await {
Ok(response) => {
answer = Some(response.status().as_u16());
break;
}
Err(_) => tokio::time::sleep(std::time::Duration::from_millis(100)).await,
}
}
assert_eq!(answer, Some(200), "a handler that requires ConnectInfo ran, so the peer address was supplied");
// without a client certificate the TLS handshake itself is refused
let anonymous = openidconnect::reqwest::Client::builder().add_root_certificate(trusted).build().unwrap();
assert!(anonymous.post(&url).header("x-tessera-admin-token", "synthetic-admin").header("content-type", "application/json").body(body.to_string()).send().await.is_err());
}
fn mtls_serve(mtls: WormholeMtls, app: Router) -> impl Future<Output = ()> {
async move {
let _ = serve(mtls, app).await;
}
}
}