Linux – How Does GNOME Reboot Without Root Privileges

linuxpolkitrebootsystemd

I am reading the book Linux kernel development, in chapter 5 "System Call Implementation" page 77 says

For example, capable(CAP_SYS_NICE) checks whether the caller has the
ability to modify nice values of other processes. By default, the
superuser possesses all capabilities and nonroot possesses none. For
example, here is the reboot() system call. Note how its first step is
ensuring that the calling process has the CAP_SYS_REBOOT . If that one
conditional statement were removed, any process could reboot the
system.

However, in my Debian Sid I can reboot my machine by using gnome or by executing /sbin/reboot without sudo or su.
How is this possible?

Maybe with systemctl?

ls -l /sbin/reboot 
lrwxrwxrwx 1 root root 14 Jun 28 04:23 /sbin/reboot -> /bin/systemctl

EDIT: My user groups

[damian@xvz:~]$ groups 
damian sudo wireshark bumblebee

EDIT 2: systemctl permissions

[damian@xvz:~]$ ls -l /bin/systemctl 
-rwxr-xr-x 1 root root 626640 Jun 28 04:23 /bin/systemctl

Best Answer

This is done via an authorization manager called polkit:

polkit provides an authorization API intended to be used by privileged programs (“MECHANISMS”) offering service to unprivileged programs (“SUBJECTS”) often through some form of inter-process communication mechanism.

With systemd and polkit users with non-remote session can issue power related commands. You can list all polkit registered actions and get details about any of them with pkaction (invoked with no arguments it will list all action ids).
In this particular case the action id is org.freedesktop.login1.reboot so if you run:

pkaction --action-id org.freedesktop.login1.reboot --verbose

the output should be something like:

org.freedesktop.login1.reboot:
  description:       Reboot the system
  message:           Authentication is required for rebooting the system.
  vendor:            The systemd Project
  vendor_url:        http://www.freedesktop.org/wiki/Software/systemd
  icon:              
  implicit any:      auth_admin_keep
  implicit inactive: auth_admin_keep
  implicit active:   yes

Here, active: yes means the user in the active session is authorized to reboot the system (details about implicit authorizations on polkit page). You can check if your session is active with:

loginctl show-session $XDG_SESSION_ID --property=Active
Active=yes
Related Question