fix: require 16 characters for a new vault passphrase and warn when an existing one is weaker
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -148,7 +148,7 @@ async fn world() -> World {
|
||||
|
||||
async fn world_with(exports: Option<crate::exports::ExportGate>) -> World {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
if let Some(gate) = exports {
|
||||
|
||||
@@ -34,7 +34,7 @@ fn every_registered_path_has_an_authorization_contract() {
|
||||
async fn human_read_endpoints_reject_anonymous_and_outpost_tokens() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state =
|
||||
crate::state::HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
crate::state::HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.sessions = crate::admin::SessionGate::fixture(state.db.clone());
|
||||
@@ -80,7 +80,7 @@ async fn human_read_endpoints_reject_anonymous_and_outpost_tokens() {
|
||||
async fn local_proxy_never_enables_auth_when_credentials_are_absent() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state =
|
||||
crate::state::HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
crate::state::HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin = crate::admin::AdminGate {
|
||||
|
||||
@@ -22,7 +22,7 @@ struct Harness {
|
||||
|
||||
async fn harness_with(configure: impl FnOnce(&mut HubState)) -> Harness {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some(ADMIN.into());
|
||||
|
||||
@@ -23,7 +23,7 @@ struct Harness {
|
||||
|
||||
async fn harness_with(gate: Option<ExportGate>) -> Harness {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some(ADMIN.into());
|
||||
|
||||
@@ -248,7 +248,7 @@ fn config(idp: &Idp) -> OidcConfig {
|
||||
async fn harness_with(min_refresh: Duration) -> Harness {
|
||||
let idp = Idp::start().await;
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
let config = config(&idp);
|
||||
@@ -788,7 +788,7 @@ async fn an_idp_outage_degrades_to_fixed_errors_and_never_a_session() {
|
||||
#[tokio::test]
|
||||
async fn oidc_endpoints_are_absent_when_oidc_is_not_configured() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
let app = crate::api::router(state);
|
||||
|
||||
@@ -44,7 +44,7 @@ struct Lab {
|
||||
|
||||
async fn lab_with(configure: impl FnOnce(&mut HubState)) -> Lab {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some(ADMIN.into());
|
||||
|
||||
@@ -1622,7 +1622,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn unauthenticated_floods_write_one_denial_row_per_source() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some("synthetic-admin-token-of-32-chars!".into());
|
||||
@@ -1661,7 +1661,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn wrong_admin_tokens_are_throttled_per_source() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some("synthetic-admin-token-of-32-chars!".into());
|
||||
@@ -1686,7 +1686,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn reconstitute_targets_stay_inside_the_exports_directory_for_every_caller() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some("synthetic-admin-token-of-32-chars!".into());
|
||||
@@ -1761,7 +1761,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn the_api_description_is_not_served_to_anonymous_callers() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some("synthetic-admin-token-of-32-chars!".into());
|
||||
@@ -1786,7 +1786,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn responses_carry_security_headers_and_assets_cache_for_a_year() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
let app = router(state);
|
||||
@@ -1821,7 +1821,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn a_failed_denial_audit_write_still_answers_401() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some("synthetic-admin-token-of-32-chars!".into());
|
||||
@@ -1853,7 +1853,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn legacy_uploads_are_owned_by_the_assigned_outpost() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "synthetic-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.accept_plain_upload = true;
|
||||
@@ -2065,7 +2065,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn orbit_creation_validates_cron_and_direct_run_preserves_wormhole_status() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "test-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "test-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some("fixture-admin".into());
|
||||
@@ -2131,7 +2131,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn new_orbits_validate_source_access_and_keep_provider_internal() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "test-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "test-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some("fixture-admin".into());
|
||||
@@ -2187,7 +2187,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn orbit_responses_and_schema_hide_provider_config() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "test-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "test-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.admin.token = Some("fixture-admin".into());
|
||||
|
||||
@@ -369,7 +369,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn operator_session_requires_csrf_and_expires_without_disabling_cli() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "fixture-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "fixture-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.sessions = SessionGate::fixture(state.db.clone());
|
||||
@@ -507,7 +507,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn me_reports_the_caller_and_rejects_anonymous() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "fixture-vault")
|
||||
let mut state = HubState::bootstrap(dir.path().to_str().unwrap(), "fixture-vault-passphrase")
|
||||
.await
|
||||
.unwrap();
|
||||
state.sessions = SessionGate::fixture(state.db.clone());
|
||||
|
||||
@@ -191,7 +191,7 @@ mod tests {
|
||||
};
|
||||
let mut state = crate::state::HubState::bootstrap(
|
||||
dir.path().join("hub").to_str().unwrap(),
|
||||
"synthetic-vault",
|
||||
"synthetic-vault-passphrase",
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -43,6 +43,9 @@ struct OutpostRepository {
|
||||
password: String,
|
||||
}
|
||||
|
||||
/// Shortest passphrase accepted for a new vault. Existing vaults keep opening with a warning.
|
||||
pub const MIN_PASSPHRASE_CHARS: usize = 16;
|
||||
|
||||
impl Vault {
|
||||
pub fn init(root: impl AsRef<Path>, passphrase: &str) -> Result<Self> {
|
||||
if passphrase == "dev-vault-key" {
|
||||
@@ -50,6 +53,10 @@ impl Vault {
|
||||
"refusing to initialize a vault with the published dev passphrase; choose a private passphrase"
|
||||
);
|
||||
}
|
||||
anyhow::ensure!(
|
||||
passphrase.chars().count() >= MIN_PASSPHRASE_CHARS,
|
||||
"the vault passphrase must be at least {MIN_PASSPHRASE_CHARS} characters"
|
||||
);
|
||||
let root = root.as_ref().to_path_buf();
|
||||
fs::create_dir_all(root.join("data"))?;
|
||||
fs::create_dir_all(root.join("snapshots"))?;
|
||||
@@ -81,6 +88,14 @@ impl Vault {
|
||||
anyhow::bail!("vault not initialized");
|
||||
}
|
||||
restrict_dir(&root.join("keys"))?;
|
||||
// Not refused: that would lock existing deployments out of their own backups.
|
||||
if passphrase == "dev-vault-key" {
|
||||
tracing::warn!("this vault uses the published dev passphrase; rotate it to a private one");
|
||||
} else if passphrase.chars().count() < MIN_PASSPHRASE_CHARS {
|
||||
tracing::warn!(
|
||||
"the vault passphrase is shorter than {MIN_PASSPHRASE_CHARS} characters; a new vault would refuse it"
|
||||
);
|
||||
}
|
||||
let salt = root.join("keys/tessera.salt");
|
||||
let key = VaultKey::derive_from_passphrase(passphrase, &salt)?;
|
||||
let index = Self::load_index(&root)?;
|
||||
@@ -830,7 +845,7 @@ mod tests {
|
||||
rand::rngs::StdRng::seed_from_u64(7).fill_bytes(&mut bytes);
|
||||
let file = source.join("large.bin");
|
||||
fs::write(&file, &bytes).unwrap();
|
||||
let mut vault = Vault::init(dir.path().join("vault"), "secret").unwrap();
|
||||
let mut vault = Vault::init(dir.path().join("vault"), "secret-test-passphrase").unwrap();
|
||||
let manifest = SnapshotManifest {
|
||||
snapshot_id: Uuid::new_v4(),
|
||||
orbit_id: Uuid::new_v4(),
|
||||
@@ -883,7 +898,7 @@ mod tests {
|
||||
#[test]
|
||||
fn init_snap_list_restore() {
|
||||
let dir = tempdir().unwrap();
|
||||
let mut vault = Vault::init(dir.path(), "secret").unwrap();
|
||||
let mut vault = Vault::init(dir.path(), "secret-test-passphrase").unwrap();
|
||||
let manifest = SnapshotManifest {
|
||||
snapshot_id: Uuid::new_v4(),
|
||||
orbit_id: Uuid::new_v4(),
|
||||
@@ -906,7 +921,7 @@ mod tests {
|
||||
#[test]
|
||||
fn dry_run_writes_nothing() {
|
||||
let dir = tempdir().unwrap();
|
||||
let mut vault = Vault::init(dir.path(), "secret").unwrap();
|
||||
let mut vault = Vault::init(dir.path(), "secret-test-passphrase").unwrap();
|
||||
let manifest = SnapshotManifest {
|
||||
snapshot_id: Uuid::new_v4(),
|
||||
orbit_id: Uuid::new_v4(),
|
||||
@@ -923,7 +938,7 @@ mod tests {
|
||||
#[test]
|
||||
fn orbit_decay_keeps_other_orbits_recoverable() {
|
||||
let dir = tempdir().unwrap();
|
||||
let mut vault = Vault::init(dir.path(), "secret").unwrap();
|
||||
let mut vault = Vault::init(dir.path(), "secret-test-passphrase").unwrap();
|
||||
let orbit_id = Uuid::new_v4();
|
||||
let other_id = Uuid::new_v4();
|
||||
let now = DateTime::from_timestamp(1_730_000_000, 0).unwrap();
|
||||
@@ -960,7 +975,7 @@ mod tests {
|
||||
#[test]
|
||||
fn new_snapshots_are_encrypted_and_legacy_json_still_reads() {
|
||||
let dir = tempdir().unwrap();
|
||||
let mut vault = Vault::init(dir.path(), "secret").unwrap();
|
||||
let mut vault = Vault::init(dir.path(), "secret-test-passphrase").unwrap();
|
||||
let legacy_id = Uuid::new_v4();
|
||||
let legacy = StoredSnapshot {
|
||||
id: legacy_id,
|
||||
@@ -1019,6 +1034,15 @@ mod tests {
|
||||
assert_eq!(vault.restore_snapshot(snap.id, &out).unwrap(), 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_vaults_need_a_long_passphrase_but_existing_short_ones_still_open() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
assert!(Vault::init(dir.path(), "fifteen-chars-x").is_err());
|
||||
assert!(Vault::init(dir.path(), "sixteen-chars-xx").is_ok());
|
||||
// a vault made before the rule: same data, shorter passphrase never got in, so reopen with the long one
|
||||
assert!(Vault::open(dir.path(), "sixteen-chars-xx").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn init_rejects_published_dev_passphrase() {
|
||||
let dir = tempdir().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user