core

package
v0.13.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthzDisabled                  = fmt.Errorf("authorization is disabled - policy management operations are not available")
	ErrRoleAlreadyExists              = fmt.Errorf("role already exists")
	ErrRoleNotFound                   = fmt.Errorf("role not found")
	ErrRoleInUse                      = fmt.Errorf("role is in use and cannot be deleted")
	ErrRolePolicyMappingAlreadyExists = fmt.Errorf("role policy mapping already exists")
	ErrRolePolicyMappingNotFound      = fmt.Errorf("role policy mapping not found")
	ErrCannotDeleteSystemMapping      = fmt.Errorf("cannot delete system mapping")
	ErrCannotModifySystemMapping      = fmt.Errorf("cannot modify system mapping")
	ErrInvalidRequest                 = fmt.Errorf("invalid request")
)

Functions

This section is empty.

Types

type ActionCapability added in v0.8.0

type ActionCapability struct {
	Allowed []*CapabilityResource `json:"allowed"`
	Denied  []*CapabilityResource `json:"denied"`
}

ActionCapability represents capabilities for a specific action

type BatchEvaluateRequest

type BatchEvaluateRequest struct {
	Requests []EvaluateRequest `json:"requests"`
}

BatchEvaluateRequest represents a batch of authorization requests

type BatchEvaluateResponse

type BatchEvaluateResponse struct {
	Decisions []Decision `json:"decisions"`
}

BatchEvaluateResponse represents a batch of authorization decisions

type CapabilityResource added in v0.8.0

type CapabilityResource struct {
	Path        string       `json:"path"`        // Full resource path: "namespace/acme/project/payment"
	Constraints *interface{} `json:"constraints"` // represents additional instance level restrictions

}

CapabilityResource represents a resource with permission details (SIMPLIFIED)

type Context

type Context struct {
}

Context additional resource instance level context

type Decision

type Decision struct {
	Decision bool             `json:"decision"`
	Context  *DecisionContext `json:"context,omitempty"`
}

Decision represents the authorization decision response

type DecisionContext

type DecisionContext struct {
	Reason string `json:"reason,omitempty"`
}

DecisionContext contains additional context about the decision

type Entitlement added in v0.8.0

type Entitlement struct {
	// Claim is the JWT claim name (e.g., "group", "sub")
	Claim string `json:"claim" yaml:"claim"`

	// Value is the entitlement value (e.g., "admin-group", "service-123")
	Value string `json:"value" yaml:"value"`
}

Entitlement represents an entitlement with its claim and value

type EvaluateRequest

type EvaluateRequest struct {
	SubjectContext *SubjectContext `json:"subject_context"`
	Resource       Resource        `json:"resource"`
	Action         string          `json:"action"`
	Context        Context         `json:"context"`
}

EvaluateRequest represents a single authorization request

type PAP

type PAP interface {
	// AddRole creates a new role with the specified name and actions
	AddRole(ctx context.Context, role *Role) error

	// RemoveRole deletes a role identified by RoleRef
	RemoveRole(ctx context.Context, roleRef *RoleRef) error

	// ForceRemoveRole deletes a role and all its associated role-entitlement mappings
	ForceRemoveRole(ctx context.Context, roleRef *RoleRef) error

	// GetRole retrieves a role identified by RoleRef
	GetRole(ctx context.Context, roleRef *RoleRef) (*Role, error)

	// UpdateRole updates an existing role's actions
	UpdateRole(ctx context.Context, role *Role) error

	// ListRoles returns roles based on the provided filter
	ListRoles(ctx context.Context, filter *RoleFilter) ([]*Role, error)

	// AddRoleEntitlementMapping creates a new role-entitlement mapping with optional conditions
	AddRoleEntitlementMapping(ctx context.Context, mapping *RoleEntitlementMapping) error

	// UpdateRoleEntitlementMapping updates an existing role-entitlement mapping
	UpdateRoleEntitlementMapping(ctx context.Context, mapping *RoleEntitlementMapping) error

	// RemoveRoleEntitlementMapping removes a role-entitlement mapping
	RemoveRoleEntitlementMapping(ctx context.Context, mappingID uint) error

	// ListRoleEntitlementMappings lists role-entitlement mappings with optional filters
	ListRoleEntitlementMappings(ctx context.Context, filter *RoleEntitlementMappingFilter) ([]*RoleEntitlementMapping, error)

	// ListActions lists all defined actions in the system
	ListActions(ctx context.Context) ([]string, error)
}

PAP (Policy Administration Point) interface defines the contract for policy management

type PDP

type PDP interface {
	// Evaluate evaluates a single authorization request and returns a decision
	Evaluate(ctx context.Context, request *EvaluateRequest) (*Decision, error)

	// BatchEvaluate evaluates multiple authorization requests and returns corresponding decisions
	BatchEvaluate(ctx context.Context, request *BatchEvaluateRequest) (*BatchEvaluateResponse, error)

	// GetSubjectProfile retrieves the authorization profile for a given subject
	GetSubjectProfile(ctx context.Context, request *ProfileRequest) (*UserCapabilitiesResponse, error)
}

PDP (Policy Decision Point) interface defines the contract for authorization evaluation

type PolicyEffectType

type PolicyEffectType string

PolicyEffectType defines the effect of a policy: allow or deny

const (
	PolicyEffectAllow PolicyEffectType = "allow"
	PolicyEffectDeny  PolicyEffectType = "deny"
)

type ProfileRequest

type ProfileRequest struct {
	// SubjectContext is the authenticated subject whose profile is being requested
	SubjectContext *SubjectContext `json:"subject_context"`

	// Scope is the resource hierarchy scope for the profile
	Scope ResourceHierarchy `json:"scope"`
}

ProfileRequest represents a request to retrieve a subject's authorization profile

type Resource

type Resource struct {
	Type      string            `json:"type"`
	ID        string            `json:"id,omitempty"`
	Hierarchy ResourceHierarchy `json:"hierarchy"`
}

Resource represents a resource in the authorization request

type ResourceHierarchy

type ResourceHierarchy struct {
	Namespace string `json:"namespace,omitempty"`
	Project   string `json:"project,omitempty"`
	Component string `json:"component,omitempty"`
}

ResourceHierarchy represents a single item in a resource hierarchy

type Role

type Role struct {
	// Name is the unique identifier for the role
	Name string `json:"name"`

	// Actions is the list of actions this role permits
	Actions []string `json:"actions"`

	// Namespace is the namespace for namespace-scoped roles, empty for cluster roles
	Namespace string `json:"namespace,omitempty"`

	// IsInternal indicates if this role should be hidden from public listings
	IsInternal bool `json:"-"`
}

Role represents a role with a set of allowed actions If Namespace is empty, it's a cluster-scoped role; otherwise it's namespace-scoped

type RoleEntitlementMapping

type RoleEntitlementMapping struct {
	// ID is the unique identifier for the mapping
	ID uint `json:"id" yaml:"id,omitempty"`

	// RoleRef identifies the role being assigned
	RoleRef RoleRef `json:"role" yaml:"role"`

	// Entitlement contains the claim and value for this mapping
	Entitlement Entitlement `json:"entitlement" yaml:"entitlement"`

	// Hierarchy defines the resource hierarchy scope where this role applies
	// Empty hierarchy means global scope (*)
	Hierarchy ResourceHierarchy `json:"hierarchy" yaml:"hierarchy,omitempty"`

	// Effect indicates whether the mapping is to allow or deny access
	Effect PolicyEffectType `json:"effect" yaml:"effect"`

	// Context provides optional additional context metadata for this mapping
	Context Context `json:"context" yaml:"context,omitempty"`

	// IsInternal indicates if this mapping should be hidden from public listings
	IsInternal bool `json:"-" yaml:"-"`
}

RoleEntitlementMapping represents the assignment of a role to an entitlement within a hierarchical scope

type RoleEntitlementMappingFilter added in v0.9.0

type RoleEntitlementMappingFilter struct {
	// RoleRef filters mappings by role reference (name and namespace)
	RoleRef *RoleRef

	// Entitlement filters mappings by entitlement claim and value
	Entitlement *Entitlement
}

RoleEntitlementMappingFilter provides filters for listing role-entitlement mappings

type RoleFilter added in v0.12.0

type RoleFilter struct {
	// Namespace filters roles by namespace scope:
	// - "" (empty) = cluster-scoped roles only
	// - "ns1" = namespace-scoped roles in "ns1" only
	// Ignored when IncludeAll is true
	Namespace string

	// IncludeAll when true returns all roles (cluster + all namespaces)
	IncludeAll bool
}

RoleFilter provides filters for listing roles

type RoleRef added in v0.12.0

type RoleRef struct {
	// Name is the role name
	Name string `json:"name" yaml:"name"`

	// Namespace identifies the role scope:
	// - Empty string ("") = cluster-scoped role
	// - Non-empty = namespace-scoped role in the specified namespace
	Namespace string `json:"namespace,omitempty" yaml:"namespace"`
}

RoleRef uniquely identifies a role by name and namespace

type SubjectContext

type SubjectContext struct {
	Type              string   `json:"type"`
	EntitlementClaim  string   `json:"entitlement_claim"`
	EntitlementValues []string `json:"entitlement_values"`
}

SubjectContext represents the authenticated subject making the authorization request

func GetAuthzSubjectContext added in v0.9.0

func GetAuthzSubjectContext(authCtx *auth.SubjectContext) *SubjectContext

GetAuthzSubjectContext converts auth.SubjectContext to authz SubjectContext

type UserCapabilitiesResponse added in v0.8.0

type UserCapabilitiesResponse struct {
	User         *SubjectContext              `json:"user"`
	Capabilities map[string]*ActionCapability `json:"capabilities"`
	GeneratedAt  time.Time                    `json:"evaluatedAt"`
}

UserCapabilitiesResponse represents the complete capabilities response

Jump to

Keyboard shortcuts

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