core

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 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: "org/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 by name
	RemoveRole(ctx context.Context, roleName string) error

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

	// GetRole retrieves a role by name
	GetRole(ctx context.Context, roleName string) (*Role, error)

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

	// ListRoles returns all defined roles
	ListRoles(ctx context.Context) ([]*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 {
	Organization      string   `json:"organization,omitempty"`
	OrganizationUnits []string `json:"organization_units,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"`

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

Role represents a role with a set of allowed actions

type RoleEntitlementMapping

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

	// RoleName is the name of the role being assigned
	RoleName string `json:"role_name" yaml:"role_name"`

	// 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
	Hierarchy ResourceHierarchy `json:"hierarchy" yaml:"hierarchy,omitempty"`

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

	// 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 {
	// RoleName filters mappings by role name
	RoleName *string

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

RoleEntitlementMappingFilter provides filters for listing role-entitlement mappings

type SubjectContext

type SubjectContext struct {
	Type              SubjectType `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 SubjectType

type SubjectType string

SubjectType defines the type of subject making the authorization request

const (
	SubjectTypeUser           SubjectType = "user"
	SubjectTypeServiceAccount SubjectType = "service_account"
)

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