Skip to content

Strip dangerous caps from gsr-kms-server and btop - #12103

Open
chessing234 wants to merge 8 commits into
omacom:quattrofrom
chessing234:fold/strip-gsr-btop-caps
Open

chessing234 wants to merge 8 commits into
omacom:quattrofrom
chessing234:fold/strip-gsr-btop-caps

Conversation

@chessing234

Copy link
Copy Markdown
Contributor

Summary

Test plan

  • test/shell.d/config-test.sh (both hook checks)
  • test/shell.d/gsr-kms-caps-test.sh
  • Fresh install / upgrade runs both strip migrations and pacman hooks

Arch grants the helper a root-equivalent capability; drop it on install/upgrade
and prefer portal capture when the capability is absent so recording does not
escalate through pkexec.
@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: on an existing install that runs the new migrations, both capabilities are stripped and stay stripped across later package upgrades. The PostTransaction hooks run after the Arch gpu-screen-recorder scriptlet that re-applies cap_sys_admin=ep, the migrations are idempotent, and the new getcap check agrees with gpu-screen-recorder's own direct-helper-or-pkexec decision for the capability sets Arch and upstream apply. Five issues remain: fresh installs are not covered, the repository's style test fails, the default recording flow changes, the migration leaves unowned hook copies, and btop loses two monitoring features.

The new hooks are not installed as pacman hooks, so fresh installs keep both capabilities

default/libalpm/hooks/ is not read by pacman directly. In omarchy-pkgs, the omarchy and omarchy-dev PKGBUILDs install three named hooks into /usr/share/libalpm/hooks/ (no glob), and omarchy-settings copies default/ to /usr/share/omarchy/default/, so the two new hook files land only there. No companion omarchy-pkgs change was found; the closed #11512 noted that "omarchy-pkgs still needs the one-line hook install", and this PR's description does not carry that forward.

Fresh installs also never run the migrations: omarchy-provision-user --first-install marks every shipped migration as done.

existing install:  migration strips caps + writes /etc/pacman.d/hooks copy  -> stripped, portal
fresh install:     migrations pre-marked, hooks not packaged                -> caps kept, KMS (as on base)

Impact: based on source reading, fresh installs keep cap_sys_admin=ep on gsr-kms-server and cap_dac_read_search,cap_perfmon=ep on btop, so the two install populations end up with different security state and different recording behavior. The alpm_hooks packaging check in test/shell.d/config-test.sh was not extended, so the suite does not catch this.

Suggested change: add install lines for both hooks to the omarchy and omarchy-dev PKGBUILDs in omarchy-pkgs, and add both names to alpm_hooks in config-test.sh.

test/shell.d/bin-style-test.sh fails on the new command -v calls

The repository test rejects raw command -v in bin/ outside omarchy-cmd-*, omarchy-pkg-* and omarchy-upgrade-to-quattro. At the PR head it fails (exit 1, not ok - bin commands use command helpers) listing exactly bin/omarchy-capture-screenrecording, bin/omarchy-strip-gsr-kms-caps and bin/omarchy-strip-btop-caps. The base has no violations, and the test is unchanged on the current quattro tip.

Suggested change: use omarchy-cmd-present getcap / omarchy-cmd-present setcap in place of command -v.

Portal becomes the default recording backend, and --fullscreen becomes interactive

Once the migration strips the capability, gsr_kms_has_sys_admin is false and every mode takes the portal path unless OMARCHY_SCREENRECORD_USE_KMS=true is set. Recorder arguments from a stubbed backend matrix (60 cases per variant):

Input Base Head, capability present Head, capability stripped
--fullscreen -w <focused monitor> (KMS) same as base -w portal
default, region picked Omarchy picker, then -w WxH+X+Y same as base -w portal, Omarchy picker not shown
USE_PORTAL=true + --fullscreen -w <focused monitor> -w portal -w portal

Impact:

  • --fullscreen was added for agents (commit 83e7f413), and Omarchy's agent skills tell agents to use it. The script does not pass -restore-portal-session, so the portal share picker opens (per gsr 6.1.3 and xdg-desktop-portal-hyprland source) and the script waits until a person picks or cancels.
  • Base keeps portal opt-in on purpose: the unchanged header comment says "Off by default because the portal path can fail EGL DMA-BUF modifier import on some configurations", and commit 6a5e5378 is "Bypass portal by default for screenrecording due to portal bug". The PR's script comment says it prefers portal, but neither the PR nor the comment addresses that earlier decision or the portal failure behind it, and the change applies to every migrated install. How often that portal failure occurs was not established.
  • The region-picker flow in manual/12-screenshots-recording.md and the webcam overlay's region anchoring no longer describe the default.

The trade-off itself is defensible: without the capability, KMS capture makes gsr run gsr-kms-server through pkexec as full root, with an authentication prompt.

Suggested change: state the default change in the PR description so maintainers can decide on it, update the "Off by default" header comment and the manual, and document OMARCHY_SCREENRECORD_USE_KMS. Note that after the strip, agents have no non-interactive route: KMS needs a pkexec prompt and portal needs a pick, so the agent docs for --fullscreen need updating too. Passing -restore-portal-session yes could let later recordings reuse the previous selection (untested; the first recording would still need a pick, and the restored source is the last one picked, not the focused monitor).

The migration's /etc/pacman.d/hooks copies become a second, unowned source of truth

Both migrations write hooks into /etc/pacman.d/hooks/ using the same file names as the in-tree hooks, but without Depends = omarchy.

Impact (per pacman 7.1.0 source and alpm-hooks(5)):

  • A same-named hook in /etc/pacman.d/hooks overrides a packaged one, so once the hooks are packaged, migrated systems keep running the /etc copy. The [[ ! -f $hook ]] guard means later hook changes never reach them.
  • No package owns the copies, so they survive removal of omarchy and then point Exec at a missing binary whenever btop or gpu-screen-recorder is installed or upgraded (a non-fatal pacman error).
  • A /dev/null mask symlink fails -f, so the migration replaces an administrator's mask. In a sandbox case with a dangling symlink in place of the hook, the migration replaced the symlink and stripped the capability.
  • Because the hook re-strips on every gpu-screen-recorder upgrade, the documented OMARCHY_SCREENRECORD_USE_KMS=true "after restoring the capability" lasts only until the next upgrade, after which each recording goes through pkexec.

Suggested change: once the hooks are packaged, reduce each migration to stripping the current capability. If the /etc copies are kept, add Depends = omarchy and plan how they are removed.

btop loses CPU package power and Intel GPU monitoring

setcap -r removes all of btop's file capabilities, including cap_perfmon, not only CAP_DAC_READ_SEARCH as the commit title says. btop's README describes these capabilities as needed for Intel GPU and CPU wattage (btop 1.4.7 source):

  • CPU package power reads intel-rapl energy_uj, which the kernel exposes as mode 0400.
  • Intel GPU stats open CPU-wide perf events, which need CAP_PERFMON at the default perf_event_paranoid of 2.

Impact: Omarchy's shipped config/btop/btop.conf enables show_cpu_watts and Intel GPU display. After this change, btop run as a normal user no longer shows either (source reading, not run on hardware).

Suggested change: state this trade-off in the PR, or keep cap_perfmon (for example setcap cap_perfmon=ep /usr/bin/btop) and drop only the DAC bypass. That keeps Intel GPU stats; CPU package power would still need the DAC bypass. Either is a maintainer judgement call.

Optional test improvement: test/shell.d/gsr-kms-caps-test.sh and the config-test.sh additions only check file presence and grep for strings. A mutant that inverts the portal fallback, turns the strip helper into a no-op, moves the hook to PreTransaction and reduces the migration to its echo line still passes gsr-kms-caps-test.sh (exit 0). Making the hard-coded /usr/bin/gsr-kms-server path overridable, stubbing getcap on PATH and asserting the recorder's -w argument (as screenrecording-test.sh already runs the script with a stub recorder), plus a migration test with recorded sudo/setcap stubs, would cover the behavior.


Review information

Test scope: Pinned head 8a07b82e. Source review of the PR, omarchy-pkgs packaging, omarchy-iso, gpu-screen-recorder 6.1.3 with its Arch packaging, btop 1.4.7 with its Arch packaging, pacman 7.1.0, libcap and xdg-desktop-portal-hyprland. Sandboxed runs with stubbed sudo, setcap, getcap and recorder: a backend-selection matrix for base, head and a mutant, a migration harness, a test-mutation run and the repository's bin-style-test.sh. No real pacman transaction, capability change, pkexec prompt, portal session or btop hardware reading was exercised.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@chessing234

Copy link
Copy Markdown
Contributor Author

switched the new bin helpers to omarchy-cmd-present so bin-style-test passes. packaging the alpm hooks in omarchy-pkgs is still a separate follow-up.

@chessing234

Copy link
Copy Markdown
Contributor Author

cmd-present fix is up. hook packaging + btop/portal behaviour are maintainer calls / omarchy-pkgs work.

@omarchybot omarchybot added the enhancement New feature or request label Sep 27, 2026
@llstrk

llstrk commented Sep 28, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Follow-up to the earlier review, checked at head a1004b28. The three new commits resolve the style-test failure. The other earlier findings are unchanged by those commits and still apply. One suggestion in the /etc hook finding needs a correction, and one new issue is noted below.

Earlier finding Status at a1004b28
bin-style-test.sh fails on raw command -v Resolved
Hooks not packaged, fresh installs keep both capabilities Still present
Portal becomes the default, --fullscreen becomes interactive Still present
Migration /etc/pacman.d/hooks copies Still present; suggested change corrected below
btop loses CPU package power and Intel GPU monitoring Still present
Optional test improvement (string-only tests) Still applies

Verified: test/shell.d/bin-style-test.sh now passes at the head and at the head merged with the current quattro tip (exit 0), and still fails at the earlier head (exit 1, listing the same three files). omarchy-cmd-present getcap/setcap behaved identically to the replaced command -v … >/dev/null 2>&1 checks in all 29 stubbed scenarios with the helper on PATH, with both the base and the current quattro version of the helper: same exit status, same setcap calls, no output. No regression from the new commits was found.

Optional: a simpler option also exists. AGENTS.md says commands from the default package set are runtime invariants to be invoked directly, without omarchy-cmd-present checks. setcap and getcap come from libcap, which coreutils depends on, so the three checks could be dropped entirely.

Hook packaging (reply to the author's comment)

The reply calls hook packaging a separate omarchy-pkgs follow-up. No companion omarchy-pkgs PR or branch was found. At omarchy-pkgs a701a8db, both the omarchy and omarchy-dev PKGBUILDs still install three hooks by name. In this repository, alpm_hooks in config-test.sh still lists three. The PR description's test-plan item "Fresh install / upgrade runs both strip migrations and pacman hooks" therefore still does not hold for fresh installs. The omarchy PKGBUILD also seeds migration markers into /etc/skel, so users created later skip the strip migrations too.

docs/file-layout.md shows default/libalpm/hooks/*.hook mapping to /usr/share/libalpm/hooks/*.hook as a glob, which the PKGBUILDs do not do. That may explain the expectation, but each hook still needs its own install line. Other contributors have opened such companion PRs directly (for example omarchy-pkgs #381 and #645).

Impact: as in the earlier review, fresh installs keep cap_sys_admin=ep on gsr-kms-server and cap_dac_read_search,cap_perfmon=ep on btop, because neither the new hooks nor the strip migrations run there.

Suggested change: open the omarchy-pkgs PR that adds both hooks to the omarchy and omarchy-dev PKGBUILDs and link it here, and add both names to alpm_hooks in config-test.sh in this PR; or mark the fresh-install test-plan item as not covered.

Correction: Depends = omarchy does not silence an orphaned /etc hook

The earlier review suggested adding Depends = omarchy if the migrations keep writing /etc/pacman.d/hooks copies. That does not fix the orphan case. In pacman 7.1.0 (lib/libalpm/hook.c), an unsatisfied Depends logs unable to run hook …: could not satisfy dependencies, so after omarchy is removed the error message changes but the error remains. The rest of that finding (a same-named /etc hook overrides the packaged one and is never updated, the migration replaces a /dev/null mask, and re-stripping on upgrade undoes OMARCHY_SCREENRECORD_USE_KMS after a restore) is unchanged.

Suggested change: once the hooks are packaged, have the migrations strip the capability without writing /etc copies.

New: cancelling the portal share dialog leaves the webcam overlay running

With the capability stripped, every recording, including --fullscreen, now opens the portal share dialog unless OMARCHY_SCREENRECORD_USE_KMS=true is set. When that dialog is cancelled, gpu-screen-recorder 6.1.3 exits (code 60, per source) before creating the output file. start_screenrecording has no else after if kill -0 $pid, so it returns 0 and start_screenrecording || cleanup_webcam never cleans up.

base default:  cancel in Omarchy region picker -> before overlay and gsr -> nothing left behind
head default:  overlay started -> gsr portal dialog cancelled -> gsr exits
               -> no else branch -> exit 0, no notification, overlay window still open

A stubbed sandbox run (no real portal, recorder or camera) matched this for the head default and --fullscreen paths: exit 0, no recording file, overlay process still alive. The same path already existed on base with OMARCHY_SCREENRECORD_USE_PORTAL=true (except --fullscreen, which stayed on KMS there). This PR makes it part of the default flow.

Impact: with --with-webcam, a routine cancel leaves the pinned webcam window open with the camera in use. --stop-recording does not remove it, because nothing is recording. It stays until the user closes it, starts another webcam recording, or stops a later recording.

Suggested change: the open PR #7189 adds a failure branch (notification plus return 1, so cleanup_webcam runs) and merges cleanly with this PR. It does not tell a deliberate cancel (exit 60) apart from a failure, so combined with this PR every cancelled dialog would show "Screen recording failed to start". Handling exit 60 quietly, while still cleaning up, would fit the new default.


Review information

Test scope: Pinned head a1004b28, compared with the earlier head 8a07b82e, the base and the current quattro tip 3faafba2; omarchy-pkgs at a701a8db; pacman 7.1.0, gpu-screen-recorder 6.1.3 and xdg-desktop-portal-hyprland 1.4.1 source. Sandboxed runs: bin-style-test.sh and gsr-kms-caps-test.sh at the earlier head, and those plus config-test.sh at the head, the head merged with quattro and a test mutant; a stubbed command -v/omarchy-cmd-present equivalence matrix; and a stubbed portal-cancel run of the recorder script. The earlier recorder-argument matrix and /etc mask case were not rerun, because that code is unchanged. No real pacman transaction, capability change, pkexec prompt, portal session, camera or btop hardware reading was exercised.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The changes affect two desktop utilities and the screen-recording workflow.

The PR still needs fixes because recording can lose its fallback, and --fullscreen can wait for input.

Findings

  1. P1 Recorder fallback stops working ▶
  2. P1 Full-screen recording waits for input ▶
  3. P2 Tests check text, not behavior ▶

Summary

This PR removes file capabilities from gsr-kms-server and btop and adds migrations and pacman hooks to keep them removed.

  • Screen recording avoids the KMS helper when it lacks CAP_SYS_ADMIN.
  • Btop runs without package-added file capabilities.

Reviews (3) · Last reviewed commit: "Keep wf-recorder-only setups off the GSR..." · Reviewed by Greptile

Comment on lines +328 to +330
elif [[ ${OMARCHY_SCREENRECORD_USE_KMS:-false} != "true" ]] &&
! gsr_kms_has_sys_admin; then
use_portal=true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Recorder fallback stops working

When gsr-kms-server is missing or its capabilities have been stripped, the new default sets target="portal". The recorder loop then skips wf-recorder. Machines where gpu-screen-recorder is unavailable or rejects the GPU, including Apple Silicon, can no longer record even when wf-recorder is installed.

Keep monitor/region targets available when choosing or falling back to wf-recorder; it does not need the KMS helper.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment thread test/shell.d/gsr-kms-caps-test.sh Resolved
Comment on lines +335 to 340
if [[ $FULLSCREEN == "true" && $use_portal != "true" ]]; then
target="monitor:$(omarchy-hyprland-monitor-focused)"
capture_args=(-w "${target#monitor:}" -s "${RESOLUTION:-$(default_resolution)}")
elif [[ ${OMARCHY_SCREENRECORD_USE_PORTAL:-false} == "true" ]]; then
elif [[ $use_portal == "true" ]]; then
target="portal"
capture_args=(-w portal -s "${RESOLUTION:-$(default_resolution)}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Full-screen recording waits for input

After the migration strips CAP_SYS_ADMIN, --fullscreen takes the portal branch instead of recording the focused monitor. It passes -w portal, so recording waits for the user to choose a source. This breaks the documented picker-free command used for automated screen recordings.

Preserve a noninteractive full-screen path without restoring the privileged helper.

Comment on lines +21 to +27
grep -Fq 'gsr_kms_has_sys_admin' "$capture" ||
fail "screenrecording must detect whether gsr-kms-server still has CAP_SYS_ADMIN"
grep -Fq 'OMARCHY_SCREENRECORD_USE_KMS' "$capture" ||
fail "screenrecording must allow forcing KMS after restoring the capability"
grep -Fq 'use_portal=true' "$capture" ||
fail "screenrecording must fall back to portal when CAP_SYS_ADMIN is absent"
pass "screenrecording avoids pkexec when gsr-kms-server has no CAP_SYS_ADMIN"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests check text, not behavior

These checks search for source strings instead of running the behavior they claim to test. Capability detection or the portal choice can break while the checks stay green.

AGENTS.md forbids tests that restate the implementation through source searches. It also requires extending the area's existing test file. Replace these checks with behavior checks in screenrecording-test.sh; the added hook-string checks in config-test.sh repeat the same pattern. These repository requirements must be satisfied before merging.

File Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants