polkit

package
v0.3.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package polkit is polkitd's Authority (org.freedesktop.PolicyKit1) on the system bus as every lys process uses it: its names declared once, typed subjects, the authorization check with its cancellation, the calls an authentication agent makes, and one context-bounded call path whose errors name the action and the subject.

Index

Constants

View Source
const (
	BusName            = "org.freedesktop.PolicyKit1"
	AuthorityPath      = dbus.ObjectPath("/org/freedesktop/PolicyKit1/Authority")
	AuthorityInterface = BusName + ".Authority"
	AgentInterface     = BusName + ".AuthenticationAgent"
)

The polkit service, its Authority object, and the interfaces of the Authority and of the agent that authenticates for it.

View Source
const (
	ErrFailed    = BusName + ".Error.Failed"
	ErrCancelled = BusName + ".Error.Cancelled"
)

The polkit errors lys tells apart (polkiterror.c): what the Authority answers a refused call and a cancelled check with, and what an agent answers a failed and a cancelled authentication with.

View Source
const CallTimeout = 5 * time.Second

CallTimeout bounds every call to polkitd but CheckAuthorization, whatever the caller's context allows: a polkitd that does not answer never hangs its caller. A check may wait for a person to authenticate and is bounded by its context alone.

View Source
const DismissedDetail = "polkit.dismissed"

DismissedDetail is the detail polkitd sets to "true" when the person asked to authenticate dismissed the dialog.

Variables

Changed is the Authority's signal that actions, authorizations, agents or sessions changed.

Functions

func ChangedMatch

func ChangedMatch() []dbus.MatchOption

ChangedMatch matches Changed from polkitd's Authority.

func Dial

func Dial(ctx context.Context) (*dbus.Conn, error)

Dial connects to the system bus, where polkitd is, giving up when ctx ends or after CallTimeout, whichever comes first; once made, the connection outlives ctx and is the caller's to close.

Types

type Action

type Action string

Action is the id of a polkit action, such as org.freedesktop.policykit.exec.

type ActionDescription

type ActionDescription struct {
	ActionID         string
	Description      string
	Message          string
	VendorName       string
	VendorURL        string
	IconName         string
	ImplicitAny      uint32
	ImplicitInactive uint32
	ImplicitActive   uint32
	Annotations      map[string]string
}

ActionDescription is one registered action as EnumerateActions describes it, (ssssssuuua{ss}): its texts in the locale asked for, and the implicit authorizations of any, inactive and active sessions.

type Authority

type Authority struct {
	// contains filtered or unexported fields
}

Authority is polkitd's Authority object on one connection.

func NewAuthority

func NewAuthority(conn *dbus.Conn) Authority

NewAuthority is polkitd's Authority on conn, the system bus.

func (Authority) CheckAuthorization

func (a Authority) CheckAuthorization(ctx context.Context, subject Subject, action Action, flags CheckFlags) (AuthorizationResult, error)

CheckAuthorization asks polkitd whether subject may perform action. With AllowUserInteraction the call lasts as long as the person takes to authenticate, so it is bounded by ctx alone; when ctx ends first the check is cancelled at polkitd, which takes its dialog down.

func (Authority) EnumerateActions

func (a Authority) EnumerateActions(ctx context.Context, locale string) ([]ActionDescription, error)

EnumerateActions describes every action registered with polkitd, its texts translated to locale.

func (Authority) EnumerateTemporaryAuthorizations

func (a Authority) EnumerateTemporaryAuthorizations(ctx context.Context, subject Subject) ([]TemporaryAuthorization, error)

EnumerateTemporaryAuthorizations lists the authorizations polkitd retains for subject.

func (Authority) RegisterAuthenticationAgent

func (a Authority) RegisterAuthenticationAgent(ctx context.Context, subject Subject, locale string, path dbus.ObjectPath) (dbus.Sequence, error)

RegisterAuthenticationAgent registers the caller's agent, exported at path with AgentInterface, as the one that authenticates for subject, its messages in locale. It returns the sequence of polkitd's reply: a NameOwnerChanged of BusName sequenced before it happened before the registration, one after it is a polkitd that has not seen the agent.

func (Authority) RevokeTemporaryAuthorizationByID

func (a Authority) RevokeTemporaryAuthorizationByID(ctx context.Context, id string) error

RevokeTemporaryAuthorizationByID revokes the one retained authorization id.

func (Authority) RevokeTemporaryAuthorizations

func (a Authority) RevokeTemporaryAuthorizations(ctx context.Context, subject Subject) error

RevokeTemporaryAuthorizations revokes every authorization polkitd retains for subject.

func (Authority) UnregisterAuthenticationAgent

func (a Authority) UnregisterAuthenticationAgent(ctx context.Context, subject Subject, path dbus.ObjectPath) error

UnregisterAuthenticationAgent takes back the registration of the caller's agent at path for subject.

type AuthorityChanged

type AuthorityChanged struct{}

AuthorityChanged is what is read of Changed: nothing. polkitd up to 125 sends it without arguments and polkitd 126 and later with one, a uint16 saying whether it was the sessions that changed (1) or anything else (0), which its introspection data does not declare; either decodes.

type AuthorizationResult

type AuthorizationResult struct {
	IsAuthorized bool
	IsChallenge  bool
	Details      map[string]string
}

AuthorizationResult is polkitd's answer to a check, (bba{ss}).

func (AuthorizationResult) Verdict

func (r AuthorizationResult) Verdict() Verdict

Verdict reads the result.

type CheckFlags

type CheckFlags uint32

CheckFlags are CheckAuthorization's flags.

const AllowUserInteraction CheckFlags = 1

AllowUserInteraction lets polkitd have the subject's authentication agent ask a person to authenticate, and wait for the answer, before it answers the check.

type Subject

type Subject interface {
	fmt.Stringer
	// Wire is the subject as it travels to polkitd.
	Wire() (WireSubject, error)
	// contains filtered or unexported methods
}

Subject is who polkitd decides about, and whom an agent authenticates for: a UnixSession or a UnixProcess.

type TemporaryAuthorization

type TemporaryAuthorization struct {
	ID       string
	ActionID string
	Subject  WireSubject
	Obtained uint64
	Expires  uint64
}

TemporaryAuthorization is one authorization polkitd retains for a while after an authentication, (ss(sa{sv})tt). Obtained is on the monotonic clock and Expires on the wall clock, both in seconds.

type UnixProcess

type UnixProcess struct {
	PID       uint32
	StartTime uint64
	UID       uint32
	PIDFD     *peercred.PIDFD
}

UnixProcess is the unix-process subject: a process by its pid, the start time that tells it from a later process with the same pid, and the uid it runs as. PIDFD, when not nil, names the process itself: polkit 124 and later decide about that process, whatever its pid is reused for, and an older polkitd ignores it. It stays the caller's to close, after the calls that send the subject.

func ProcessOf

func ProcessOf(c peercred.Credentials) (UnixProcess, error)

ProcessOf is the unix-process subject for the peer of a socket, by the pid and uid the kernel recorded when it connected and the start time /proc gives that pid now. Between the two the pid may have been reused: ProcessOfPIDFD closes that window where the kernel has SO_PEERPIDFD.

func ProcessOfPIDFD

func ProcessOfPIDFD(pidfd *peercred.PIDFD) (UnixProcess, error)

ProcessOfPIDFD is the unix-process subject for the peer pidfd names, carrying pidfd. The peer was still running after its start time was read, so that start time is its own and not a later process's with its pid; a peer that has exited is an error.

func (UnixProcess) String

func (p UnixProcess) String() string

String names the process and its user.

func (UnixProcess) Wire

func (p UnixProcess) Wire() (WireSubject, error)

Wire is the process as it travels to polkitd, its pidfd included when it has one.

type UnixSession

type UnixSession struct{ ID logind.SessionID }

UnixSession is the unix-session subject: a logind session.

func (UnixSession) String

func (s UnixSession) String() string

String names the session.

func (UnixSession) Wire

func (s UnixSession) Wire() (WireSubject, error)

Wire is the session as it travels to polkitd.

type Verdict

type Verdict uint8

Verdict is what an AuthorizationResult says.

const (
	Authorized Verdict = iota + 1
	Denied
	Dismissed
	Challenge
)

The verdicts. Challenge says authentication is needed and nobody was asked: the check did not allow interaction, or no agent is registered for the subject.

func (Verdict) String

func (v Verdict) String() string

String names the verdict.

type WireSubject

type WireSubject struct {
	Kind    string
	Details map[string]dbus.Variant
}

WireSubject is a subject as it travels on the bus, (sa{sv}): its kind and that kind's details. It is what an Authority receives, and what polkitd's replies carry.

func (WireSubject) PIDFD

func (w WireSubject) PIDFD() (fd dbus.UnixFD, ok bool)

PIDFD is the pidfd a received unix-process subject carries: a descriptor of the receiver's own, for it to close. ok is false for a subject that carries none.

func (WireSubject) Subject

func (w WireSubject) Subject() (Subject, error)

Subject reads a received subject. A unix-process subject's pidfd is not part of what it returns: PIDFD hands that over.

Directories

Path Synopsis
Package polkittest is a fake polkitd Authority for tests: it answers CheckAuthorization with the result the test sets and records every check and cancel, records agent registrations and refuses a second agent for a subject, as polkit 127 does, describes the actions it is given, keeps temporary authorizations, and counts the calls it answers.
Package polkittest is a fake polkitd Authority for tests: it answers CheckAuthorization with the result the test sets and records every check and cancel, records agent registrations and refuses a second agent for a subject, as polkit 127 does, describes the actions it is given, keeps temporary authorizations, and counts the calls it answers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL