capabilities

package
v0.3.5-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package capabilities defines domain types for capability management.

Package capabilities defines domain types for capability management.

Package capabilities defines domain types for capability management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchEnvironmentPattern

func MatchEnvironmentPattern(requested, granted string) bool

MatchEnvironmentPattern checks if an environment variable key matches a capability pattern. Supports exact match ("AWS_REGION"), prefix match ("AWS_*"), and wildcard ("*"). This is the canonical implementation used by both capability enforcement and plugin injection.

Examples:

  • MatchEnvironmentPattern("AWS_REGION", "AWS_REGION") -> true (exact)
  • MatchEnvironmentPattern("AWS_ACCESS_KEY_ID", "AWS_*") -> true (prefix)
  • MatchEnvironmentPattern("PATH", "*") -> true (wildcard)
  • MatchEnvironmentPattern("GCP_PROJECT", "AWS_*") -> false (no match)

Types

type Capability

type Capability struct {
	Kind    string // fs, network, env, exec
	Pattern string // e.g., "/etc/**", "80,443", "AWS_*"
}

Capability represents a permission requirement or grant. This is a pure value object in the domain.

func (Capability) Equals

func (c Capability) Equals(other Capability) bool

Equals checks if two capabilities are equal (value object equality).

func (Capability) IsBroad

func (c Capability) IsBroad() bool

IsBroad returns true if this capability pattern is overly permissive.

func (Capability) IsEmpty

func (c Capability) IsEmpty() bool

IsEmpty returns true if this is a zero-value capability.

func (Capability) RiskDescription

func (c Capability) RiskDescription() string

RiskDescription returns a human-readable explanation of the security risk. This encapsulates domain knowledge about what each capability means.

func (Capability) RiskLevel

func (c Capability) RiskLevel() RiskLevel

RiskLevel returns the security risk level of this capability. This is a core business rule that determines how capabilities are presented to users.

func (Capability) String

func (c Capability) String() string

String returns a human-readable representation of the capability.

type Extractor

type Extractor interface {
	// Extract analyzes the configuration and returns a list of required capabilities.
	Extract(config map[string]interface{}) []Capability
}

Extractor is an interface for extracting capabilities from a plugin configuration. Implementations of this interface contain plugin-specific logic for determining required permissions based on the user's configuration.

type Grant

type Grant []Capability

Grant represents a collection of capabilities granted to a plugin. This acts as a domain entity for managing approved permissions.

func NewGrant

func NewGrant() Grant

NewGrant creates a new empty Grant.

func (*Grant) Add

func (g *Grant) Add(capability Capability)

Add adds a capability to the grant if it's not already present.

func (Grant) Contains

func (g Grant) Contains(capability Capability) bool

Contains checks if the grant contains a specific capability.

func (Grant) ContainsAny

func (g Grant) ContainsAny(caps []Capability) bool

ContainsAny checks if the grant contains any of the given capabilities.

func (*Grant) Remove

func (g *Grant) Remove(capability Capability)

Remove removes a capability from the grant.

type Policy

type Policy struct {
}

Policy represents an authorization policy that determines if a requested operation is allowed. This is a pure domain service.

func NewPolicy

func NewPolicy() *Policy

NewPolicy creates a new domain policy.

func (*Policy) IsGranted

func (p *Policy) IsGranted(request Capability, granted []Capability, cwd string) bool

IsGranted checks if a specific capability (request) is covered by any of the granted capabilities. The cwd parameter must be provided for filesystem capability checks that involve relative paths. Pass an empty string if filesystem checks are not needed or all paths are absolute.

type Registry

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

Registry manages the registration and retrieval of capability extractors.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new, empty capability registry.

func (*Registry) Get

func (r *Registry) Get(pluginName string) (Extractor, bool)

Get retrieves the extractor for a given plugin. Returns nil and false if no extractor is registered.

func (*Registry) Register

func (r *Registry) Register(pluginName string, extractor Extractor)

Register adds a capability extractor for a specific plugin. If an extractor allows overwriting, it will replace any existing one.

type RiskLevel

type RiskLevel int

RiskLevel represents the security risk level of a capability.

const (
	// RiskLevelLow represents minimal security risk (specific, narrow permissions).
	RiskLevelLow RiskLevel = iota
	// RiskLevelMedium represents moderate security risk (network access, read-only sensitive data).
	RiskLevelMedium
	// RiskLevelHigh represents high security risk (broad permissions, arbitrary code execution).
	RiskLevelHigh
)

func (RiskLevel) String

func (r RiskLevel) String() string

String returns a human-readable representation of the risk level.

Jump to

Keyboard shortcuts

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