WIP: Manage packages through PackageKit over D-Bus #3

Closed
laurent wants to merge 0 commits from plan/apt-management into main
Owner

Summary

Adds a package-management surface to gilfoyle, backed by PackageKit
(org.freedesktop.PackageKit) over in-process D-Bus — the same mechanism already used
for systemd. PackageKit is addressed over a channel gilfoyle already uses, so this adds
no privileged binary, no std::process::Command and no unsafe, and polkit stays
the authority.

The hard constraint is respected: gilfoyle never installs or removes a package.

Tools

Tool Arguments Effect
list_packages name_contains?, limit? list installed packages and versions (read-only)
list_updates min_severity?, limit? list available updates (read-only)
preview_upgrade — simulate an upgrade and report the plan (read-only)
refresh_package_cache force? (default true) refresh metadata, i.e. apt update
upgrade_packages — apply upgrades, i.e. apt upgrade

Never install, never remove — by construction

  • The operation vocabulary is a closed enum with only Refresh and Upgrade; there
    is no Install/Remove variant, so [packagekit] allow = ["install"] fails the
    config load
    .
  • UpdatePackages always carries ONLY_TRUSTED; PURGE, ALLOW_REINSTALL and
    ALLOW_DOWNGRADE are never set.
  • upgrade_packages runs a SIMULATE transaction first (PackageKit authorises it
    without polkit). If the plan would install, remove, obsolete or downgrade a package it
    is refused, unless the operator sets allow_transitive_changes = true.
  • Untrusted packages (missing signature, signing key required, EULA) are always refused;
    gilfoyle never answers InstallSignature or AcceptEula.
  • The generated polkit rule explicitly denies the install/uninstall/signing-key
    actions for the gilfoyle user.

Configuration

[packagekit]
allow = []                        # subset of ["refresh", "upgrade"]; empty = default-deny
allow_transitive_changes = false
poll_timeout_seconds = 600
default_limit = 200

Authority stays out of process: gilfoyle packagekit polkit-rule renders a rule for
/etc/polkit-1/rules.d/49-gilfoyle-packagekit.rules (same shape as the systemd rule),
and gilfoyle warns at startup when it is missing or out of sync.

Crates

  • gilfoyle-core: package domain types, the closed operation vocabulary, the
    PackageManager/PackageAdmin ports, a pure transaction collector, and
    PackageService (allowlist + transitive-change gate).
  • gilfoyle-packagekit (new): zbus adapter for the PackageKit 1.x dialect, signal-driven
    transactions on a single stream, bus-name detection, LazyPackagekit.
  • gilfoyle-server: the five MCP tools, [packagekit] config and the polkit rule.

Dialect

Released PackageKit (1.2–1.4) uses org.freedesktop.PackageKit and the classic
enumeration values; the unreleased 2.x renamed the bus and re-ordered the enums (they
are sent as 1 << index bitfields). Gilfoyle decodes signals by member name (so both the
singular Package and batched Packages shapes work) but targets the 1.x wire values and
refuses 2.x with a clear error rather than mis-decoding. See ADR 0007.

Tests

  • Pure core tests (35) including the collector, filters, mapping and the service gate.
  • An in-process mock PackageKit bus (peer-to-peer socket pair) covering list/update/
    plan/apply/refresh, untrusted, error codes, failed exit, timeout→Cancel, missing
    authorisation and unsupported version.
  • Server config and polkit-rule tests; HTTP integration tests for the new tools.
  • New fuzz target package_id.

cargo fmt --check, cargo clippy -D warnings and cargo test --workspace pass locally.
The 100% mutation gate passes (cargo-mutants: 362 caught / 138 unviable / 0 missed), and the fuzzers ran clean (20 000 runs per target).

Notes / trade-offs

  • Dependency cost: PackageKit and its backend must be installed on the host; on a
    minimal host the package tools report a clear "PackageKit is unavailable" error. This
    trades a binary we would control for a daemon we do not.
  • The README documents the new config, tools and polkit step, and adds ADRs
    0005-packagekit-over-dbus, 0006-no-install-by-construction and
    0007-packagekit-bus-negotiation.
## Summary Adds a package-management surface to gilfoyle, backed by **PackageKit** (`org.freedesktop.PackageKit`) over in-process D-Bus — the same mechanism already used for systemd. PackageKit is addressed over a channel gilfoyle already uses, so this adds **no privileged binary, no `std::process::Command` and no `unsafe`**, and polkit stays the authority. The hard constraint is respected: gilfoyle **never installs or removes a package**. ## Tools | Tool | Arguments | Effect | |---|---|---| | `list_packages` | `name_contains?`, `limit?` | list installed packages and versions (read-only) | | `list_updates` | `min_severity?`, `limit?` | list available updates (read-only) | | `preview_upgrade` | — | simulate an upgrade and report the plan (read-only) | | `refresh_package_cache` | `force?` (default `true`) | refresh metadata, i.e. `apt update` | | `upgrade_packages` | — | apply upgrades, i.e. `apt upgrade` | ## Never install, never remove — by construction - The operation vocabulary is a **closed enum** with only `Refresh` and `Upgrade`; there is no `Install`/`Remove` variant, so `[packagekit] allow = ["install"]` **fails the config load**. - `UpdatePackages` always carries `ONLY_TRUSTED`; `PURGE`, `ALLOW_REINSTALL` and `ALLOW_DOWNGRADE` are never set. - `upgrade_packages` runs a **SIMULATE** transaction first (PackageKit authorises it without polkit). If the plan would install, remove, obsolete or downgrade a package it is refused, unless the operator sets `allow_transitive_changes = true`. - Untrusted packages (missing signature, signing key required, EULA) are always refused; gilfoyle never answers `InstallSignature` or `AcceptEula`. - The generated polkit rule explicitly **denies** the install/uninstall/signing-key actions for the gilfoyle user. ## Configuration ```toml [packagekit] allow = [] # subset of ["refresh", "upgrade"]; empty = default-deny allow_transitive_changes = false poll_timeout_seconds = 600 default_limit = 200 ``` Authority stays out of process: `gilfoyle packagekit polkit-rule` renders a rule for `/etc/polkit-1/rules.d/49-gilfoyle-packagekit.rules` (same shape as the systemd rule), and gilfoyle warns at startup when it is missing or out of sync. ## Crates - `gilfoyle-core`: package domain types, the closed operation vocabulary, the `PackageManager`/`PackageAdmin` ports, a pure transaction collector, and `PackageService` (allowlist + transitive-change gate). - `gilfoyle-packagekit` (new): zbus adapter for the PackageKit 1.x dialect, signal-driven transactions on a single stream, bus-name detection, `LazyPackagekit`. - `gilfoyle-server`: the five MCP tools, `[packagekit]` config and the polkit rule. ## Dialect Released PackageKit (1.2–1.4) uses `org.freedesktop.PackageKit` and the classic enumeration values; the unreleased 2.x renamed the bus and **re-ordered the enums** (they are sent as `1 << index` bitfields). Gilfoyle decodes signals by member name (so both the singular `Package` and batched `Packages` shapes work) but targets the 1.x wire values and **refuses 2.x with a clear error** rather than mis-decoding. See ADR 0007. ## Tests - Pure core tests (35) including the collector, filters, mapping and the service gate. - An **in-process mock PackageKit bus** (peer-to-peer socket pair) covering list/update/ plan/apply/refresh, untrusted, error codes, failed exit, timeout→Cancel, missing authorisation and unsupported version. - Server config and polkit-rule tests; HTTP integration tests for the new tools. - New fuzz target `package_id`. `cargo fmt --check`, `cargo clippy -D warnings` and `cargo test --workspace` pass locally. The **100% mutation gate passes** (`cargo-mutants`: 362 caught / 138 unviable / 0 missed), and the fuzzers ran clean (20 000 runs per target). ## Notes / trade-offs - **Dependency cost:** PackageKit and its backend must be installed on the host; on a minimal host the package tools report a clear "PackageKit is unavailable" error. This trades a binary we would control for a daemon we do not. - The README documents the new config, tools and polkit step, and adds ADRs `0005-packagekit-over-dbus`, `0006-no-install-by-construction` and `0007-packagekit-bus-negotiation`.
Add a package surface backed by PackageKit (org.freedesktop.PackageKit) over
in-process D-Bus, exactly like systemd: no new privileged binary, no
std::process::Command, polkit stays the authority.

- gilfoyle-core: package domain types, a closed operation vocabulary
  (refresh/upgrade only), the PackageManager/PackageAdmin ports, a pure
  transaction collector and PackageService with the transitive-change gate.
- gilfoyle-packagekit: zbus adapter for the 1.x dialect, signal-driven
  transactions, bus-name detection, in-process mock-bus tests.
- gilfoyle-server: five MCP tools (list_packages, list_updates,
  preview_upgrade, refresh_package_cache, upgrade_packages), a [packagekit]
  config section and a generated polkit rule (gilfoyle packagekit polkit-rule)
  that explicitly refuses install/remove/signing-key actions.
- docs: README, GLOSSARY, ADR 0005/0006/0007; fuzz target package_id.

Never installs or removes a package: closed vocabulary, ONLY_TRUSTED on every
update, and a SIMULATE gate that refuses plans which would install, remove,
obsolete or downgrade unless the operator opts in.
The first mutant run left 73 survivors, then 4; all are now caught:

- cover every `info`/`exit`/severity/to-name arm and the error mappings
- assert non-truncation (`total == len`) at every truncation site, and the
  truncated case, so `>` cannot become `>=`
- assert the strongest restart wins, `is_finished` before/after, runtime
- rewrite equivalent operators (is_transitive `||`, update_flags `+`, restart
  `.max`) so no viable mutant is left
- extract the lock-retry policy into `retry_delays` and test it; exercise
  retry-then-succeed, retry-budget-exhausted, untrusted, EULA and restart
  through the mock bus
- add a lazy-delegation test and `mcp` unit tests

`cargo mutants` now reports 362 caught / 138 unviable / 0 missed (100%).
main replaced the HTTP transport with an embedded SSH server and added a
multi-node client (six crates). Conflict resolution:

- take main's architecture for the server (config over SSH, per-key tool
  grants, serve.rs, tests/tools.rs) and re-apply the package additions:
  [packagekit] config, the ten-tool list, the package polkit rule and its
  startup warning, the packages driving port in serve.rs.
- drop the HTTP-era files main deleted (server/src/http.rs,
  server/tests/integration.rs); the package tool tests now live in
  server/tests/tools.rs.
- add the package read tools to gilfoyle-client's READ_TOOLS so they fan out.
- renumber the package ADRs to 0007/0008/0009 (0005/0006 are the SSH transport
  and key authentication).
- merge GLOSSARY (Packages + Trust) and README (package tools + polkit),
  refresh docs/INSTALL.md.
- README: split Requirements into build vs run; list the old runtime
  dependencies (systemd, polkitd) and the new ones (PackageKit + a backend,
  the D-Bus surfaces, the `ring` C crypto backend); document the package tools,
  the package polkit rule and a `make package-release` step.
- docs/INSTALL.md: add PackageKit to prerequisites, the `[packagekit]` config,
  the package polkit rule and the touched-files table; rewrite the install
  agent prompt so it asks each choice (mode, bind, keys, managed units, package
  operations, tool grants) instead of assuming one.
- AGENTS.md: seven crates, package invariants, mock buses, ADR 0007-0009.
- scripts/package-release.sh + `make package-release`; ignore dist/.
- version 0.3.0.
laurent closed this pull request 2026-11-09 07:31:09 +01:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
laurent/gilfoyle!3
No description provided.