Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

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

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.

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:

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.