mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
fix(pack): add approvals by name only for installed, declared capabilities
Pruning compared a list of the declared capabilities with the set of approved ones by length. A manifest repeating a capability could therefore keep an approval it no longer declared. The two are now compared as sets. weft-pack approve <id> <capability>... replaced the app's approval instead of adding to it. It also accepted any app ID and any capability, which let an approval cover a capability declared later. It now adds to the approval, requires the app to be installed, and for a package weft-pack can read, requires each listed capability to be declared. The docs state the remaining limits for verified images.
This commit is contained in:
parent
9b83625778
commit
e482fec07c
2 changed files with 63 additions and 21 deletions
|
|
@ -516,13 +516,13 @@ fn settle_approval(
|
||||||
// An approval covers what the installed package declares: a capability
|
// An approval covers what the installed package declares: a capability
|
||||||
// it no longer declares is dropped, so declaring it again later asks
|
// it no longer declares is dropped, so declaring it again later asks
|
||||||
// again.
|
// again.
|
||||||
let kept: Vec<String> = declared
|
let kept: std::collections::BTreeSet<String> = declared
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|c| approved.contains(*c))
|
.filter(|c| approved.contains(*c))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
if kept.len() != approved.len() {
|
if kept != approved {
|
||||||
write_approved(&record, &kept)
|
write_approved(&record, &kept.into_iter().collect::<Vec<_>>())
|
||||||
.with_context(|| format!("update the approval of {app_id}"))?;
|
.with_context(|| format!("update the approval of {app_id}"))?;
|
||||||
}
|
}
|
||||||
let pending = unapproved(declared, &approved);
|
let pending = unapproved(declared, &approved);
|
||||||
|
|
@ -549,6 +549,10 @@ fn approve_package(app_id: &str, explicit: &[String]) -> anyhow::Result<()> {
|
||||||
let data_home = weft_ipc_types::package::data_home()
|
let data_home = weft_ipc_types::package::data_home()
|
||||||
.context("cannot locate the data home to record the approval")?;
|
.context("cannot locate the data home to record the approval")?;
|
||||||
let _lock = weft_ipc_types::trust::lock_owner(&data_home, app_id)?;
|
let _lock = weft_ipc_types::trust::lock_owner(&data_home, app_id)?;
|
||||||
|
let roots = list_installed_roots();
|
||||||
|
let image = roots
|
||||||
|
.iter()
|
||||||
|
.any(|root| ImageFiles::in_store(root, app_id).any_present());
|
||||||
if !explicit.is_empty() {
|
if !explicit.is_empty() {
|
||||||
for capability in explicit {
|
for capability in explicit {
|
||||||
capability
|
capability
|
||||||
|
|
@ -556,26 +560,50 @@ fn approve_package(app_id: &str, explicit: &[String]) -> anyhow::Result<()> {
|
||||||
.map_err(|e| anyhow::anyhow!("{e}"))?;
|
.map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
anyhow::ensure!(needs_approval(capability), "{capability} needs no approval");
|
anyhow::ensure!(needs_approval(capability), "{capability} needs no approval");
|
||||||
}
|
}
|
||||||
return settle_approval(&data_home, app_id, explicit, true);
|
// Approvals by name add to the app's approval. They are for an
|
||||||
}
|
// installed app, and for a package weft-pack can read, only for
|
||||||
let roots = list_installed_roots();
|
// what it declares.
|
||||||
if roots
|
if !image {
|
||||||
|
let manifest = launched_manifest(&roots, app_id)?;
|
||||||
|
if let Some(undeclared) = explicit
|
||||||
.iter()
|
.iter()
|
||||||
.any(|root| ImageFiles::in_store(root, app_id).any_present())
|
.find(|c| !manifest.capabilities().contains(c))
|
||||||
{
|
{
|
||||||
|
anyhow::bail!("{app_id} does not declare {undeclared}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let record = weft_ipc_types::approval::approval_path(&data_home, app_id);
|
||||||
|
let mut approved: Vec<String> = weft_ipc_types::approval::read_approved(&record)
|
||||||
|
.with_context(|| format!("read {}", record.display()))?
|
||||||
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
approved.extend(explicit.iter().cloned());
|
||||||
|
return settle_approval(&data_home, app_id, &approved, true);
|
||||||
|
}
|
||||||
|
if image {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"{app_id} is installed as a verified image, whose capabilities weft-pack cannot \
|
"{app_id} is installed as a verified image, whose capabilities weft-pack cannot \
|
||||||
read; approve them by name: weft-pack approve {app_id} <capability>..."
|
read; approve them by name: weft-pack approve {app_id} <capability>..."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
let manifest = launched_manifest(&roots, app_id)?;
|
||||||
|
if !manifest.capabilities().iter().any(|c| needs_approval(c)) {
|
||||||
|
println!("{app_id} declares nothing that needs approval");
|
||||||
|
}
|
||||||
|
settle_approval(&data_home, app_id, manifest.capabilities(), true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The manifest of the package of `app_id` that weft-appd launches from a
|
||||||
|
/// directory or revision: the first of `roots` holding one.
|
||||||
|
fn launched_manifest(roots: &[PathBuf], app_id: &str) -> anyhow::Result<Manifest> {
|
||||||
let found = roots
|
let found = roots
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|root| match active(root, app_id) {
|
.find_map(|root| match active(root, app_id) {
|
||||||
Ok(Some(found))
|
Ok(Some(found))
|
||||||
if found
|
if std::fs::symlink_metadata(
|
||||||
.dir()
|
found.dir().join(weft_ipc_types::manifest::MANIFEST_FILE),
|
||||||
.join(weft_ipc_types::manifest::MANIFEST_FILE)
|
)
|
||||||
.is_file() =>
|
.is_ok() =>
|
||||||
{
|
{
|
||||||
Some(found)
|
Some(found)
|
||||||
}
|
}
|
||||||
|
|
@ -588,10 +616,7 @@ fn approve_package(app_id: &str, explicit: &[String]) -> anyhow::Result<()> {
|
||||||
"{} declares another app ID",
|
"{} declares another app ID",
|
||||||
found.dir().display()
|
found.dir().display()
|
||||||
);
|
);
|
||||||
if !manifest.capabilities().iter().any(|c| needs_approval(c)) {
|
Ok(manifest)
|
||||||
println!("{app_id} declares nothing that needs approval");
|
|
||||||
}
|
|
||||||
settle_approval(&data_home, app_id, manifest.capabilities(), true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The active package of `app_id` in `store_root`.
|
/// The active package of `app_id` in `store_root`.
|
||||||
|
|
@ -2155,12 +2180,29 @@ mod tests {
|
||||||
// Capabilities can be approved by name, and only valid ones that
|
// Capabilities can be approved by name, and only valid ones that
|
||||||
// need approval.
|
// need approval.
|
||||||
with_home(&home, || {
|
with_home(&home, || {
|
||||||
|
with_store(&store, || {
|
||||||
approve_package(app_id, &["sys:clipboard:read".to_owned()])
|
approve_package(app_id, &["sys:clipboard:read".to_owned()])
|
||||||
})
|
})
|
||||||
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(pending(&["sys:clipboard:read"]).is_empty());
|
// Added to what was approved before.
|
||||||
|
assert!(pending(&["sys:notifications", "sys:clipboard:read"]).is_empty());
|
||||||
|
let undeclared = with_home(&home, || {
|
||||||
|
with_store(&store, || {
|
||||||
|
approve_package(app_id, &["sys:clipboard:write".to_owned()])
|
||||||
|
})
|
||||||
|
});
|
||||||
|
assert!(
|
||||||
|
undeclared.is_err(),
|
||||||
|
"approved a capability the package does not declare"
|
||||||
|
);
|
||||||
for refused in ["fs:rw:app-data", "sys:everything"] {
|
for refused in ["fs:rw:app-data", "sys:everything"] {
|
||||||
assert!(with_home(&home, || approve_package(app_id, &[refused.to_owned()])).is_err());
|
assert!(
|
||||||
|
with_home(&home, || with_store(&store, || {
|
||||||
|
approve_package(app_id, &[refused.to_owned()])
|
||||||
|
}))
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// Uninstalling forgets the approval.
|
// Uninstalling forgets the approval.
|
||||||
with_home(&home, || uninstall_package_from(app_id, &store)).unwrap();
|
with_home(&home, || uninstall_package_from(app_id, &store)).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ WEFT OS enforces a capability-based security model. No capability is granted by
|
||||||
|
|
||||||
`weft-pack check` validates capability strings against the shared vocabulary in `weft_ipc_types::capability`. Unknown capability strings are rejected. At launch, `weft-appd` derives the session's grants from the manifest and refuses to start a package with a capability that is unknown, unsupported or unsatisfiable. `weft-runtime` enforces the grants it is given: read-only directories are preopened read-only, and each host import checks its grant on every call. See the capability table in `architecture.md`.
|
`weft-pack check` validates capability strings against the shared vocabulary in `weft_ipc_types::capability`. Unknown capability strings are rejected. At launch, `weft-appd` derives the session's grants from the manifest and refuses to start a package with a capability that is unknown, unsupported or unsatisfiable. `weft-runtime` enforces the grants it is given: read-only directories are preopened read-only, and each host import checks its grant on every call. See the capability table in `architecture.md`.
|
||||||
|
|
||||||
A package gets only the capabilities the user approved. `weft-pack install --approve` approves those the installed package declares. `weft-pack approve <id>` approves those of the package weft-appd would launch, the first store in weft-appd's order that holds the app, which also covers packages in the system store. `weft-pack approve <id> <capability>...` approves the listed capabilities, which is the only way for an app installed as a verified image, since weft-pack cannot read an image's manifest. Without approval, `install` and `rollback` list what still needs it.
|
A package gets only the capabilities the user approved. `weft-pack install --approve` approves those the installed package declares. `weft-pack approve <id>` approves those of the package weft-appd would launch, the first store in weft-appd's order that holds the app, which also covers packages in the system store. `weft-pack approve <id> <capability>...` adds the listed capabilities to the app's approval; for a package weft-pack can read they must be ones it declares. Listing them is the only way to approve an app installed as a verified image, since weft-pack cannot read an image's manifest; for the same reason, approvals for an image are not reduced when it is updated, and uninstalling a directory copy of the app removes them although the image remains. Without approval, `install` and `rollback` list what still needs it.
|
||||||
|
|
||||||
The approval is recorded per user, in `$XDG_DATA_HOME/weft/approvals/<id>`; weft-pack and weft-appd must use the same data home, as for owner records. An installation by another user, such as root installing into the system store, approves nothing for this user. weft-appd refuses to launch an app that declares a capability the record does not hold (403, naming the capabilities), after refusing unknown and unsupported capabilities and before preparing anything for the session. An approval covers what the installed package declares: an update or rollback drops approvals for capabilities the package no longer declares, so a capability declared again later, or newly, needs approval again. Uninstalling the app forgets its approval unless another store still holds the app. Approvals are keyed by app ID, not by store or publisher. Private app data (`fs:read:app-data`, `fs:rw:app-data`) is a minimal execution resource and needs no approval. Signature verification and approval are separate decisions: a trusted signature approves nothing.
|
The approval is recorded per user, in `$XDG_DATA_HOME/weft/approvals/<id>`; weft-pack and weft-appd must use the same data home, as for owner records. An installation by another user, such as root installing into the system store, approves nothing for this user. weft-appd refuses to launch an app that declares a capability the record does not hold (403, naming the capabilities), after refusing unknown and unsupported capabilities and before preparing anything for the session. An approval covers what the installed package declares: an update or rollback drops approvals for capabilities the package no longer declares, so a capability declared again later, or newly, needs approval again. Uninstalling the app forgets its approval unless another store still holds the app. Approvals are keyed by app ID, not by store or publisher. Private app data (`fs:read:app-data`, `fs:rw:app-data`) is a minimal execution resource and needs no approval. Signature verification and approval are separate decisions: a trusted signature approves nothing.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue