mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
fix(pack): approve the package weft-appd launches, and drop approvals no longer declared
weft-pack approve read only the user store, so an app in the system store, or installed as a verified image, could not be approved. The remedy the launch refusal named also did not work. approve now resolves the package in weft-appd's store order. It also accepts the capabilities by name, which is how an image is approved, since weft-pack cannot read its manifest. An install or rollback without --approve now drops approvals for capabilities the package no longer declares. A capability declared again later therefore asks again. Both commands report what still needs approval. weft-appd validates capabilities without side effects first, then refuses unapproved ones, then derives grants, so an unsupported capability is reported as such and not as one needing approval. The docs state that approvals are per user.
This commit is contained in:
parent
3186e524ab
commit
9b83625778
5 changed files with 131 additions and 26 deletions
|
|
@ -87,14 +87,9 @@ impl HostDirs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Derives grants for the declared capabilities. Every capability is
|
/// Parses the declared capabilities, refusing unknown ones and those this
|
||||||
/// checked before host directories are resolved or the app's data
|
/// host does not support, without touching the host.
|
||||||
/// directory is created, so a refused launch leaves nothing behind.
|
pub(crate) fn validate(declared: &[String]) -> Result<Vec<Capability>, Refusal> {
|
||||||
pub(crate) fn derive(
|
|
||||||
app_id: &str,
|
|
||||||
declared: &[String],
|
|
||||||
host_dirs: impl FnOnce() -> Result<HostDirs, Refusal>,
|
|
||||||
) -> Result<SessionGrants, Refusal> {
|
|
||||||
let mut capabilities = Vec::new();
|
let mut capabilities = Vec::new();
|
||||||
for text in declared {
|
for text in declared {
|
||||||
let capability: Capability =
|
let capability: Capability =
|
||||||
|
|
@ -110,7 +105,18 @@ pub(crate) fn derive(
|
||||||
}
|
}
|
||||||
capabilities.push(capability);
|
capabilities.push(capability);
|
||||||
}
|
}
|
||||||
|
Ok(capabilities)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Derives grants for the declared capabilities. Every capability is
|
||||||
|
/// checked before host directories are resolved or the app's data
|
||||||
|
/// directory is created, so a refused launch leaves nothing behind.
|
||||||
|
pub(crate) fn derive(
|
||||||
|
app_id: &str,
|
||||||
|
declared: &[String],
|
||||||
|
host_dirs: impl FnOnce() -> Result<HostDirs, Refusal>,
|
||||||
|
) -> Result<SessionGrants, Refusal> {
|
||||||
|
let capabilities = validate(declared)?;
|
||||||
let mut grants = SessionGrants::default();
|
let mut grants = SessionGrants::default();
|
||||||
let needs_dirs = capabilities
|
let needs_dirs = capabilities
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
||||||
|
|
@ -609,6 +609,9 @@ async fn resolve_launch(
|
||||||
) -> Result<(launch::LaunchPackage, grants::SessionGrants), grants::Refusal> {
|
) -> Result<(launch::LaunchPackage, grants::SessionGrants), grants::Refusal> {
|
||||||
tokio::task::spawn_blocking(move || {
|
tokio::task::spawn_blocking(move || {
|
||||||
let package = launch::resolve(&app_id)?;
|
let package = launch::resolve(&app_id)?;
|
||||||
|
// Unknown and unsupported capabilities are refused as such, then
|
||||||
|
// unapproved ones, before anything is prepared on the host.
|
||||||
|
grants::validate(&package.capabilities)?;
|
||||||
check_approval(&app_id, &package.capabilities)?;
|
check_approval(&app_id, &package.capabilities)?;
|
||||||
let grants = grants::derive(&app_id, &package.capabilities, grants::HostDirs::from_env)?;
|
let grants = grants::derive(&app_id, &package.capabilities, grants::HostDirs::from_env)?;
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,10 @@ fn main() -> anyhow::Result<()> {
|
||||||
uninstall_package(app_id)?;
|
uninstall_package(app_id)?;
|
||||||
}
|
}
|
||||||
Some("approve") => {
|
Some("approve") => {
|
||||||
let app_id = args.get(2).context("usage: weft-pack approve <app_id>")?;
|
let app_id = args
|
||||||
approve_package(&resolve_install_root()?, app_id)?;
|
.get(2)
|
||||||
|
.context("usage: weft-pack approve <app_id> [<capability>...]")?;
|
||||||
|
approve_package(app_id, &args[3..])?;
|
||||||
}
|
}
|
||||||
Some("rollback") => {
|
Some("rollback") => {
|
||||||
let app_id = args.get(2).context("usage: weft-pack rollback <app_id>")?;
|
let app_id = args.get(2).context("usage: weft-pack rollback <app_id>")?;
|
||||||
|
|
@ -135,7 +137,7 @@ fn main() -> anyhow::Result<()> {
|
||||||
eprintln!(" weft-pack uninstall <app_id> remove installed package");
|
eprintln!(" weft-pack uninstall <app_id> remove installed package");
|
||||||
eprintln!(" weft-pack rollback <app_id> activate the previous revision");
|
eprintln!(" weft-pack rollback <app_id> activate the previous revision");
|
||||||
eprintln!(
|
eprintln!(
|
||||||
" weft-pack approve <app_id> approve the app's declared capabilities"
|
" weft-pack approve <app_id> [<cap>...] approve its declared or listed capabilities"
|
||||||
);
|
);
|
||||||
eprintln!(" weft-pack list list installed packages");
|
eprintln!(" weft-pack list list installed packages");
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
|
@ -511,6 +513,18 @@ fn settle_approval(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let approved = read_approved(&record).with_context(|| format!("read {}", record.display()))?;
|
let approved = read_approved(&record).with_context(|| format!("read {}", record.display()))?;
|
||||||
|
// An approval covers what the installed package declares: a capability
|
||||||
|
// it no longer declares is dropped, so declaring it again later asks
|
||||||
|
// again.
|
||||||
|
let kept: Vec<String> = declared
|
||||||
|
.iter()
|
||||||
|
.filter(|c| approved.contains(*c))
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
if kept.len() != approved.len() {
|
||||||
|
write_approved(&record, &kept)
|
||||||
|
.with_context(|| format!("update the approval of {app_id}"))?;
|
||||||
|
}
|
||||||
let pending = unapproved(declared, &approved);
|
let pending = unapproved(declared, &approved);
|
||||||
if !pending.is_empty() {
|
if !pending.is_empty() {
|
||||||
println!(
|
println!(
|
||||||
|
|
@ -521,8 +535,13 @@ fn settle_approval(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Approves the capabilities the active package of `app_id` declares.
|
/// Approves capabilities for `app_id`: those listed in `explicit`, or
|
||||||
fn approve_package(store_root: &Path, app_id: &str) -> anyhow::Result<()> {
|
/// without a list, those its installed package declares. The package is the
|
||||||
|
/// one weft-appd launches: the first store, in weft-appd's order, holding
|
||||||
|
/// the app. A verified image, whose manifest weft-pack cannot read, needs
|
||||||
|
/// the explicit list.
|
||||||
|
fn approve_package(app_id: &str, explicit: &[String]) -> anyhow::Result<()> {
|
||||||
|
use weft_ipc_types::approval::needs_approval;
|
||||||
anyhow::ensure!(
|
anyhow::ensure!(
|
||||||
weft_ipc_types::package::is_valid_app_id(app_id),
|
weft_ipc_types::package::is_valid_app_id(app_id),
|
||||||
"'{app_id}' is not a valid app ID"
|
"'{app_id}' is not a valid app ID"
|
||||||
|
|
@ -530,23 +549,49 @@ fn approve_package(store_root: &Path, app_id: &str) -> 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 found = active(store_root, app_id)?
|
if !explicit.is_empty() {
|
||||||
.with_context(|| format!("{app_id} is not installed in {}", store_root.display()))?;
|
for capability in explicit {
|
||||||
|
capability
|
||||||
|
.parse::<weft_ipc_types::capability::Capability>()
|
||||||
|
.map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
|
anyhow::ensure!(needs_approval(capability), "{capability} needs no approval");
|
||||||
|
}
|
||||||
|
return settle_approval(&data_home, app_id, explicit, true);
|
||||||
|
}
|
||||||
|
let roots = list_installed_roots();
|
||||||
|
if roots
|
||||||
|
.iter()
|
||||||
|
.any(|root| ImageFiles::in_store(root, app_id).any_present())
|
||||||
|
{
|
||||||
|
anyhow::bail!(
|
||||||
|
"{app_id} is installed as a verified image, whose capabilities weft-pack cannot \
|
||||||
|
read; approve them by name: weft-pack approve {app_id} <capability>..."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let found = roots
|
||||||
|
.iter()
|
||||||
|
.find_map(|root| match active(root, app_id) {
|
||||||
|
Ok(Some(found))
|
||||||
|
if found
|
||||||
|
.dir()
|
||||||
|
.join(weft_ipc_types::manifest::MANIFEST_FILE)
|
||||||
|
.is_file() =>
|
||||||
|
{
|
||||||
|
Some(found)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.with_context(|| format!("{app_id} is not installed"))?;
|
||||||
let manifest = load_manifest(found.dir())?;
|
let manifest = load_manifest(found.dir())?;
|
||||||
anyhow::ensure!(
|
anyhow::ensure!(
|
||||||
manifest.package.id == app_id,
|
manifest.package.id == app_id,
|
||||||
"{} declares another app ID",
|
"{} declares another app ID",
|
||||||
found.dir().display()
|
found.dir().display()
|
||||||
);
|
);
|
||||||
settle_approval(&data_home, app_id, manifest.capabilities(), true)?;
|
if !manifest.capabilities().iter().any(|c| needs_approval(c)) {
|
||||||
if !manifest
|
|
||||||
.capabilities()
|
|
||||||
.iter()
|
|
||||||
.any(|c| weft_ipc_types::approval::needs_approval(c))
|
|
||||||
{
|
|
||||||
println!("{app_id} declares nothing that needs approval");
|
println!("{app_id} declares nothing that needs approval");
|
||||||
}
|
}
|
||||||
Ok(())
|
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`.
|
||||||
|
|
@ -937,7 +982,8 @@ fn rollback_package(store_root: &Path, app_id: &str) -> anyhow::Result<()> {
|
||||||
activate(store_root, app_id, &previous)?;
|
activate(store_root, app_id, &previous)?;
|
||||||
collect(store_root, app_id);
|
collect(store_root, app_id);
|
||||||
println!("rolled {app_id} back to revision {}", &previous[..12]);
|
println!("rolled {app_id} back to revision {}", &previous[..12]);
|
||||||
Ok(())
|
let manifest = load_manifest(&dir)?;
|
||||||
|
settle_approval(&data_home, app_id, manifest.capabilities(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Establishes who owns the app ID of a checked, staged package:
|
/// Establishes who owns the app ID of a checked, staged package:
|
||||||
|
|
@ -1556,6 +1602,22 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Runs `f` with WEFT_APP_STORE set to `store`. Callers run it inside
|
||||||
|
/// `with_home`, which holds env_lock.
|
||||||
|
fn with_store<T>(store: &Path, f: impl FnOnce() -> T) -> T {
|
||||||
|
let prior = std::env::var_os("WEFT_APP_STORE");
|
||||||
|
// SAFETY: the caller holds env_lock through with_home.
|
||||||
|
unsafe { std::env::set_var("WEFT_APP_STORE", store) };
|
||||||
|
let result = f();
|
||||||
|
unsafe {
|
||||||
|
match prior {
|
||||||
|
Some(v) => std::env::set_var("WEFT_APP_STORE", v),
|
||||||
|
None => std::env::remove_var("WEFT_APP_STORE"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
/// Runs `f` with HOME set to `home` and XDG_DATA_HOME to `home/share`.
|
/// Runs `f` with HOME set to `home` and XDG_DATA_HOME to `home/share`.
|
||||||
fn with_home<T>(home: &Path, f: impl FnOnce() -> T) -> T {
|
fn with_home<T>(home: &Path, f: impl FnOnce() -> T) -> T {
|
||||||
let _env = env_lock();
|
let _env = env_lock();
|
||||||
|
|
@ -2046,7 +2108,10 @@ mod tests {
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(pending(&["sys:notifications"]), ["sys:notifications"]);
|
assert_eq!(pending(&["sys:notifications"]), ["sys:notifications"]);
|
||||||
with_home(&home, || approve_package(&store, app_id)).unwrap();
|
with_home(&home, || {
|
||||||
|
with_store(&store, || approve_package(app_id, &[]))
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
assert!(pending(&["sys:notifications", "fs:rw:app-data"]).is_empty());
|
assert!(pending(&["sys:notifications", "fs:rw:app-data"]).is_empty());
|
||||||
// An update that asks for more is not approved by the earlier answer.
|
// An update that asks for more is not approved by the earlier answer.
|
||||||
write_package(
|
write_package(
|
||||||
|
|
@ -2068,6 +2133,35 @@ mod tests {
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(pending(&["sys:notifications", "sys:clipboard:read"]).is_empty());
|
assert!(pending(&["sys:notifications", "sys:clipboard:read"]).is_empty());
|
||||||
|
// A capability the package stops declaring is no longer approved.
|
||||||
|
write_package(&src, app_id, "\"sys:notifications\"");
|
||||||
|
with_home(&home, || {
|
||||||
|
install_package_to(&src, &store, InstallMode::Development)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
write_package(
|
||||||
|
&src,
|
||||||
|
app_id,
|
||||||
|
"\"sys:notifications\", \"sys:clipboard:read\"",
|
||||||
|
);
|
||||||
|
with_home(&home, || {
|
||||||
|
install_package_to(&src, &store, InstallMode::Development)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
pending(&["sys:notifications", "sys:clipboard:read"]),
|
||||||
|
["sys:clipboard:read"]
|
||||||
|
);
|
||||||
|
// Capabilities can be approved by name, and only valid ones that
|
||||||
|
// need approval.
|
||||||
|
with_home(&home, || {
|
||||||
|
approve_package(app_id, &["sys:clipboard:read".to_owned()])
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
assert!(pending(&["sys:clipboard:read"]).is_empty());
|
||||||
|
for refused in ["fs:rw:app-data", "sys:everything"] {
|
||||||
|
assert!(with_home(&home, || 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();
|
||||||
assert!(!record.exists());
|
assert!(!record.exists());
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ WASI Preview 2 + Component Model execution host (Wasmtime 30). Runs the componen
|
||||||
|
|
||||||
### weft-pack
|
### weft-pack
|
||||||
|
|
||||||
Package management CLI. Subcommands: `check` (validate wapp.toml, entries and package content), `sign` (Ed25519 signature over every file), `verify` (verify signature), `generate-key`, `install` (requires a signature by a trusted key unless `--dev`; records the app ID's owner; installs or updates, see [Installing and updating](#installing-and-updating)), `uninstall`, `rollback`, `approve` (approve the installed app's declared capabilities; `install --approve` does so at installation), `list`, `build-image` (EROFS dm-verity), `info`.
|
Package management CLI. Subcommands: `check` (validate wapp.toml, entries and package content), `sign` (Ed25519 signature over every file), `verify` (verify signature), `generate-key`, `install` (requires a signature by a trusted key unless `--dev`; records the app ID's owner; installs or updates, see [Installing and updating](#installing-and-updating)), `uninstall`, `rollback`, `approve` (approve the app's declared capabilities, or those listed; `install --approve` does so at installation), `list`, `build-image` (EROFS dm-verity), `info`.
|
||||||
|
|
||||||
### weft-file-portal
|
### weft-file-portal
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ 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, and `weft-pack approve <id>` approves those of the installed app later; without approval, `install` lists what still needs it. The approval is recorded in `$XDG_DATA_HOME/weft/approvals/<id>`, and weft-appd refuses to launch an app that declares a capability it does not hold (403, naming the capabilities). An update that declares a new capability needs approval again; an earlier approval never extends to it. Uninstalling the app forgets the approval. 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.
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
## Process Isolation
|
## Process Isolation
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue