Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions bin/omarchy-capture-screenrecording
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# DMA-BUF modifier import on some configurations, leaving recording unable to
# start.
#
# When gsr-kms-server lacks CAP_SYS_ADMIN (Omarchy strips it; see #8245), the
# KMS path would otherwise fall back to pkexec as full root. Prefer the portal
# backend in that case unless OMARCHY_SCREENRECORD_USE_KMS=true forces KMS.
#
# Env: OMARCHY_SCREENRECORD_DEBUG=true appends gpu-screen-recorder's stderr (and
# the picker target it was launched with) to /tmp/omarchy-screenrecord.log so
# users can attach a log when reporting capture failures.
Expand Down Expand Up @@ -143,18 +147,39 @@ select_capture_target() {
echo "region:${BASH_REMATCH[3]}x${BASH_REMATCH[4]}+${BASH_REMATCH[1]}+${BASH_REMATCH[2]}"
}

# True when gsr-kms-server still carries CAP_SYS_ADMIN (Arch default). Omarchy
# strips that capability; without it the helper would pkexec as full root.
gsr_kms_has_sys_admin() {
local caps

[[ -x /usr/bin/gsr-kms-server ]] || return 1
command -v getcap >/dev/null 2>&1 || return 1
caps=$(getcap /usr/bin/gsr-kms-server 2>/dev/null) || return 1
[[ $caps == *cap_sys_admin* || $caps == *CAP_SYS_ADMIN* ]]
}

start_screenrecording() {
local capture_args=()
local target
local use_portal=false

# Prefer portal when the KMS helper has no CAP_SYS_ADMIN: without it,
# gpu-screen-recorder falls back to pkexec as full root (#8245). Opt into
# KMS anyway with OMARCHY_SCREENRECORD_USE_KMS=true (after restoring the
# capability), or force portal with OMARCHY_SCREENRECORD_USE_PORTAL=true.
if [[ ${OMARCHY_SCREENRECORD_USE_PORTAL:-false} == "true" ]]; then
use_portal=true
elif [[ ${OMARCHY_SCREENRECORD_USE_KMS:-false} != "true" ]] &&
! gsr_kms_has_sys_admin; then
use_portal=true
fi

# Opt-in path for HDR, external-GPU monitors, and window capture (all things
# the portal backend supports and the kms backend doesn't). Default flow uses
# slurp + the kms backend, which avoids the EGL DMA-BUF modifier import
# failures the portal path can hit on some configurations.
if [[ $FULLSCREEN == "true" ]]; then
# Portal covers HDR, external-GPU monitors, and window capture. KMS avoids
# EGL DMA-BUF modifier import failures the portal path can hit on some setups.
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)}")
else
Expand Down
15 changes: 15 additions & 0 deletions bin/omarchy-strip-gsr-kms-caps
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# omarchy:summary=Strip file capabilities from gsr-kms-server
# omarchy:hidden=true

set -euo pipefail

# gpu-screen-recorder's Arch package grants CAP_SYS_ADMIN to gsr-kms-server so
# KMS capture can run without pkexec. That capability is root-equivalent and
# world-executable (#8245). Omarchy strips it; screen recording falls back to
# the portal backend when the capability is absent (see
# omarchy-capture-screenrecording).
if [[ -x /usr/bin/gsr-kms-server ]] && command -v setcap >/dev/null 2>&1; then
setcap -r /usr/bin/gsr-kms-server || true
fi
11 changes: 11 additions & 0 deletions default/libalpm/hooks/90-omarchy-strip-gsr-kms-caps.hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = gpu-screen-recorder

[Action]
Description = Stripping file capabilities from gsr-kms-server...
When = PostTransaction
Depends = omarchy
Exec = /usr/bin/omarchy-strip-gsr-kms-caps
29 changes: 29 additions & 0 deletions migrations/1789318700.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
echo "Strip CAP_SYS_ADMIN from gsr-kms-server"

# Arch's gpu-screen-recorder package re-applies cap_sys_admin=ep on every
# upgrade. Strip it now and install a pacman hook so upgrades stay stripped.
# omarchy-capture-screenrecording uses the portal backend when the helper no
# longer has the capability, avoiding gpu-screen-recorder's pkexec fallback.

if [[ -x /usr/bin/gsr-kms-server ]] && command -v setcap >/dev/null 2>&1; then
if getcap /usr/bin/gsr-kms-server 2>/dev/null | grep -q .; then
sudo setcap -r /usr/bin/gsr-kms-server
fi
fi

hook=/etc/pacman.d/hooks/90-omarchy-strip-gsr-kms-caps.hook
if [[ ! -f $hook ]]; then
sudo mkdir -p /etc/pacman.d/hooks
sudo install -Dm644 /dev/stdin "$hook" <<'HOOK'
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = gpu-screen-recorder

[Action]
Description = Stripping file capabilities from gsr-kms-server...
When = PostTransaction
Exec = /usr/bin/omarchy-strip-gsr-kms-caps
HOOK
fi
8 changes: 8 additions & 0 deletions test/shell.d/config-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,11 @@ if grep -RIl 'upgrade-to-quattro\|Omarchy 4\.0 is upgraded' "$ROOT/migrations" >
fail "4.0 upgrade is not modeled as a migration"
fi
pass "4.0 upgrade is handled outside the migration runner"

[[ -f $ROOT/default/libalpm/hooks/90-omarchy-strip-gsr-kms-caps.hook ]] ||
fail "missing gsr-kms-server cap-strip pacman hook"
[[ -x $ROOT/bin/omarchy-strip-gsr-kms-caps ]] || fail "missing omarchy-strip-gsr-kms-caps"
grep -Fq 'Exec = /usr/bin/omarchy-strip-gsr-kms-caps' \
"$ROOT/default/libalpm/hooks/90-omarchy-strip-gsr-kms-caps.hook" ||
fail "gsr-kms-server cap-strip hook must call omarchy-strip-gsr-kms-caps"
pass "gsr-kms-server capability strip hook and command are present"
31 changes: 31 additions & 0 deletions test/shell.d/gsr-kms-caps-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

strip="$ROOT/bin/omarchy-strip-gsr-kms-caps"
hook="$ROOT/default/libalpm/hooks/90-omarchy-strip-gsr-kms-caps.hook"
capture="$ROOT/bin/omarchy-capture-screenrecording"

[[ -x $strip ]] || fail "missing omarchy-strip-gsr-kms-caps"
[[ -f $hook ]] || fail "missing gsr-kms-server cap-strip pacman hook"
grep -Fq 'Target = gpu-screen-recorder' "$hook" ||
fail "cap-strip hook must trigger on gpu-screen-recorder"
grep -Fq 'Exec = /usr/bin/omarchy-strip-gsr-kms-caps' "$hook" ||
fail "cap-strip hook must call omarchy-strip-gsr-kms-caps"
grep -Fq 'setcap -r /usr/bin/gsr-kms-server' "$strip" ||
fail "strip helper must clear capabilities on gsr-kms-server"
pass "gsr-kms-server capability strip hook and command are present"

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"

grep -Fq 'Strip CAP_SYS_ADMIN from gsr-kms-server' "$ROOT/migrations/1789318700.sh" ||
fail "migration must strip gsr-kms-server capabilities on existing installs"
pass "migration strips gsr-kms-server capabilities on update"