POLKIT(8) polkit POLKIT(8) (NAME) polkit - (OVERVIEW) polkit API ("MECHANISMS" ) ("SUBJECTS" ) (IPC) . . . API polkit : polkit ( polkit authority). polkit polkitd(8) polkitd . (system message bus) . polkit . . (SYSTEM ARCHITECTURE) polkit (Authority) ( ) (Authentication Agent) ( ) . (Actions) . (Authorization Rules) . [IMAGE][1] +-------------------+ | Authentication | | Agent | +-------------------+ | libpolkit-agent-1 | +-------------------+ ^ +---------+ | | Subject | +--------------+ +---------+ | ^ | | User Session | | =======================|========================|============= System Context | | | | | +---+ V | /------------\ | | System Bus | | \------------/ | ^ ^ V | | +---------------------+ +--------------+ | | Mechanism | | | +---------------------+ V +----> | libpolkit-gobject-1 | +------------------+ +---------------------+ | polkitd(8) | +------------------+ | org.freedesktop. | | PolicyKit1 |<---------+ +------------------+ | ^ | | +--------------------------------------------+ | | /etc/polkit-1/actions/*.policy | | | /run/polkit-1/actions/*.policy | | | /usr/local/share/polkit-1/actions/*.policy | | | /usr/share/polkit-1/actions/*.policy | | +--------------------------------------------+ | +--------------------------------------------+ | /etc/polkit-1/rules.d/*.rules | | /run/polkit-1/rules.d/*.rules | | /usr/local/share/polkit-1/rules.d/*.rules | | /usr/share/polkit-1/rules.d/*.rules | +--------------------------------------------+ libpolkit-gobject-1 API D-Bus polkit C/C++ GObjectIntrospection[2] ( JavaScript Python) . API - pkcheck(1) . libpolkit-agent-1 pam(8) D-Bus polkit . polkit [3] . (AUTHENTICATION AGENTS) ( ) ( ). ( ) . : [IMAGE][4] +----------------------------------------------------------+ | | | [Icon] Authentication required | | | | Authentication is required to format INTEL | | SSDSA2MH080G1GC (/dev/sda) | | | | Administrator | | | | Password: [__________________________________] | | | | [Cancel] [Authenticate] | +----------------------------------------------------------+ root : [IMAGE][5] +----------------------------------------------------------+ | | | [Icon] Authentication required | | | | Authentication is required to format INTEL | | SSDSA2MH080G1GC (/dev/sda) | | | | [Icon] David Zeuthen | | | | Password: [__________________________________] | | | | [Cancel] [Authenticate] | +----------------------------------------------------------+ ( ssh(1) ) . PolkitAgentTextListener pkttyagent(1) . (DECLARING ACTIONS) polkit (actions) . XML /usr/share/polkit-1/actions . polkit (namespaced) "[A-Z][a-z][0-9].-" ASCII . XML .policy . XML (doctype) : policyconfig . policyconfig : vendor XML . . vendor_url XML . . icon_name XML . Freedesktop.org[6] . . action . id "[A-Z][a-z][0-9].-" ASCII . action : description "Install unsigned software" ( ). message "Installing unsigned software requires authentication" ( ). defaults . defaults : allow_any . . allow_inactive . . allow_active . . allow_any allow_inactive allow_active : no . yes . auth_self . *auth_admin . auth_admin . auth_self_keep auth_self ( ) . auth_self . auth_admin_keep auth_admin ( ) . annotate / . key value . . . vendor . . vendor_url . . icon_name . . description message xml:lang . polkit pkaction(1) . (Known annotations) org.freedesktop.policykit.exec.path pkexec polkit - pkexec(1) . org.freedesktop.policykit.imply ( ) (meta actions) . . . org.freedesktop.policykit.owner . root . PolkitIdentity "unix-user:42 unix-user:colord". root . (AUTHORIZATION RULES) polkitd .rules : o /etc/polkit-1/rules.d o /run/polkit-1/rules.d o /usr/local/share/polkit-1/rules.d o /usr/share/polkit-1/rules.d (basename) . . : o /etc/polkit-1/rules.d/10-auth.rules o /run/polkit-1/rules.d/10-auth.rules o /usr/local/share/polkit-1/rules.d/10-auth.rules o /usr/share/polkit-1/rules.d/10-auth.rules . JavaScript[7] polkit ( Polkit) polkitd . polkit ( let) ECMA-262 [8] ( polkit ). : o o . . Polkit (The Polkit type) polkit : void addRule(polkit.Result function(action, subject) {...}); void addAdminRule(string[] function(action, subject) {...}); void log(string message); string spawn(string[] argv); addRule() action subject . . /etc/polkit-1/rules.d 00-early-checks.rules. polkit.Result polkit.Result = { NO : "no", YES : "yes", AUTH_SELF : "auth_self", AUTH_SELF_KEEP : "auth_self_keep", AUTH_ADMIN : "auth_admin", AUTH_ADMIN_KEEP : "auth_admin_keep", NOT_HANDLED : null }; . polkit.Result.NOT_HANDLED null undefined . polkit.Result.AUTH_SELF_KEEP polkit.Result.AUTH_ADMIN_KEEP ( ) ( polkit.Result.YES ) . "*_KEEP" ( Date[9] ). addAdminRule() . action subject . . "unix-group:", "unix-netgroup:" "unix-user:" . null undefined . addRule() addAdminRule() - . ( ). . spawn() argv . . . . spawn() . polkitd . log() message (logger) . LOG_AUTHPRIV /var/log/secure . log() . Action Subject toString() : polkit.addRule(function(action, subject) { if (action.id == "org.freedesktop.policykit.exec") { polkit.log("action=" + action); polkit.log("subject=" + subject); } }); 'pkexec -u bateman bash -i' : May 24 14:28:50 thinkpad polkitd[32217]: /etc/polkit-1/rules.d/10-test.rules:3: action=[Action id='org.freedesktop.policykit.exec' command_line='/usr/bin/bash -i' program='/usr/bin/bash' user='bateman' user.gecos='Patrick Bateman' user.display='Patrick Bateman (bateman)'] May 24 14:28:50 thinkpad polkitd[32217]: /etc/polkit-1/rules.d/10-test.rules:4: subject=[Subject pid=1352 user='davidz' groups=davidz,wheel, seat='seat0' session='1' local=true active=true] Action (The Action type) action . Action : string id org.freedesktop.policykit.exec. Action : string lookup(string key); lookup() polkit . pkexec(1) program action.lookup("program") . key undefined . . Subject (The Subject type) subject . Subject : int pid (PID). int uid (UID) . string user . string[] groups user . string seat (seat) - . string session . string system_unit systemd ( ). ( root ). ( user-1000.service). boolean local true . boolean no_new_privileges system_unit true systemd NoNewPrivileges= . setuid . boolean active true . Subject : boolean isInGroup(string groupName); boolean isInNetGroup(string netGroupName); isInGroup() isInNetGroup() netgroup . (Authorization Rules Examples) admin : polkit.addRule(function(action, subject) { if (action.id == "org.freedesktop.accounts.user-administration" && subject.isInGroup("admin")) { return polkit.Result.YES; } }); wheel : polkit.addAdminRule(function(action, subject) { return ["unix-group:wheel"]; }); children ( org.freedesktop.hostname1. ) : polkit.addRule(function(action, subject) { if (action.id.indexOf("org.freedesktop.hostname1.") == 0) { if (subject.isInGroup("children")) { return polkit.Result.NO; } else { return polkit.Result.AUTH_SELF_KEEP; } } }); : polkit.addRule(function(action, subject) { if (action.id.indexOf("org.freedesktop.login1.reboot") == 0) { try { // user-may-reboot exits with success (exit code 0) // only if the passed username is authorized polkit.spawn(["/opt/company/bin/user-may-reboot", subject.user]); return polkit.Result.YES; } catch (error) { // Nope, but do allow admin authentication return polkit.Result.AUTH_ADMIN; } } }); pkexec(1) : polkit.addRule(function(action, subject) { if (action.id == "org.freedesktop.policykit.exec" && action.lookup("program") == "/usr/bin/cat") { return polkit.Result.AUTH_ADMIN; } }); . UDisks[10] [11] : // Allow users in group 'engineers' to perform any operation on // some drives without having to authenticate // polkit.addRule(function(action, subject) { if (action.id.indexOf("org.freedesktop.udisks2.") == 0 && action.lookup("drive.vendor") == "SEAGATE" && action.lookup("drive.model") == "ST3300657SS" && subject.isInGroup("engineers")) { return polkit.Result.YES; } } }); admin.service systemd : polkit.addRule(function(action, subject) { if (action.id == "org.freedesktop.accounts.user-administration" && subject.system_unit == "admin.service" && subject.no_new_privileges) { return polkit.Result.YES; } }); (AUTHORS) David Zeuthen . (BUGS) polkit-devel : https://github.com/polkit-org/polkit#bugs-and-development. (SEE ALSO) polkitd(8), pkaction(1), pkcheck(1), pkexec(1), pkttyagent(1) (NOTES) 1. /usr/share/gtk-doc/html/polkit-1/polkit-architecture.png 2. GObjectIntrospection https://live.gnome.org/GObjectIntrospection 3. http://www.freedesktop.org/software/polkit/docs/latest 4. /usr/share/gtk-doc/html/polkit-1/polkit-authentication-agent- example.png 5. /usr/share/gtk-doc/html/polkit-1/polkit-authentication-agent- example-wheel.png 6. Freedesktop.org http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec- latest.html 7. JavaScript http://en.wikipedia.org/wiki/JavaScript 8. ECMA-262 http://en.wikipedia.org/wiki/ECMAScript#ECMAScript.2C_5th_Edition 9. Date https://developer.mozilla.org/en- US/docs/Web/JavaScript/Reference/Global_Objects/Date 10. UDisks http://udisks.freedesktop.org/docs/latest/udisks.8.html 11. http://udisks.freedesktop.org/docs/latest/udisks-polkit- actions.html polkit February 2021 POLKIT(8)