79.3. polkit-128
Authorization framework for unprivileged processes (NetworkManager, fwupd, bolt, fprintd)
| Version | 128, release 3 |
| Shelf | auth — Authentication, authorisation, accounts and directory services |
| Phase | 41_system (System), 49 of 1047 in build order |
| Licence | LGPL-2.0-or-later |
| Homepage | https://github.com/polkit-org/polkit |
| Build time | 0.1 SBU |
| Installed size | 749.5 KiB in 59 files |
| Recipe | ports/core/auth/polkit/kpkgbuild |
About
polkit is the system service that other daemons ask whether a user may perform a privileged action. On KDOS, elogind, NetworkManager, ModemManager, udisksd, accounts-daemon, libvirtd, bolt, fwupd, upower, fprintd, pcscd, brltty’s braille server and the KAuth helpers of Plasma and KDE applications ask it, and pkexec runs GParted and other programs as root through it; networkmanager and the other ports that ask it depend on this one.
polkitd learns from elogind which session a caller belongs to. A caller in the active local session, the person at the machine, gets each action’s allow_active answer, a local session switched away from gets allow_inactive, and anything else, an SSH login or a daemon, gets allow_any. Where that answer is a password, polkit-kde-agent-1 asks for it in a Plasma session. What KDOS decides differently from the shipped defaults is in /etc/polkit-1/rules.d/50-kdos.rules, which comes from the tree’s fs/ overlay rather than from this port; see Security model.
polkitd is started at boot by /etc/init.d/41_polkitd.sh, after D-Bus and before ModemManager and NetworkManager, and never by D-Bus activation; see How polkit and ModemManager are started.
Sources
polkit-128.tar.gz(500.2 KiB)
sha2566edb06bf1448e49e428f9597a97af6a05d62146dd0b58f86eeaebcee3f5ecfaa
upstream: https://github.com/polkit-org/polkit/archive/refs/tags/128.tar.gz
archive copy: sources-1/auth--polkit-128.tar.gz
Dependencies
Depends on: meson, glib, expat, duktape, dbus, libxslt, docbook-xsl, docbook-xml, pam, elogind.
Required by (29): accountsservice, bolt, brltty, fprintd, fwupd, gparted, gvfs, iio-sensor-proxy, kcron, kde-inotify-survey, kdos-discover, kdos-installer-gui, kdos-settingsd, kdos-sysupdated, kdos-welcome, kinfocenter, kio-admin, kpmcore, libvirt, modemmanager, networkmanager, pcsc-lite, polkit-kde-agent-1, polkit-qt6, powerdevil, resources, tlp-pd, udisks2, upower.
Patches
build.sh applies these; kpkg applies nothing by itself.
turnstile-session.patch— Answer a turnstile session's processes for the user's display sessionturnstiled registers each user's services as one session of their own, with the PAM service name "turnstiled" and no seat. On KDOS the session bus is one of those services, so every program the bus starts (plasma-shutdown, krunner and what it launches, ksystemstats) is in that session, and polkit answers for it as for a session with no seat: allow_any, never allow_active, with no authentication agent, which is registered for the display session.
When a process's session is a turnstile session, take the user from that session (sd_session_get_uid) and answer for the user's display session (sd_uid_get_display); with no display session the process has no session. The owner-uid lookups polkit falls back to cannot stand in: under elogind they fail for a process in a session's /cN/session cgroup leaf. Every other session is used as before. Chimera Linux's polkit turnstile.patch skips the turnstile session in the same place.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install polkit'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/auth/polkit.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/auth/polkit
echo '6edb06bf1448e49e428f9597a97af6a05d62146dd0b58f86eeaebcee3f5ecfaa polkit-128.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/polkit
SRC=$SRC_ROOT/polkit-128
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf polkit-128.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i "$PORT_SRC/turnstile-session.patch"
meson setup build \
--prefix=/usr --sysconfdir=/etc --libdir=lib --libexecdir=/usr/lib --localstatedir=/var \
--buildtype=release \
-Dauthfw=pam \
-Dpam_prefix=/etc/pam.d \
-Dsession_tracking=elogind \
-Dintrospection=false \
-Dgtk_doc=false \
-Dman=true \
-Dgettext=false \
-Dexamples=false \
-Dtests=false \
-Dos_type=lfs
meson compile -C build
DESTDIR=$PKG meson install --no-rebuild -C build
rm -rf "$PKG/usr/lib/systemd" "$PKG/usr/lib/sysusers.d" "$PKG/usr/lib/tmpfiles.d"
rm "$PKG/usr/share/dbus-1/system-services/org.freedesktop.PolicyKit1.service"
The switches, and why each is set:
--libexecdir=/usr/lib— Changes nothing in polkit 128, whose build reads nolibexecdir: it installspolkitdandpolkit-agent-helper-1inlib/polkit-1/under the prefix whatever the option says, so the daemon is/usr/lib/polkit-1/polkitd, the path the boot script starts.-Dauthfw=pam— Authenticates through PAM, from the pam port, rather than by reading the shadow file itself. It is upstream’s default.-Dpam_prefix=/etc/pam.d— Installs polkit’s PAM service file,polkit-1, in/etc/pam.d, beside thesystem-*stacks the pam port writes, instead of upstream’s default/usr/lib/pam.d. Linux-PAM looks a service up in/etc/pam.dfirst, then in/usr/lib/pam.dand/usr/share/pam/pam.d, so a file in/etc/pam.dis the one that is read even if another copy exists in either of the others.-Dos_type=lfs— Names the distribution family, which picks the PAM stacks thepolkit-1file includes:system-auth,system-account,system-passwordandsystem-session, the four files the pam port writes. Left empty, polkit’s configure guesses from marker files in the build root such as/etc/lfs-release, finds none, and falls back to includingsystem-authfor all four.-Dsession_tracking=elogind— Build the session monitor that asks logind, linked againstlibelogindfrom elogind, which is independs. Without a session monitor that finds sessions, polkit never sees an active one: every check falls to an action’sallow_anyanswer, which for most actions is a refusal or a request for the administrator’s password, so nothing the person at the machine does is granted by theallow_activedefaults and50-kdos.ruleswould have to grant each action by name.logindwould link libsystemd, which is not a port, andConsoleKitasks a daemon that is not installed.-Dintrospection=false— Generates no GObject introspection data for the polkit libraries, so the build does not need gobject-introspection.-Dman=true— Builds the manual pages (polkit(8),polkitd(8),pkexec(1)and the rest) from DocBook withxsltproc; libxslt, docbook-xsl and docbook-xml are independsfor this.-Dgettext=false—polkitdthen translates an action’s message only from the translations written into its.policyfile, and never looks it up throughdgettextin a message catalogue. It is upstream’s default.-Dgtk_doc=false,-Dexamples=false,-Dtests=false— Build no API reference, no example programs and no test suite. All three are upstream’s defaults.
The common switches of each build system are explained in the Flag glossary.
postinstall.sh runs on the installed system after the package is adopted:
# Everything is written under PKG_ROOT, the root kpkgadd is installing into:
# --root and an A/B update install into a tree that is not the running one, and
# an account made in / instead would be missing from the system that needs it.
#
# The guard reads PKG_ROOT's files: getent answers for the running root, not
# the tree being installed, and would let useradd run against an account the
# target already has.
root="${PKG_ROOT:-/}"
grep -q '^polkitd:' "$root/etc/group" 2>/dev/null || groupadd -R "$root" -r polkitd
grep -q '^polkitd:' "$root/etc/passwd" 2>/dev/null || \
useradd -R "$root" -r -g polkitd -d /nonexistent -s /sbin/nologin polkitd
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/polkit, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf polkit-128-3.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/polkit, and runs the triggers its paths call for.
Contents
Installed programs: pkaction, pkcheck, pkexec, pkttyagent.
Installed libraries: libpolkit-agent-1.so, libpolkit-gobject-1.so.
Installed directories: /etc/polkit-1, /usr/include/polkit-1, /usr/lib/polkit-1, /usr/share/licenses/polkit.
Short descriptions
pkaction |
Get details about a registered action |
pkcheck |
Check whether a process is authorized |
pkexec |
Execute a command as another user |
pkttyagent |
Textual authentication helper |
polkit-agent-1.pc |
PolicyKit Authentication Agent API |
polkit-gobject-1.pc |
PolicyKit Authorization API |
Notes
A process the session bus started is answered for the desktop session. Programs the bus starts, such as plasma-shutdown, KRunner and ksystemstats, run in the seatless session turnstile opens for each user’s services, where polkit would allow them only what any remote session gets and could ask no password. turnstile-session.patch, described in the patch list above, answers them for the user’s display session instead.
The recipe deletes /usr/lib/systemd, /usr/lib/sysusers.d and /usr/lib/tmpfiles.d after the install. With no systemd to find, polkit’s build still installs its unit, account and tmpfiles fragments at fixed default paths, and none of them is read on KDOS. The account they describe is made by the port’s postinstall.sh instead, in the root being installed into; 41_polkitd.sh skips the daemon when the account is missing, because polkitd drops to it after starting and would exit at once without it.
The recipe also deletes /usr/share/dbus-1/system-services/org.freedesktop.PolicyKit1.service, the D-Bus activation file the build installs with no option to leave it out. 41_polkitd.sh supervises polkitd, and with the file a caller that asked for org.freedesktop.PolicyKit1 before the supervised daemon held it (ModemManager does as it starts) would make the bus start a second, unsupervised polkitd; whichever lost the name would exit, and a supervised one that lost would be restarted every five seconds without ever getting it. Without the file the call is refused, and 41_polkitd.sh waits until polkitd holds the name before the scripts after it run.
The rules files are JavaScript, which polkitd runs with duktape, the one JavaScript engine polkit’s build accepts.
elogind is built before polkit and needs none of polkit’s libraries to build: its -Dpolkit=enabled only installs its policy and makes it ask polkitd over D-Bus at run time. So polkit can depend on elogind with no cycle. At boot, 40_elogind.sh runs before 41_polkitd.sh, so the first checks already find the sessions elogind records.