permissions

package
v2.16.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package permissions defines client roles and the capability lookup that gates privileged API methods.

Three orthogonal properties describe a request's authority:

  • Locality: a connection from the device itself (loopback). Local means "physically at the device" — anyone with OS access owns the whole system anyway, so local connections default to admin.
  • Role: the identity of a paired client, chosen at pairing approval.
  • Session role: a voluntary downgrade a client declares for its own connection (e.g. a kiosk frontend restricting the UI it exposes). Reserved — nothing sets it yet, but the check honors it so kiosk support can land without touching handlers.

Handlers never compare roles directly; they require a capability, and roles map to capability sets. Finer-grained roles later are new map entries, not handler changes.

A remote request with no paired identity (plaintext WebSocket while service.encryption is off) is treated as admin: it predates the permission system and restricting it would break unpaired clients. Setting service.encryption = true requires every remote client to be paired, which is what makes member restrictions enforceable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidRole

func ValidRole(s string) bool

ValidRole reports whether s is a recognized role name.

Types

type Capability

type Capability string

Capability names a privileged operation a handler can require. The guiding rule for what needs a capability: anything that can weaken playtime limits is admin.

const (
	// CapProfilesManage covers creating, updating, and deleting device
	// profiles, and reading profile switch IDs (bearer credentials that
	// authorize PIN-free switching).
	CapProfilesManage Capability = "profiles.manage"
	// CapSettingsWrite covers device settings changes, which include
	// disabling playtime limits and the require-profile launch gate.
	CapSettingsWrite Capability = "settings.write"
)

type Grant

type Grant struct {
	// Role is the paired client's stored role, or "" when the request
	// carries no paired identity.
	Role Role
	// SessionRole is a voluntary downgrade declared by the client for
	// this session. Empty means no downgrade. Reserved for kiosk mode.
	SessionRole Role
	// IsLocal is true for loopback connections.
	IsLocal bool
}

Grant describes the authority of a single request.

func (Grant) Capabilities

func (g Grant) Capabilities() []Capability

Capabilities returns the effective grant's enabled capabilities in stable lexical order. The returned slice is always non-nil.

func (Grant) EffectiveRole

func (g Grant) EffectiveRole() Role

EffectiveRole resolves the request's role: local connections and unpaired remote requests are admin (see the package doc for why), a paired identity uses its stored role (unknown values degrade to member), and a voluntary session downgrade to member always wins.

func (Grant) Has

func (g Grant) Has(capability Capability) bool

Has reports whether the request may perform the given capability.

type Role

type Role string

Role is a paired client's permission level.

const (
	// RoleAdmin grants every capability.
	RoleAdmin Role = "admin"
	// RoleMember grants day-to-day use (browse, launch, switch profile
	// with PIN) but none of the capabilities that could weaken another
	// person's limits.
	RoleMember Role = "member"
)

Jump to

Keyboard shortcuts

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