accesscontrol

package
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 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 accesscontrol is the plugin-side PEP for ABAC over agents, LLM services, and external MCP servers.

Any failure to obtain a decision is an error, and every error denies. An allow with the no_policy reason is vacuous: legacy-mode agents fall through to their allow/block checks, and services and MCP servers are unrestricted. Attribute-based agents deny: the policy is the sole user- access gate, so a missing policy is not a grant.

Enforcement call sites: bots/ (agent+service gate), mcp/ (per-user server filtering), api/ (authoring, list filters), mcpserver/ (external HTTP tool filtering).

Index

Constants

View Source
const (
	ResourceTypeAgent   = PluginID + model.PluginAccessControlPolicyTypeSeparator + "agent"
	ResourceTypeService = PluginID + model.PluginAccessControlPolicyTypeSeparator + "service"
	ResourceTypeMCP     = PluginID + model.PluginAccessControlPolicyTypeSeparator + "mcp"

	// ActionUse is plugin-defined; the server validates an action's format,
	// not its meaning.
	ActionUse = "use"
)

Resource types compose against the platform's separator. There is no server-side registry; the server treats both segments opaquely.

View Source
const PluginID = "mattermost-ai"

PluginID is the owner segment of every policy type below. Must equal plugin.json's id — TestAccessControlPluginIDMatchesManifest pins that.

Variables

View Source
var ErrABACUnavailable = errors.New("attribute-based access requires Attribute-Based Access Control to be licensed and enabled on this server")

ErrABACUnavailable is returned when saving an agent as attribute-based while ABAC is not available.

View Source
var ErrAccessDenied = errors.New("access denied by policy")

ErrAccessDenied is wrapped by every deny return.

View Source
var ErrPolicyNotFound = errors.New("access policy not found")

ErrPolicyNotFound is returned when no plugin-owned policy is stored under the resource ID.

Functions

func NoMCPServerIDs

func NoMCPServerIDs() map[string]string

NoMCPServerIDs is the empty origin→ID resolver (tests, passthrough).

func WithResourceName added in v2.10.0

func WithResourceName(ctx context.Context, name string) context.Context

WithResourceName returns a ctx that labels the next policy check's span with the resource's display name (e.g. an MCP server name), so a denied resource can be identified without looking its ID up in the config.

Types

type Checker

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

Checker is the plugin-side PEP; PAP methods live here so api never holds a raw plugin.API.

func New

func New(client DecisionClient, papi plugin.API, mcpIDsByOrigin func() map[string]string, log Logger) *Checker

New builds a Checker. papi may be nil in decision-only tests. mcpIDsByOrigin must be non-nil (use NoMCPServerIDs).

func (*Checker) CanUseAgent

func (c *Checker) CanUseAgent(ctx context.Context, userID string, cfg *llm.BotConfig, legacyCheck func() error) error

CanUseAgent combines the resource policy with cfg.UserAccessLevel. Attribute-based mode never invokes legacyCheck: an explicit allow grants, and no_policy (including a missing policy, or a non-addressable agent ID) denies. Any failure to obtain a decision denies in every agent mode.

func (*Checker) CanUseMCPServer

func (c *Checker) CanUseMCPServer(ctx context.Context, userID, serverID string) error

func (*Checker) CanUseService

func (c *Checker) CanUseService(ctx context.Context, userID, serviceID string) error

func (*Checker) CheckExpression

func (c *Checker) CheckExpression(ctx context.Context, actingUserID, resourceType, expression string) ([]model.CELExpressionError, error)

func (*Checker) DeletePolicy

func (c *Checker) DeletePolicy(ctx context.Context, actingUserID, resourceType, resourceID string) error

func (*Checker) FieldsAutocomplete

func (c *Checker) FieldsAutocomplete(ctx context.Context, actingUserID, after string, limit int) ([]*model.PropertyField, error)

func (*Checker) GetPolicy

func (c *Checker) GetPolicy(ctx context.Context, resourceID string) (*model.AccessControlPolicy, error)

func (*Checker) IsAvailable

func (c *Checker) IsAvailable(ctx context.Context, actingUserID string) bool

IsAvailable reports whether the ABAC PAP is usable. Only a non-nil VisualAST means available (past the server's readiness gate). Cached for availabilityCacheTTL.

A policy-read probe is unsound: the server 404s an absent row before consulting license or ABAC config, so an unlicensed enterprise binary would look available.

func (*Checker) RequesterMatchesExpression

func (c *Checker) RequesterMatchesExpression(ctx context.Context, actingUserID, resourceType, expression string) (bool, error)

RequesterMatchesExpression is the plugin-API stand-in for core's ValidateExpressionAgainstRequester. The pinned plugin surface exposes QueryUsersForAccessControlExpression but not SubjectID or ExcludeNativeAttributes, so this probes with the acting user's username. Unlike Channel Settings, native-only rules (e.g. email verified) are not skipped here and may fail self-inclusion where core would pass.

func (*Checker) SavePolicy

func (c *Checker) SavePolicy(ctx context.Context, actingUserID, resourceType, resourceID, defaultName string, policy *model.AccessControlPolicy) (*model.AccessControlPolicy, error)

SavePolicy overwrites ID/Type/Version/Active from the route and persists in one plugin-API call — the server owns policy existence.

func (*Checker) TestExpression

func (c *Checker) TestExpression(ctx context.Context, actingUserID, resourceType, expression, term, cursorID string, limit int) (*model.AccessControlPolicyTestResponse, error)

func (*Checker) ValidateAgentWrite

func (c *Checker) ValidateAgentWrite(ctx context.Context, actingUserID string, cfg, prev *llm.BotConfig) error

ValidateAgentWrite rejects attribute-based mode when ABAC is unavailable, and newly-assigned service/MCP refs the acting user may not use. prev is nil on create; only changed assignments are checked. AutoEnableNewMCPTools skips write-time MCP checks — runtime per-user filtering is the gate. System admins author MCP server policies, so they may assign servers they cannot use themselves; runtime per-user filtering still applies.

func (*Checker) VisualAST

func (c *Checker) VisualAST(ctx context.Context, actingUserID, resourceType, expression string) (*model.VisualExpression, error)

type DecisionClient

type DecisionClient interface {
	EvaluateAccessRequest(ctx context.Context, userID, resourceType, resourceID, action string) (*model.AccessDecision, error)
}

DecisionClient abstracts plugin.API.EvaluateAccessControl so Checker logic is testable.

type Logger

type Logger interface {
	Debug(message string, keyValuePairs ...any)
	Error(message string, keyValuePairs ...any)
}

Logger is satisfied by *pluginapi.LogService. A nil Logger disables logging (tests).

type PassthroughClient

type PassthroughClient struct{}

PassthroughClient reports no_policy for every resource. Tests that need an explicit grant must stub DecisionClient; attribute-based agents deny on no_policy. Services and MCP servers stay unrestricted, matching production when no policy exists.

func (PassthroughClient) EvaluateAccessRequest

func (PassthroughClient) EvaluateAccessRequest(_ context.Context, _, _, _, _ string) (*model.AccessDecision, error)

type PluginAPIClient

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

func NewPluginAPIClient

func NewPluginAPIClient(papi plugin.API) *PluginAPIClient

func (*PluginAPIClient) EvaluateAccessRequest

func (c *PluginAPIClient) EvaluateAccessRequest(ctx context.Context, userID, resourceType, resourceID, action string) (*model.AccessDecision, error)

EvaluateAccessRequest proxies one PDP call. ctx is span-only; the plugin RPC hop carries no context. A missing decision is an error (checkers deny).

No span of its own: every caller is a checker whose span already carries the user, resource and outcome, and a second span per decision doubled the volume of the noisiest span family. Failures are recorded on the caller's span.

Jump to

Keyboard shortcuts

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