fix(ai): refuse proposals that weaken required settings
Deterministic review now rejects encryption=none, filesystem=ext4 and the aggressive kernel profile, so the LUKS2/Btrfs/stability posture cannot be traded for convenience. A live provider that returns an invalid proposal is reported and the installer continues with the proven defaults (the explicit --ai-proposal-file test path still fails loudly).
This commit is contained in:
parent
b120c1e5e4
commit
c6665e550a
2 changed files with 57 additions and 6 deletions
|
|
@ -321,9 +321,29 @@ impl ReviewOutcome {
|
|||
}
|
||||
}
|
||||
|
||||
/// Validate a proposal with mandatory evidence, reject conflicts, and apply it
|
||||
/// atomically (fail closed). This is the path a guided install uses; the model
|
||||
/// never reaches the executor without passing it.
|
||||
/// Changes that would weaken a required, non-negotiable setting.
|
||||
///
|
||||
/// Phoebus is a LUKS2 + Btrfs system; aggressive kernel profiles are
|
||||
/// speculative. The model may propose these, but a deterministic check refuses
|
||||
/// them so the proven security posture is never traded for convenience.
|
||||
fn fixed_policy_violation(change: &ProposedChange) -> Option<String> {
|
||||
match change {
|
||||
ProposedChange::SetEncryption {
|
||||
value: Encryption::None,
|
||||
} => Some("encryption must remain LUKS2".into()),
|
||||
ProposedChange::SetFilesystem {
|
||||
value: Filesystem::Ext4,
|
||||
} => Some("the filesystem must remain Btrfs".into()),
|
||||
ProposedChange::SetKernelProfile {
|
||||
value: KernelProfile::Aggressive,
|
||||
} => Some("aggressive kernel profiles are not accepted".into()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Validate a proposal with mandatory evidence, reject conflicts and unsafe
|
||||
/// changes, and apply it atomically (fail closed). This is the path a guided
|
||||
/// install uses; the model never reaches the executor without passing it.
|
||||
pub fn review(config: &mut InstallConfig, proposal: &AiProposal) -> Result<ReviewOutcome, AiError> {
|
||||
if proposal.version != 1 {
|
||||
return Err(AiError::UnsupportedVersion(proposal.version));
|
||||
|
|
@ -355,6 +375,12 @@ pub fn review(config: &mut InstallConfig, proposal: &AiProposal) -> Result<Revie
|
|||
|
||||
// Validate everything; a single failure rejects the whole proposal.
|
||||
for change in &proposal.changes {
|
||||
if let Some(reason) = fixed_policy_violation(change) {
|
||||
return Err(AiError::Rejected(format!(
|
||||
"{}: {reason}",
|
||||
change.action_name()
|
||||
)));
|
||||
}
|
||||
change.validate().map_err(AiError::Rejected)?;
|
||||
reason_for(change)?;
|
||||
}
|
||||
|
|
@ -524,6 +550,29 @@ mod tests {
|
|||
assert!(config.packages.package_use.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn review_refuses_to_weaken_required_settings() {
|
||||
for (action, value) in [
|
||||
("set_encryption", "none"),
|
||||
("set_filesystem", "ext4"),
|
||||
("set_kernel_profile", "aggressive"),
|
||||
] {
|
||||
let text = format!(
|
||||
r#"{{"version":1,"changes":[{{"action":"{action}","value":"{value}"}}],"rationale":[{{"action":"{action}","reason":"x"}}]}}"#
|
||||
);
|
||||
let proposal = parse_proposal(&text).unwrap();
|
||||
let mut config = InstallConfig::default();
|
||||
assert!(
|
||||
matches!(review(&mut config, &proposal), Err(AiError::Rejected(_))),
|
||||
"{action}={value} must be refused"
|
||||
);
|
||||
// The proven defaults are untouched.
|
||||
assert_eq!(config.encryption.mode, Encryption::Luks2);
|
||||
assert_eq!(config.storage.filesystem, Filesystem::Btrfs);
|
||||
assert_eq!(config.kernel.profile, KernelProfile::Optimized);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn review_requires_a_supported_version() {
|
||||
let proposal = parse_proposal(r#"{"version":1,"changes":[]}"#).unwrap();
|
||||
|
|
|
|||
|
|
@ -188,14 +188,16 @@ fn run_ai_guidance(
|
|||
let api_key = phoebus_executor::ai::load_api_key(key_path)?;
|
||||
let model = cli.ai_model.clone().unwrap_or_default();
|
||||
let transport = phoebus_executor::ai::CurlTransport::new(&installer.exec, api_key);
|
||||
let outcome = phoebus_installer::ai_guide::generate_and_review(
|
||||
match phoebus_installer::ai_guide::generate_and_review(
|
||||
&mut installer.config,
|
||||
&facts,
|
||||
provider,
|
||||
&model,
|
||||
&transport,
|
||||
)?;
|
||||
println!("{}", outcome.render());
|
||||
) {
|
||||
Ok(outcome) => println!("{}", outcome.render()),
|
||||
Err(e) => eprintln!("AI proposal rejected; continuing with the proven defaults: {e}"),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue