Provide readonly and mutating framework_tool instances with scoped sudoers #389

Closed
opened 2026-10-26 20:21:12 +00:00 by nimmo · 1 comment
Owner

Context

framework_tool is already installed on Electra from framework-system (0.6.6) and carries the thermal, fan and expansion-bay commands, but it cannot be used without root:

  • /dev/port is crw-r----- root kmem (chardev 1,4) — the portio interface used for EC access
  • no /dev/v4l/ecchars, and /sys/kernel/debug/ec/ is empty
  • unprivileged run fails: Must be root to get SMBIOS data. → Failed to find SMBIOS → Not a Framework Laptop

So every EC capability, including read-only diagnostics such as --thermal, --sensors and --expansion-bay, is currently blocked behind an interactive password. Observed 2026-10-26 on Electra while investigating background heat.

Why two instances

The upstream readonly Cargo feature is a compile-time capability guard, not a runtime flag. Because the guard is compiled in, a sudoers rule on the readonly binary does not need to enumerate safe arguments — the binary physically cannot issue a blocked command. That is the reason to use the feature rather than sudoers argument wildcards.

Deliverables

  1. A readonly build installed under a distinct name (framework-tool-ro).
  2. The normal build kept as framework-tool, with the existing nvidia feature only in the dgpu tier.
  3. Sudoers: passwordless for the ro binary, authenticated for the mutating binary.
  4. Optional: use the ro binary's --expansion-bay output as an assertion in electra-select-latest-specialisation instead of trusting operator input.

Upstream behaviour to design around (verified in the 0.6.6 source)

framework_lib/src/commandline/mod.rs replaces the parsed CLI with an explicit allow-list, then ..Default::default(). Upstream's own TODO: "Instead of silently ignoring blocked command, we should remind the user." Blocked options therefore fail silently.

Allowed in a readonly build: --thermal, --thermalget, --thermalset, --sensors, --power, --expansion-bay, --inputdeck(-mode), --pdports, --pd-info, --switches, --console, --sysinfo, --uptimeinfo, --s0ix-counter, --port80read, --panicinfo, --protoinfo, --versions, --features, --esrt, --kblight, --rgbkbd, --remap-key, --fp-led-level, --fp-brightness, --get-gpio, --intrusion, --privacy, --ps2-enable, --nvidia (when that feature is also on)

Blocked in a readonly build: --autofanctrl, --fansetduty, --fansetrpm, --charge-limit, --charge-current-limit, --charge-rate-limit, --smartbattery, --smartbattery-auth, all --flash-*, --force, --host-command, --ec-hib-delay, --tablet-mode, --touchscreen-enable, --pd-reset/disable/enable, --dp-hdmi-update, --dump-ec-flash

Consequences for the current thermal investigation:

  • --thermalset survives in the readonly build, so the "safe" binary can still write fan thresholds — it is not purely read-only.
  • --autofanctrl and --fansetduty do not survive; fan control belongs in the mutating binary.
  • --smartbattery (EC battery) and the smartmontools feature (disk SMART via libsmartmon) are unrelated despite similar names.

Upstream defect: the allow-list contains pd_info: cli.version, so in a readonly build --pd-info only fires when --version is also set.

Draft shape

# proposed: modules/hardware/framework-tool.nix
let
  base = inputs.framework-system.packages.${pkgs.system}.default;

  roPkg = base.overrideAttrs (old: {
    buildFeatures = (old.buildFeatures or [ ]) ++ [ "readonly" ];
    installPhase = ""
      runHook preInstall
      mkdir -p $out/bin
      cp target/release/framework_tool $out/bin/framework-tool-ro
      runHook postInstall
    "";
  });

  rwPkg = base.overrideAttrs (old: {
    buildFeatures = (old.buildFeatures or [ ])
      ++ lib.optionals cfg.nixosConfig.gpu.nvidia.enable [ "nvidia" ];
  });
in
{
  system.extraDependencies = [ roPkg rwPkg ];

  sudoers.extraRules = ""
    # EC diagnostics — compile-time guard, cannot write EC state
    ${cfg.nixosConfig.primaryUser} ALL=(ALL:ALL) NOPASSWD: /run/current-system/sw/bin/framework-tool-ro
    # EC changes — authenticate
    ${cfg.nixosConfig.primaryUser} ALL=(ALL:ALL) /run/current-system/sw/bin/framework-tool
  "";
}

Both still need root regardless of the difference above: the difference between them is capability and authentication, not privilege.

Completion criteria

  • nix flake check clean
  • framework-tool-ro present, and a blocked command (e.g. --fansetduty 50) is a no-op rather than a write
  • sudo -n framework-tool-ro --thermal succeeds without a password and returns fan/temperature state
  • framework-tool --thermalset ... requires authentication
  • --expansion-bay output recorded through the ro binary
  • README updated if the user-facing command surface changes
  • just test on electra passes with the new packages and sudoers

Not yet verified

  • The readonly build has not been compiled; the feature is declared in Cargo.toml but untested here.
  • smartmon and nvml-wrapper are declared in Cargo.lock, but the cargo vendor dirs are not realised in this store, so enabling smartmontools or nvidia is not confirmed to build offline.
  • No actual --thermal readings have been obtained; fan/thermal state on Electra is still unknown.

Licensing

framework-system is BSD-3-Clause. The smartmontools feature pulls in libsmartmon, GPL-2.0-or-later — a standard license with nothing unusual in it. The only consequence is that the combined binary becomes GPL-2.0-or-later, a one-way door for publishing that binary. Not a blocker here; enable only if disk SMART detail is actually wanted.

  • #378 — Framework external-module certificate generation (same host, different package)
## Context `framework_tool` is already installed on Electra from `framework-system` (0.6.6) and carries the thermal, fan and expansion-bay commands, but it cannot be used without root: - `/dev/port` is `crw-r----- root kmem` (chardev 1,4) — the portio interface used for EC access - no `/dev/v4l/ecchars`, and `/sys/kernel/debug/ec/` is empty - unprivileged run fails: `Must be root to get SMBIOS data.` → `Failed to find SMBIOS` → `Not a Framework Laptop` So every EC capability, including read-only diagnostics such as `--thermal`, `--sensors` and `--expansion-bay`, is currently blocked behind an interactive password. Observed 2026-10-26 on Electra while investigating background heat. ## Why two instances The upstream `readonly` Cargo feature is a **compile-time** capability guard, not a runtime flag. Because the guard is compiled in, a sudoers rule on the readonly binary does not need to enumerate safe arguments — the binary physically cannot issue a blocked command. That is the reason to use the feature rather than sudoers argument wildcards. ## Deliverables 1. A `readonly` build installed under a distinct name (`framework-tool-ro`). 2. The normal build kept as `framework-tool`, with the existing `nvidia` feature only in the `dgpu` tier. 3. Sudoers: passwordless for the ro binary, authenticated for the mutating binary. 4. Optional: use the ro binary's `--expansion-bay` output as an assertion in `electra-select-latest-specialisation` instead of trusting operator input. ## Upstream behaviour to design around (verified in the 0.6.6 source) `framework_lib/src/commandline/mod.rs` replaces the parsed CLI with an explicit allow-list, then `..Default::default()`. Upstream's own TODO: *"Instead of silently ignoring blocked command, we should remind the user."* Blocked options therefore **fail silently**. **Allowed in a `readonly` build:** `--thermal`, `--thermalget`, `--thermalset`, `--sensors`, `--power`, `--expansion-bay`, `--inputdeck(-mode)`, `--pdports`, `--pd-info`, `--switches`, `--console`, `--sysinfo`, `--uptimeinfo`, `--s0ix-counter`, `--port80read`, `--panicinfo`, `--protoinfo`, `--versions`, `--features`, `--esrt`, `--kblight`, `--rgbkbd`, `--remap-key`, `--fp-led-level`, `--fp-brightness`, `--get-gpio`, `--intrusion`, `--privacy`, `--ps2-enable`, `--nvidia` (when that feature is also on) **Blocked in a `readonly` build:** `--autofanctrl`, `--fansetduty`, `--fansetrpm`, `--charge-limit`, `--charge-current-limit`, `--charge-rate-limit`, `--smartbattery`, `--smartbattery-auth`, all `--flash-*`, `--force`, `--host-command`, `--ec-hib-delay`, `--tablet-mode`, `--touchscreen-enable`, `--pd-reset/disable/enable`, `--dp-hdmi-update`, `--dump-ec-flash` Consequences for the current thermal investigation: - `--thermalset` **survives** in the readonly build, so the "safe" binary can still write fan thresholds — it is not purely read-only. - `--autofanctrl` and `--fansetduty` do **not** survive; fan control belongs in the mutating binary. - `--smartbattery` (EC battery) and the `smartmontools` feature (disk SMART via libsmartmon) are unrelated despite similar names. Upstream defect: the allow-list contains `pd_info: cli.version`, so in a readonly build `--pd-info` only fires when `--version` is also set. ## Draft shape ```nix # proposed: modules/hardware/framework-tool.nix let base = inputs.framework-system.packages.${pkgs.system}.default; roPkg = base.overrideAttrs (old: { buildFeatures = (old.buildFeatures or [ ]) ++ [ "readonly" ]; installPhase = "" runHook preInstall mkdir -p $out/bin cp target/release/framework_tool $out/bin/framework-tool-ro runHook postInstall ""; }); rwPkg = base.overrideAttrs (old: { buildFeatures = (old.buildFeatures or [ ]) ++ lib.optionals cfg.nixosConfig.gpu.nvidia.enable [ "nvidia" ]; }); in { system.extraDependencies = [ roPkg rwPkg ]; sudoers.extraRules = "" # EC diagnostics — compile-time guard, cannot write EC state ${cfg.nixosConfig.primaryUser} ALL=(ALL:ALL) NOPASSWD: /run/current-system/sw/bin/framework-tool-ro # EC changes — authenticate ${cfg.nixosConfig.primaryUser} ALL=(ALL:ALL) /run/current-system/sw/bin/framework-tool ""; } ``` Both still need root regardless of the difference above: the difference between them is **capability and authentication**, not privilege. ## Completion criteria - [ ] `nix flake check` clean - [ ] `framework-tool-ro` present, and a blocked command (e.g. `--fansetduty 50`) is a no-op rather than a write - [ ] `sudo -n framework-tool-ro --thermal` succeeds without a password and returns fan/temperature state - [ ] `framework-tool --thermalset ...` requires authentication - [ ] `--expansion-bay` output recorded through the ro binary - [ ] README updated if the user-facing command surface changes - [ ] `just test` on electra passes with the new packages and sudoers ## Not yet verified - The `readonly` build has not been compiled; the feature is declared in `Cargo.toml` but untested here. - `smartmon` and `nvml-wrapper` are declared in `Cargo.lock`, but the cargo vendor dirs are not realised in this store, so enabling `smartmontools` or `nvidia` is not confirmed to build offline. - No actual `--thermal` readings have been obtained; fan/thermal state on Electra is still unknown. ## Licensing `framework-system` is BSD-3-Clause. The `smartmontools` feature pulls in libsmartmon, `GPL-2.0-or-later` — a standard license with nothing unusual in it. The only consequence is that the combined binary becomes GPL-2.0-or-later, a one-way door for publishing that binary. Not a blocker here; enable only if disk SMART detail is actually wanted. ## Related - #378 — Framework external-module certificate generation (same host, different package)
Author
Owner

Opened in error — this repository's issues are tracked on GitLab (forge.nimmog.uk, nimmo-nix/nixos-config), which is where the git remote points. Tracked instead as https://forge.nimmog.uk/nimmo-nix/nixos-config/-/work_items/358.

Opened in error — this repository's issues are tracked on GitLab (`forge.nimmog.uk`, `nimmo-nix/nixos-config`), which is where the git remote points. Tracked instead as https://forge.nimmog.uk/nimmo-nix/nixos-config/-/work_items/358.
nimmo closed this issue 2026-10-26 20:24:02 +00:00
Sign in to join this conversation.
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
nimmo/nixos-config#389
No description provided.