mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
fix(pack): let --claim-data install without HOME and test HOME refusals
Claiming data does not depend on finding earlier-layout data, so an install that claims it no longer needs HOME. Tests cover a first launch and a first install with an unusable HOME refusing and recording no owner, and the security docs state the HOME requirement.
This commit is contained in:
parent
d3adced897
commit
af6f716823
3 changed files with 37 additions and 2 deletions
|
|
@ -485,6 +485,19 @@ mod tests {
|
||||||
assert_eq!(owner, None);
|
assert_eq!(owner, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_first_launch_without_a_usable_home_records_nothing() {
|
||||||
|
let _env = crate::tests::env_lock().blocking_lock();
|
||||||
|
let store = demo_store("no_home", true);
|
||||||
|
// SAFETY: env_lock is held; finish restores HOME.
|
||||||
|
unsafe { std::env::set_var("HOME", "relative") };
|
||||||
|
let refused = refusal(resolve(DEMO));
|
||||||
|
let owner = read_owner(&owner_record_path(&store.join("share"), DEMO)).unwrap();
|
||||||
|
finish(&store);
|
||||||
|
assert_eq!(refused.code, 500, "{}", refused.message);
|
||||||
|
assert_eq!(owner, None);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn only_the_signed_manifest_is_accepted() {
|
fn only_the_signed_manifest_is_accepted() {
|
||||||
let _env = crate::tests::env_lock().blocking_lock();
|
let _env = crate::tests::env_lock().blocking_lock();
|
||||||
|
|
|
||||||
|
|
@ -490,6 +490,10 @@ fn admit(
|
||||||
"{app_id} belongs to {existing}; this package is {owner}. Its app data stays with \
|
"{app_id} belongs to {existing}; this package is {owner}. Its app data stays with \
|
||||||
its owner, so another publisher or a development build cannot take the ID over"
|
its owner, so another publisher or a development build cannot take the ID over"
|
||||||
),
|
),
|
||||||
|
None if claim_data => {
|
||||||
|
write_owner(&record, owner)?;
|
||||||
|
Some(record)
|
||||||
|
}
|
||||||
None => {
|
None => {
|
||||||
// Data in the earlier layout counts: weft-appd moves it to the
|
// Data in the earlier layout counts: weft-appd moves it to the
|
||||||
// app's data directory when the app next launches.
|
// app's data directory when the app next launches.
|
||||||
|
|
@ -498,7 +502,7 @@ fn admit(
|
||||||
)?;
|
)?;
|
||||||
let existing = weft_ipc_types::package::existing_app_data(data_home, &home, app_id)
|
let existing = weft_ipc_types::package::existing_app_data(data_home, &home, app_id)
|
||||||
.with_context(|| format!("inspect the app data of {app_id}"))?;
|
.with_context(|| format!("inspect the app data of {app_id}"))?;
|
||||||
if let Some(data) = existing.filter(|_| !claim_data) {
|
if let Some(data) = existing {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"{} holds app data for {app_id} with no recorded owner; install with \
|
"{} holds app data for {app_id} with no recorded owner; install with \
|
||||||
--claim-data to give it to {owner}, or move it aside",
|
--claim-data to give it to {owner}, or move it aside",
|
||||||
|
|
@ -1433,6 +1437,24 @@ mod tests {
|
||||||
let _ = std::fs::remove_dir_all(&home);
|
let _ = std::fs::remove_dir_all(&home);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_first_install_without_a_usable_home_records_nothing() {
|
||||||
|
let home = temp_root("no_home");
|
||||||
|
let app_id = "org.weft.test.nohome";
|
||||||
|
write_package(&home.join("src"), app_id, "");
|
||||||
|
let store = home.join("store");
|
||||||
|
let refused = with_home(&home, || {
|
||||||
|
// SAFETY: with_home holds env_lock and restores HOME afterwards.
|
||||||
|
unsafe { std::env::set_var("HOME", "relative") };
|
||||||
|
install_package_to(&home.join("src"), &store, InstallMode::Development)
|
||||||
|
});
|
||||||
|
let message = format!("{:#}", refused.unwrap_err());
|
||||||
|
assert!(message.contains("HOME"), "{message}");
|
||||||
|
assert_eq!(owner_of(&home, app_id), None);
|
||||||
|
assert!(!store.join(app_id).exists());
|
||||||
|
let _ = std::fs::remove_dir_all(&home);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn uninstalling_one_of_two_copies_keeps_the_record() {
|
fn uninstalling_one_of_two_copies_keeps_the_record() {
|
||||||
let home = temp_root("two_copies");
|
let home = temp_root("two_copies");
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ Packages are signed with Ed25519 over their content digest: the SHA-256 of an in
|
||||||
|
|
||||||
The first installation of an app ID records its owner in `$XDG_DATA_HOME/weft/owners/<id>`: the publisher key, or development. Installations and uninstallations of one ID under one data home hold a per-ID lock, so concurrent installations cannot leave a placed package without its record. Every later installation of that ID must have the same owner, so neither another trusted publisher nor a development build can take over an ID, and with it the app's data. The record survives uninstall while the app's data remains; uninstalling with no data left frees the ID. App data with no recorded owner, as left by installations from before owner records, is given to a new owner only with `--claim-data`. A record is written under a temporary name and linked into place, so it is never partial, and a record created by an installation that then fails to place its package is removed. A record left by an installation that was killed before placing its package is released by `weft-pack uninstall <id>` once no data remains. A record is only released while no known store (the user store, the system store and `$WEFT_APP_STORE`) holds the package; a package installed into another custom store is uninstalled with that store selected. The demo key in `examples/keys` is a test fixture, not a signing authority.
|
The first installation of an app ID records its owner in `$XDG_DATA_HOME/weft/owners/<id>`: the publisher key, or development. Installations and uninstallations of one ID under one data home hold a per-ID lock, so concurrent installations cannot leave a placed package without its record. Every later installation of that ID must have the same owner, so neither another trusted publisher nor a development build can take over an ID, and with it the app's data. The record survives uninstall while the app's data remains; uninstalling with no data left frees the ID. App data with no recorded owner, as left by installations from before owner records, is given to a new owner only with `--claim-data`. A record is written under a temporary name and linked into place, so it is never partial, and a record created by an installation that then fails to place its package is removed. A record left by an installation that was killed before placing its package is released by `weft-pack uninstall <id>` once no data remains. A record is only released while no known store (the user store, the system store and `$WEFT_APP_STORE`) holds the package; a package installed into another custom store is uninstalled with that store selected. The demo key in `examples/keys` is a test fixture, not a signing authority.
|
||||||
|
|
||||||
`weft-appd` checks every package again before a session starts. A package recorded as a publisher's runs only while that key is still trusted and its signature covers the package's current content. A package with no record runs only when a trusted key signed it, and that key is then recorded as its owner; if app data already exists for the ID without a recorded owner, in the current layout or the earlier one that is migrated at launch, the launch is refused rather than handing the data to that publisher; `weft-pack install` applies the same rule unless given `--claim-data`. The record is written before the session starts, so it remains even if that first launch then fails; `weft-pack uninstall` releases it once no data exists in either layout and no known store holds the package. Upgrading from installations made before owner records: data with no record is refused at launch until it is claimed. While an ID is recorded as development content, whatever package is found for it runs unverified, from any store. A changed package, or one whose key was removed from the trust store, is refused with code 403; a damaged trust store or owner record is a host error, 500. The manifest is read once and its bytes must be the ones in the verified inventory, so a session's capabilities and entries come from the signed manifest. The module and UI files are read again when the session starts, so a directory install changed by its owning user after the check, or while the session runs, is not detected; verified images are not writable.
|
`weft-appd` checks every package again before a session starts. A package recorded as a publisher's runs only while that key is still trusted and its signature covers the package's current content. A package with no record runs only when a trusted key signed it, and that key is then recorded as its owner; if app data already exists for the ID without a recorded owner, in the current layout or the earlier one that is migrated at launch, the launch is refused rather than handing the data to that publisher; `weft-pack install` applies the same rule unless given `--claim-data`. The record is written before the session starts, so it remains even if that first launch then fails; `weft-pack uninstall` releases it once no data exists in either layout and no known store holds the package. Finding earlier-layout data needs `HOME`: without an absolute `HOME`, a first launch is refused (500), a first install fails unless it claims the data, and uninstall keeps the record. While an ID is recorded as development content, whatever package is found for it runs unverified, from any store. A changed package, or one whose key was removed from the trust store, is refused with code 403; a damaged trust store or owner record is a host error, 500. The manifest is read once and its bytes must be the ones in the verified inventory, so a session's capabilities and entries come from the signed manifest. The module and UI files are read again when the session starts, so a directory install changed by its owning user after the check, or while the session runs, is not detected; verified images are not writable.
|
||||||
|
|
||||||
Not yet covered: key rotation and ownership transfer have no workflow, and removing a key is the only revocation; and capabilities are granted at launch without asking the user, independently of the signature.
|
Not yet covered: key rotation and ownership transfer have no workflow, and removing a key is the only revocation; and capabilities are granted at launch without asking the user, independently of the signature.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue