Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<!--
The fingerprint panel runs omarchy-setup-security-fingerprint-enroll through
pkexec to install packages, enroll a print, and configure PAM. Giving it its
own action lets polkit show the reason on a single line instead of the
truncated command line, while keeping arbitrary pkexec commands visible.
-->
<policyconfig>
<vendor>Omarchy</vendor>
<vendor_url>https://omarchy.org</vendor_url>
<action id="org.omarchy.setup-security-fingerprint-enroll">
<description>Set up fingerprint authentication</description>
<message>Set up fingerprint authentication</message>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_admin</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/omarchy-setup-security-fingerprint-enroll</annotate>
<annotate key="org.freedesktop.policykit.exec.argv1">enroll</annotate>
</action>
</policyconfig>
25 changes: 20 additions & 5 deletions shell/plugins/panels/fingerprint/Enrollment.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Item {
property string reason: ""

readonly property string helper: "omarchy-setup-security-fingerprint-enroll"
readonly property string packagedHelper: "/usr/bin/" + helper
readonly property string policyPath: "/usr/share/polkit-1/actions/org.omarchy.setup-security-fingerprint-enroll.policy"
// Everything the last run's commands said, for a failure that takes more
// than a line to explain.
readonly property string logPath: Quickshell.env("HOME") + "/.local/state/omarchy/fingerprint.log"
Expand Down Expand Up @@ -89,11 +91,24 @@ Item {
}
cancelling = false
phase = demo ? "setup" : "auth"
var command = demo ? [helper, demoFails ? "demo-fail" : "demo", finger] : ["pkexec", helper, "enroll", finger]
// The polkit agent labels the prompt for this exact command line with the
// reason. The helper's stderr, and pkexec's own, is the log of this run.
run.command = ["bash", "-c", 'mkdir -p "${0%/*}"; [[ -z $1 ]] || omarchy-shell -q omarchy.polkit expect "$1" "$2"; shift 2; exec "$@" 2>"$0"',
logPath, demo ? "" : helper + " enroll " + finger, reason].concat(command)
// The helper's stderr, and pkexec's own, is the log of this run.
if (demo) {
run.command = ["bash", "-c", 'mkdir -p "${0%/*}"; exec "$@" 2>"$0"',
logPath, helper, demoFails ? "demo-fail" : "demo", finger]
} else {
// The polkit policy for packagedHelper gives the prompt its reason
// without showing the command line. On a dev checkout before that policy
// is installed, fall back to the helper on PATH with a polkit label.
run.command = ["bash", "-c",
'mkdir -p "${0%/*}"\n' +
'if [[ -f $1 && -x $2 ]]; then\n' +
' exec pkexec "$2" enroll "$4" 2>"$0"\n' +
'else\n' +
' omarchy-shell -q omarchy.polkit expect "$3 enroll $4" "$5"\n' +
' exec pkexec "$3" enroll "$4" 2>"$0"\n' +
'fi',
logPath, policyPath, packagedHelper, helper, finger, reason]
}
run.running = true
}

Expand Down
12 changes: 10 additions & 2 deletions shell/plugins/polkit/PolkitModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ function matchesProgram(shown, want) {
var clean = want.replace(/^\.\//, "")
var bare = "/" + clean
if (shown.slice(-bare.length) === bare && shown.slice(0, shown.length - bare.length).indexOf(" ") === -1) return true
if (shown.length !== 80 || shown.indexOf(" ... ") !== 38) return false
var head = shown.slice(0, 38)
var tail = shown.slice(-37)
if (bare.length < 37 || tail !== bare.slice(-37)) return false
var wantExe = "/" + clean.split(" ")[0]
var shownExe = shown.split(" ")[0]
return shown.length === 80 && shown.indexOf(" ... ") === 38 && shownExe.slice(-wantExe.length) === wantExe && shown.slice(-37) === bare.slice(-37)
if (head.indexOf(" ") !== -1) return head.split(" ")[0].slice(-wantExe.length) === wantExe
var lastSlash = head.lastIndexOf("/")
return lastSlash !== -1 && wantExe.indexOf(head.slice(lastSlash)) === 0
}

// A label a command asked for its next prompt (omarchy.polkit expect), when
Expand Down Expand Up @@ -88,6 +93,9 @@ function authorizationLabel(message, tr, agentName) {
// udisks formatting a drive, named as udisks names it.
match = clean.match(/^Authentication is required to format (.+)$/i)
if (match) return t("polkit.authorizeFormatting", "Authorize formatting of %1").replace("%1", function() { return match[1] })
// Fingerprint setup policy message, translated through the shell catalog.
if (clean === "Set up fingerprint authentication")
return t("fingerprint.authorize", "Set up fingerprint authentication")
return clean
}

Expand Down
24 changes: 24 additions & 0 deletions test/shell.d/polkit-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ assertEqual(
'Authentication is required to change system settings',
'polkit preserves custom authorization messages'
)
assertEqual(
polkit.authorizationLabel('Set up fingerprint authentication', key => key === 'fingerprint.authorize' ? 'Opsæt fingeraftryksgodkendelse' : key),
'Opsæt fingeraftryksgodkendelse',
'polkit translates the fingerprint setup policy message through the shell catalog'
)
assertEqual(
polkit.promptProgram('Set up fingerprint authentication'),
'',
'fingerprint setup policy message hides the command line'
)
const multilineSh = "Authentication is needed to run `/usr/bin/sh -c\nfor f in /sys/device ... [ -w \"$f\" ] && echo 1 > \"$f\"\ndone\n' as the super user"
assertEqual(
polkit.authorizationLabel(multilineSh),
Expand Down Expand Up @@ -73,6 +83,20 @@ assertEqual(polkit.expectedLabel(cutPrompt, { program: longLine, label: 'Claude
assertEqual(polkit.expectedLabel("Authentication is needed to run `/usr/bin/pacman -S valkey' as the super user", { program: 'pacman -S valkey', label: 'Install Valkey', until: 1000 }, 500), 'Install Valkey', 'a bare program name matches the resolved path in the prompt')
assertEqual(polkit.expectedLabel("Authentication is needed to run `/usr/bin/unpacman -S valkey' as the super user", { program: 'pacman -S valkey', label: 'Install Valkey', until: 1000 }, 500), '', 'a bare program name does not match a different program suffix')
assertEqual(polkit.expectedLabel("Authentication is needed to run `/usr/bin/echo /usr/bin/pacman -S valkey' as the super user", { program: 'pacman -S valkey', label: 'Install Valkey', until: 1000 }, 500), '', 'a bare program name does not match when appearing inside arguments')
const longExe = '/usr/share/omarchy/bin/omarchy-setup-security-fingerprint-enroll enroll right-index-finger'
const cutExePrompt = "Authentication is needed to run `" + longExe.slice(0, 38) + ' ... ' + longExe.slice(-37) + "' as the super user"
assertEqual(
polkit.expectedLabel(cutExePrompt, { program: 'omarchy-setup-security-fingerprint-enroll enroll right-index-finger', label: 'Set up fingerprint authentication', until: 1000 }, 500),
'Set up fingerprint authentication',
'a bare program name matches even when pkexec cuts inside the executable name'
)
const badPrefixExe = '/usr/share/omarchy/bin/unomarchy-setup-security-fingerprint-enroll enroll right-index-finger'
const cutBadPrefixPrompt = "Authentication is needed to run `" + badPrefixExe.slice(0, 38) + ' ... ' + badPrefixExe.slice(-37) + "' as the super user"
assertEqual(
polkit.expectedLabel(cutBadPrefixPrompt, { program: 'omarchy-setup-security-fingerprint-enroll enroll right-index-finger', label: 'Set up fingerprint authentication', until: 1000 }, 500),
'',
'a bare program name cut inside the executable still rejects a different program prefix'
)
assertEqual(polkit.promptProgram(pacman), '/usr/bin/pacman', 'a pkexec prompt names the program it runs, which a label never hides')
assertEqual(polkit.promptProgram("Authentication is needed to run `/usr/bin/sh -c echo it's' as the super user"), "/usr/bin/sh -c echo it's", 'a command line holding a quote is read up to the quote that closes it')
assertEqual(JSON.stringify(polkit.parseRequester('claude\tClaude\t0\n')), JSON.stringify({ mark: 'claude', name: 'Claude', light: false }), 'parseRequester reads mark, display name, and light flag')
Expand Down