The polkit interface provides daemons with:
See Interface management and Supported interfaces for further details on how interfaces are used.
Auto-connect: no
Super-privileged: yes
Attributes:
${action-prefix}.* .*Note: At least one of action-prefix or install-rules attributes must be set.
To perform polkit authorisation checks, a daemon needs to do two things:
$SNAP/meta/polkit/${plug_name}.*.policy describing the actions it will use (codifying the type of administrative access a user might be granted). Snapd will install the policy file when the plug is connected.CheckAuthorization D-Bus call to polkitd to ask if they have access. The D-Bus call passes a string action ID describing the access, and a “subject” struct describing the client application.There are two primary ways a daemon can describe the subject of the check:
system-bus-name subject, sending the unique bus name of the client app.unix-process subject, sending the process ID (as retrieved through SO_PEERCRED or SCM_CREDENTIALS).See Proposal: add polkit and polkit-agent interfaces to snapd for the original interface proposal and reasoning.
To install polkit rules to the host system, a snap has to include a .rules file to $SNAP/meta/polkit/${plug_name}.*.rules. Snapd will install the rule file when the plug is connected given that there is a corresponding entry under install-rules with the same rule file name and the specified integrity sha3-384 hash matches.
install-rulesFor distribution via the Snap store, snaps that use the polkit interface with the install-rules attribute need an approved snap declaration.
For acceptance, the publisher needs to:
plugs:
polkit:
action-prefix: org.example.foo
install-rules:
- name: polkit.bar.rules
sha3-384: 2YM8oyXyE7xuXR07EXqUpixvr8duiJwgPQqhnxZgrBCU8ZSDowV0Gyujvs1j0-KR
apps:
app:
command: foo
plugs: [polkit]
The test code can be found in the snapd repository: snapd/interfaces/builtin/polkit_test.go at master · canonical/snapd · GitHub
The source code for the interface is in the snapd repository: snapd/interfaces/builtin/polkit.go at master · canonical/snapd · GitHub
Last updated 7 months ago.