authz

package
v0.1.35 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package authz is kafui's local authorization layer: a permission model, an action vocabulary, and a Gate that classifies every datasource operation as allowed or denied for the active cluster profile.

kafui is a single-user local tool, so this is a self-imposed guardrail (like a read-only kubeconfig), not a security boundary — the real enforcement remains broker-side ACLs plus the SASL/TLS credentials in ~/.kaf/config. When no profiles are configured the Gate is disabled and allows everything; read-only mode is an independent switch that always denies altering actions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAltering

func IsAltering(rt ResourceType, action Action) bool

IsAltering reports whether the (resource, action) pair mutates cluster state. Unknown pairs are treated as altering (fail safe: deny under read-only).

func KnownAction

func KnownAction(rt ResourceType, action Action) bool

KnownAction reports whether action is valid for the resource type. The "all" wildcard is considered known for any known resource.

func KnownResource

func KnownResource(rt ResourceType) bool

KnownResource reports whether rt is a recognized resource type.

Types

type Action

type Action string

Action names an operation class. Read actions leave the cluster unchanged; altering actions mutate state and are the ones read-only mode blocks.

const (
	// ActionAll is the wildcard action expanded to every action of a resource.
	ActionAll Action = "all"

	ActionView            Action = "view"
	ActionReadMessages    Action = "read messages"
	ActionProduceMessages Action = "produce messages"
	ActionDeleteMessages  Action = "delete messages"
	ActionRunAnalysis     Action = "run analysis"
	ActionCreate          Action = "create"
	ActionEdit            Action = "edit"
	ActionDelete          Action = "delete"
	ActionResetOffsets    Action = "reset offsets"
	ActionExecute         Action = "execute"
	ActionModifyCompat    Action = "modify compatibility"
	ActionPause           Action = "pause"
	ActionResume          Action = "resume"
	ActionRestart         Action = "restart"
)

func ActionsFor

func ActionsFor(rt ResourceType) []Action

ActionsFor returns every action valid for the resource type (excluding the "all" wildcard), in a stable order (view first).

type EffectivePerm

type EffectivePerm struct {
	Resource ResourceType
	Pattern  string // "" = any name
	Action   Action
}

EffectivePerm is one row of the resolved permission set for the whoami view.

type Gate

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

Gate evaluates permission and read-only checks against the active cluster's profile. It is safe for concurrent use and re-resolves the active profile on SetCluster (called by the guard on context switch).

func NewGate

func NewGate(cfg appconfig.AuthzSettings, readOnly func(cluster string) bool, forceReadOnly bool) (*Gate, error)

NewGate compiles and validates the authz configuration, returning a fail-fast error for empty clusters, permissions missing resource/actions, unknown resources/actions, or invalid name regexes. readOnly reports whether a cluster is configured read-only; forceReadOnly is the global --read-only CLI flag.

func (*Gate) ActiveProfileName

func (g *Gate) ActiveProfileName() string

ActiveProfileName returns the name of the resolved active profile, or "" when authz is disabled or no profile covers the current cluster.

func (*Gate) Allowed

func (g *Gate) Allowed(action Action, rt ResourceType, name string) bool

Allowed is the boolean form of Check, for UI decisions.

func (*Gate) Check

func (g *Gate) Check(action Action, rt ResourceType, name string) error

Check evaluates an action on a resource for the current cluster. It returns api.ClusterReadOnlyError for an altering action on a read-only cluster, api.AccessDeniedError when the active profile denies it, or nil when allowed.

func (*Gate) EffectivePermissions

func (g *Gate) EffectivePermissions() []EffectivePerm

EffectivePermissions returns the flattened, expanded permission set of the active profile, sorted for stable rendering. Empty when authz is disabled or no profile covers the current cluster.

func (*Gate) Enabled

func (g *Gate) Enabled() bool

Enabled reports whether authorization is active (at least one profile or a default profile configured).

func (*Gate) ReadOnly

func (g *Gate) ReadOnly() bool

ReadOnly reports whether the current cluster is read-only.

func (*Gate) SetCluster

func (g *Gate) SetCluster(cluster string)

SetCluster re-resolves the active profile for the named cluster. Called on context switch. The activeProfile override wins; otherwise a profile listing the cluster is used, falling back to the default profile.

type Perm

type Perm struct {
	Resource ResourceType
	Action   Action
}

Perm is a single (resource, action) grant.

func Expand

func Expand(p Perm) []Perm

Expand normalizes a permission into the full set of concrete grants it implies:

  • the "all" wildcard expands to every action of the resource;
  • any non-view action implies view on the same resource;
  • any connector action implies view on the reaching connect-cluster.

type ResourceType

type ResourceType string

ResourceType enumerates the Kafka resource categories kafui can act on.

const (
	ResourceTopic          ResourceType = "topic"
	ResourceConsumerGroup  ResourceType = "consumer-group"
	ResourceSchema         ResourceType = "schema"
	ResourceConnectCluster ResourceType = "connect-cluster"
	ResourceConnector      ResourceType = "connector"
	ResourceSQLEngine      ResourceType = "sql-engine"
	ResourceACL            ResourceType = "acl"
	ResourceAudit          ResourceType = "audit"
	ResourceClientQuota    ResourceType = "client-quotas"
	ResourceClusterConfig  ResourceType = "cluster-configuration"
	ResourceAppConfig      ResourceType = "application-configuration"
)

Jump to

Keyboard shortcuts

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