Compare commits
2 commits
60913995a2
...
29d2cfd37a
| Author | SHA1 | Date | |
|---|---|---|---|
| 29d2cfd37a | |||
| bed56cd52a |
5 changed files with 60 additions and 9 deletions
|
|
@ -22,7 +22,11 @@ this file is the curated, human-readable summary.
|
|||
- `phoebus-mcp`: Implemented standard JSON-RPC 2.0 error handling for malformed JSON frames (error code `-32700`, Parse Error) and missing/invalid tool params (error code `-32602`, Invalid Params), preventing server silent aborts or broken agent pipes.
|
||||
4. Agent Containment Jail Hardening:
|
||||
- `phoebus-executor::agent_jail`: Sanitized `extra_masked_subdirs` to reject directory traversal components (`..`) and leading slashes. Enabled mock/recording runner testability when `bwrap` is not present on the build host.
|
||||
Gates: `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo test --workspace` (all passed: 54 adversarial tests, 39 CLI tests, 9 flaw tests, 4 MCP tests, 5 desktop config tests, 3 agent jail tests, 4 AI e2e tests).
|
||||
5. Btrfs Swapfile Hardening:
|
||||
- `phoebus-executor::storage`: Ensured `chattr +C` (NOCOW) is executed on the parent `@swap` directory and on the empty 0-byte file prior to truncation, avoiding Btrfs `EINVAL` on allocated extents. Enforced secure mode `0600` permissions on the swapfile.
|
||||
6. Inter-Process Lock Drop Verification:
|
||||
- `phoebus-executor::system_lock`: Validated lockfile PID ownership before unlinking on drop, guaranteeing that a dropping handle never unlinks a lock acquired by another process.
|
||||
Gates: `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo test --workspace` (all passed: 54 adversarial tests, 39 CLI tests, 9 flaw tests, 4 MCP tests, 5 desktop config tests, 3 agent jail tests, 4 AI e2e tests, 4 storage tests, 2 system lock tests).
|
||||
|
||||
- **System stability & reliability hardening: Advisory Mutation Lock, Atomic Transactions, System Health & Context-Aware Guidance (2026-09-30).**
|
||||
Hardened system operations against race conditions, database drift, and usability friction:
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ commit it. It should be short and current; use `git log` for detail.
|
|||
4. Structured TOML serialization for MangoWM keybindings to prevent syntax breakage from unescaped quotes in actions.
|
||||
5. JSON-RPC 2.0 error conformance for `phoebus-mcp` (handling parse errors and missing params with proper error frames).
|
||||
6. Sanitized Bubblewrap `agent_jail` paths to filter out directory traversal (`..`) attacks.
|
||||
7. Btrfs swapfile hardening: executed `chattr +C` on directory and on 0-byte file prior to truncation, avoiding Btrfs extent errors; enforced mode `0600`.
|
||||
8. Inter-process lock drop safety: verified PID ownership prior to unlinking lockfile on drop.
|
||||
Quality gates: `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo test --workspace` all passed cleanly with 0 warnings and 0 errors.
|
||||
|
||||
- **System stability & reliability hardening (2026-09-30, IMPLEMENTED + TESTED):**
|
||||
|
|
|
|||
|
|
@ -394,10 +394,12 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
/// Save, set, and restore PHOEBUS_AI_TIMEOUT around a check. Only this
|
||||
/// module's tests touch the variable, and no other test asserts a
|
||||
/// timeout value, so parallel execution stays deterministic.
|
||||
static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
|
||||
/// Save, set, and restore PHOEBUS_AI_TIMEOUT around a check.
|
||||
/// Serialized via ENV_LOCK to keep parallel test execution deterministic.
|
||||
fn with_ai_timeout(var: Option<&str>, check: impl FnOnce()) {
|
||||
let _guard = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let prev = std::env::var("PHOEBUS_AI_TIMEOUT").ok();
|
||||
match var {
|
||||
Some(v) => std::env::set_var("PHOEBUS_AI_TIMEOUT", v),
|
||||
|
|
|
|||
|
|
@ -371,6 +371,12 @@ pub fn create_swapfile(
|
|||
_root_source: &str,
|
||||
) -> Result<()> {
|
||||
let swapdir = root.ensure_dir("swap")?;
|
||||
// Ensure the swap directory itself has +C (NOCOW) so created files inherit it.
|
||||
let _ = exec.run(
|
||||
CommandSpec::new("storage_prepare", "disable CoW on swap directory", "chattr")
|
||||
.arg("+C")
|
||||
.arg(swapdir.to_string_lossy().to_string()),
|
||||
);
|
||||
let swapfile = swapdir.join("swapfile");
|
||||
let size_mib = swap_size_mib(exec);
|
||||
let spec = CommandSpec::new("storage_prepare", "create Btrfs swapfile", "btrfs")
|
||||
|
|
@ -382,17 +388,29 @@ pub fn create_swapfile(
|
|||
])
|
||||
.arg(swapfile.to_string_lossy().to_string());
|
||||
if exec.run(spec).is_ok() {
|
||||
let _ = exec.run(
|
||||
CommandSpec::new("storage_prepare", "secure swapfile permissions", "chmod")
|
||||
.arg("0600")
|
||||
.arg(swapfile.to_string_lossy().to_string()),
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
// Fallback for older btrfs-progs.
|
||||
// Fallback for older btrfs-progs:
|
||||
// Create empty 0-byte file first, set +C (NOCOW), then truncate, chmod 0600, and mkswap.
|
||||
let _ = std::fs::File::create(&swapfile);
|
||||
let _ = exec.run(
|
||||
CommandSpec::new("storage_prepare", "disable CoW on swapfile", "chattr")
|
||||
.arg("+C")
|
||||
.arg(swapfile.to_string_lossy().to_string()),
|
||||
);
|
||||
exec.run(
|
||||
CommandSpec::new("storage_prepare", "create swapfile container", "truncate")
|
||||
.args(["-s", &format!("{size_mib}M")])
|
||||
.arg(swapfile.to_string_lossy().to_string()),
|
||||
)?;
|
||||
exec.run(
|
||||
CommandSpec::new("storage_prepare", "disable CoW on swapfile", "chattr")
|
||||
.arg("+C")
|
||||
CommandSpec::new("storage_prepare", "secure swapfile permissions", "chmod")
|
||||
.arg("0600")
|
||||
.arg(swapfile.to_string_lossy().to_string()),
|
||||
)?;
|
||||
exec.run(
|
||||
|
|
@ -567,4 +585,25 @@ mod tests {
|
|||
let crypttab = std::fs::read_to_string(exec.root.join("etc/crypttab")).unwrap();
|
||||
assert!(crypttab.contains("cryptroot UUID=1111-2222 none luks,discard"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn swapfile_creation_secures_permissions_and_nocow() {
|
||||
let runner = RecordingRunner::new();
|
||||
let exec = make_exec(runner.clone());
|
||||
let cfg = InstallConfig::default();
|
||||
let root = exec.target();
|
||||
|
||||
create_swapfile(&exec, &cfg, &root, "/dev/mapper/cryptroot").unwrap();
|
||||
let recorded = runner.recorded();
|
||||
|
||||
// Verify chattr +C was run on the swap directory
|
||||
assert!(recorded.iter().any(|s| s.program == "chattr"
|
||||
&& s.args.contains(&"+C".to_string())
|
||||
&& s.args.iter().any(|a| a.contains("swap"))));
|
||||
|
||||
// Verify chmod 0600 was run on the swapfile
|
||||
assert!(recorded.iter().any(|s| s.program == "chmod"
|
||||
&& s.args.contains(&"0600".to_string())
|
||||
&& s.args.iter().any(|a| a.contains("swapfile"))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,8 +162,12 @@ impl SystemLock {
|
|||
|
||||
impl Drop for SystemLock {
|
||||
fn drop(&mut self) {
|
||||
if self.lock_path.exists() {
|
||||
let _ = fs::remove_file(&self.lock_path);
|
||||
if let Ok(content) = fs::read_to_string(&self.lock_path) {
|
||||
if let Some(info) = LockInfo::parse(&content) {
|
||||
if info.pid == std::process::id() {
|
||||
let _ = fs::remove_file(&self.lock_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue