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
- Variables
- func NoMCPServerIDs() map[string]string
- func WithResourceName(ctx context.Context, name string) context.Context
- type Checker
- func (c *Checker) CanUseAgent(ctx context.Context, userID string, cfg *llm.BotConfig, ...) error
- func (c *Checker) CanUseMCPServer(ctx context.Context, userID, serverID string) error
- func (c *Checker) CanUseService(ctx context.Context, userID, serviceID string) error
- func (c *Checker) CheckExpression(ctx context.Context, actingUserID, resourceType, expression string) ([]model.CELExpressionError, error)
- func (c *Checker) DeletePolicy(ctx context.Context, actingUserID, resourceType, resourceID string) error
- func (c *Checker) FieldsAutocomplete(ctx context.Context, actingUserID, after string, limit int) ([]*model.PropertyField, error)
- func (c *Checker) GetPolicy(ctx context.Context, resourceID string) (*model.AccessControlPolicy, error)
- func (c *Checker) IsAvailable(ctx context.Context, actingUserID string) bool
- func (c *Checker) RequesterMatchesExpression(ctx context.Context, actingUserID, resourceType, expression string) (bool, error)
- func (c *Checker) SavePolicy(ctx context.Context, ...) (*model.AccessControlPolicy, error)
- func (c *Checker) TestExpression(ctx context.Context, ...) (*model.AccessControlPolicyTestResponse, error)
- func (c *Checker) ValidateAgentWrite(ctx context.Context, actingUserID string, cfg, prev *llm.BotConfig) error
- func (c *Checker) VisualAST(ctx context.Context, actingUserID, resourceType, expression string) (*model.VisualExpression, error)
- type DecisionClient
- type Logger
- type PassthroughClient
- type PluginAPIClient
Constants ¶
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.
const PluginID = "mattermost-ai"
PluginID is the owner segment of every policy type below. Must equal plugin.json's id — TestAccessControlPluginIDMatchesManifest pins that.
Variables ¶
ErrABACUnavailable is returned when saving an agent as attribute-based while ABAC is not available.
var ErrAccessDenied = errors.New("access denied by policy")
ErrAccessDenied is wrapped by every deny return.
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 ¶
NoMCPServerIDs is the empty origin→ID resolver (tests, passthrough).
func WithResourceName ¶ added in v2.10.0
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 (*Checker) CanUseService ¶
func (*Checker) CheckExpression ¶
func (*Checker) DeletePolicy ¶
func (*Checker) FieldsAutocomplete ¶
func (*Checker) IsAvailable ¶
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 (*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.
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.