Files
upstream-mattermost/server/public/model/access_control_decision.go
upstream-mirror 240db4e2a7
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 00:29:55 +05:00

115 lines
5.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"net/http"
"slices"
)
// maxActionSearchActions bounds how many actions a single Action Search request
// may ask about, to prevent unbounded PDP evaluation loops from a single call.
const maxActionSearchActions = 16
// RenderDecisionReasonRestrictedByPolicy is the only denial reason exposed to
// clients. It is intentionally generic: it never reveals policy names,
// expressions, attribute names, or values.
const RenderDecisionReasonRestrictedByPolicy = "restricted_by_policy"
// RenderPermissionDecision is a non-authoritative, render-time ABAC decision for
// a single action. MUST NOT be used to authorize — enforcement always re-evaluates
// the PDP live on the server.
type RenderPermissionDecision struct {
Allowed bool `json:"allowed"`
Evaluated bool `json:"evaluated"`
Reason string `json:"reason,omitempty"`
}
// ActionSearchResultAction is the action identity inside an AuthZEN result entry.
type ActionSearchResultAction struct {
Name string `json:"name"`
}
// ActionSearchResult is the AuthZEN-canonical permitted-action entry.
// Only PERMITTED actions appear in the results list; denial is expressed by omission.
type ActionSearchResult struct {
Action ActionSearchResultAction `json:"action"`
}
// ActionSearchSubject is RESERVED for Phase 3 cross-subject evaluation.
// In Phase 2, any Subject.ID that does not match the authenticated session user is
// rejected with 403. The field is present in the contract to make Phase 3 a
// non-breaking extension of this endpoint.
type ActionSearchSubject struct {
ID string `json:"id"`
Type string `json:"type,omitempty"`
}
// ActionSearchPage is RESERVED for Phase 3 pagination.
// Accepted in requests but always ignored; next_token is never emitted in responses.
type ActionSearchPage struct {
NextToken string `json:"next_token,omitempty"`
}
// ActionSearchRequest asks "for the current session user, on this resource,
// which actions are allowed?".
//
// Actions is optional:
// - nil or empty → discovery mode: the server evaluates all renderable actions
// registered for the resource type and returns the permitted set.
// - non-empty → targeted mode: the server evaluates exactly those actions
// (max 16; all must be registered for the resource type).
//
// Subject is RESERVED. If provided, its ID must equal the authenticated session
// user ID; mismatches are rejected with 403.
//
// Page is RESERVED. Accepted but always ignored.
type ActionSearchRequest struct {
Resource Resource `json:"resource"`
Actions []string `json:"actions,omitempty"` // optional; nil/empty = discovery
Subject *ActionSearchSubject `json:"subject,omitempty"` // reserved
Page *ActionSearchPage `json:"page,omitempty"` // reserved
}
// ActionSearchResponse returns render-time ABAC decisions for the requested resource.
//
// Results is the AuthZEN-canonical list: only actions the server evaluated as
// PERMITTED appear here. An empty Results ([]) is meaningful — all evaluated actions
// were denied — and is always present (never null).
//
// Decisions is the Mattermost extension: all evaluated actions appear here with full
// decision detail (Allowed, Evaluated, Reason), including denied ones. Always present.
//
// Page is RESERVED; always absent in the current implementation.
type ActionSearchResponse struct {
Resource Resource `json:"resource"`
Results []ActionSearchResult `json:"results"` // no omitempty — [] is meaningful
Decisions map[string]RenderPermissionDecision `json:"decisions"` // no omitempty — {} is meaningful
Page *ActionSearchPage `json:"page,omitempty"`
}
// IsValid validates the shape of an Action Search request. It does not validate
// that the actions/resource type are supported for rendering; that allowlist
// check happens in the App layer against the renderable-action registry.
func (r *ActionSearchRequest) IsValid() *AppError {
if r.Resource.Type == "" {
return NewAppError("ActionSearchRequest.IsValid", "model.access_control_decision.is_valid.resource_type.app_error", nil, "", http.StatusBadRequest)
}
if !IsValidId(r.Resource.ID) {
return NewAppError("ActionSearchRequest.IsValid", "model.access_control_decision.is_valid.resource_id.app_error", nil, "", http.StatusBadRequest)
}
// nil/empty Actions = discovery mode (valid). Validate bounds only when non-empty.
if len(r.Actions) > maxActionSearchActions {
return NewAppError("ActionSearchRequest.IsValid", "model.access_control_decision.is_valid.actions_too_many.app_error", map[string]any{"Max": maxActionSearchActions}, "", http.StatusBadRequest)
}
if slices.Contains(r.Actions, "") {
return NewAppError("ActionSearchRequest.IsValid", "model.access_control_decision.is_valid.action_empty.app_error", nil, "", http.StatusBadRequest)
}
// Subject shape validation. Identity check (must match session user) is in the app layer.
if r.Subject != nil && !IsValidId(r.Subject.ID) {
return NewAppError("ActionSearchRequest.IsValid", "model.access_control_decision.is_valid.subject_id.app_error", nil, "", http.StatusBadRequest)
}
return nil
}