authz

package
v0.19.1308 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: AGPL-3.0 Imports: 26 Imported by: 0 modules, 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

Index

Constants

View Source
const NativeCutoverMigration = "native_rbac_cutover"

NativeCutoverMigration is the completion record written by the offline data conversion after validating all cohorts, including an initially empty database.

Variables

View Source
var ErrDenied = errors.New("authorization denied")
View Source
var ErrStandardRoleDrift = errors.New("standard role requires an explicit data migration")

ErrStandardRoleDrift reports a stored standard definition that no longer matches its code template.

Functions

func APIForRoles added in v0.19.1273

func APIForRoles(roles []app.Role) (permissions.API, bool, error)

func APIFromRole added in v0.19.1273

func APIFromRole(role *app.Role) (permissions.API, bool, error)

func CanCreate

func CanCreate(ctx *gin.Context, objectID string) error

func CanDelete

func CanDelete(ctx *gin.Context, objectID string) error

func CanRead

func CanRead(ctx *gin.Context, objectID string) error

func CanUpdate

func CanUpdate(ctx *gin.Context, objectID string) error

func CompatibilityRole

func CompatibilityRole(definition app.RoleDefinition) *app.Role

func DeleteManagedServiceAccountRoles added in v0.19.1290

func DeleteManagedServiceAccountRoles(tx *gorm.DB, accountIDs []string) error

func DeletePrivateRoles added in v0.19.1289

func DeletePrivateRoles(tx *gorm.DB, accountIDs []string) error

func PrivateRoleBlockedAccounts added in v0.19.1290

func PrivateRoleBlockedAccounts(tx *gorm.DB, accountIDs []string) (map[string]struct{}, error)

func ReconcileOrgRoles added in v0.19.1115

func ReconcileOrgRoles(ctx context.Context, db *gorm.DB, org app.Org) error

ReconcileOrgRoles brings an org's managed roles in line with standardOrgRoles: missing roles are created (with their policies), and existing roles have their metadata (title, description, contexts, managed) updated to match the definition. Existing rows' policies are deliberately never modified.

func RequireNativeCutover

func RequireNativeCutover(ctx context.Context, db *gorm.DB) error

func RequireUserManaged added in v0.19.1239

func RequireUserManaged(tx *gorm.DB, accountID string) error

func ScopedRolePolicy added in v0.19.1293

func ScopedRolePolicy(role *app.Role) (permissions.Policy, error)

func WithAuthority

func WithAuthority(ctx context.Context, authority *Authority) context.Context

Types

type AccessContext

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

AccessContext carries authorized operation/target pairs to downstream handlers. Handlers use the captured resource facts to act on the targets that were checked.

func (*AccessContext) Collection

func (a *AccessContext) Collection() (*Selection, error)

func (*AccessContext) Identity

func (a *AccessContext) Identity() Identity

func (*AccessContext) Matches

func (a *AccessContext) Matches(authority *Authority) bool

Matches reports whether these checks used the given authority snapshot.

func (*AccessContext) Require

func (a *AccessContext) Require(requirements ...Requirement) (*AccessContext, error)

Require extends the checked set without modifying the original. Every new check must pass, and repeated references to a resource must agree on its ancestry and relationships, even when checking different operations on that resource.

func (*AccessContext) Requirements

func (a *AccessContext) Requirements() []Requirement

Requirements returns a deep copy of the checked resource facts, preserving the authorization snapshot when callers modify the returned values.

func (*AccessContext) Select

func (a *AccessContext) Select(operation permissions.OperationID, resources *Resources) (*AccessContext, error)

func (*AccessContext) Target

func (a *AccessContext) Target(operation permissions.OperationID) (permissions.Target, error)

Target returns the sole checked target for an operation. Multi-target consumers must use Requirements rather than implicitly selecting one target.

type Authority

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

Authority evaluates operations against a request-local snapshot of native grants. Load it again for each request so subsequent requests observe binding revocation.

func RequestAuthority

func RequestAuthority(ctx cctx.ValueContext) (*Authority, error)

RequestAuthority retrieves the snapshot and verifies that its identity matches the request's authenticated account, credential and selected org.

func (*Authority) Check

Check reports whether the snapshot grants the operation on the resolved target.

func (*Authority) Require

func (a *Authority) Require(requirements ...Requirement) (*AccessContext, error)

Require checks every requirement and returns the checked targets for downstream use. An empty set is denied rather than treated as a successful check.

func (*Authority) RequireCollection

func (a *Authority) RequireCollection(operation permissions.OperationID, resources *Resources) (*AccessContext, error)

func (*Authority) Select

func (a *Authority) Select(operation permissions.OperationID, resources *Resources) (*Selection, error)

type Client

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

func New

func New(params Params) *Client

func (*Client) AddAccountOrgRole

func (h *Client) AddAccountOrgRole(ctx context.Context, roleType app.RoleType, orgID, accountID string) error

func (*Client) AddAccountRoleByID

func (h *Client) AddAccountRoleByID(ctx context.Context, roleID, accountID string) error

func (*Client) AssignableRoles added in v0.19.1115

func (c *Client) AssignableRoles(ctx context.Context, orgID, roleContext string) ([]app.Role, error)

AssignableRoles returns the org's roles offerable on the given assignment surface (see app.RoleContext*), ordered by role type.

func (*Client) CreateOrgRoles

func (c *Client) CreateOrgRoles(ctx context.Context, orgID string) error

func (*Client) EnsureLogStreamRole added in v0.19.1289

func (h *Client) EnsureLogStreamRole(ctx context.Context, orgID, logStreamID, accountID string) error

func (*Client) EnsureManagedServiceAccountRole added in v0.19.1239

func (h *Client) EnsureManagedServiceAccountRole(ctx context.Context, accountID string, want *app.Role) error

func (*Client) EnsurePhoneHomeRole added in v0.19.1299

func (h *Client) EnsurePhoneHomeRole(ctx context.Context, orgID, versionID, accountID string) error

func (*Client) EnsureRunnerJobRole added in v0.19.1299

func (h *Client) EnsureRunnerJobRole(ctx context.Context, orgID, jobID, installID, accountID string) error

EnsureRunnerJobRole grants one job, and the install its runner serves when installID is set, in a single private role.

func (*Client) EnsureRunnerRole added in v0.19.1299

func (h *Client) EnsureRunnerRole(ctx context.Context, orgID, installID, accountID string) error

func (*Client) EnsureStackInstallRole added in v0.19.1149

func (h *Client) EnsureStackInstallRole(ctx context.Context, orgID, installID, accountID string) error

EnsureStackInstallRole converges a stack account's install-scoped role: one role, one policy, on this install's stack object. Looked up through the account's own binding, since the account is already per-install.

func (*Client) EnsureStandardRoles

func (c *Client) EnsureStandardRoles(ctx context.Context, orgID string) error

EnsureStandardRoles seeds an org's standard role definitions from code templates. Drifted definitions are left untouched and reported after missing definitions are seeded. Changing or restoring them requires an explicit data migration.

func (*Client) EnsureTelemetryCollectorRole added in v0.19.1299

func (h *Client) EnsureTelemetryCollectorRole(ctx context.Context, orgID, installID, accountID string) error

func (*Client) LoadAccountPermissions added in v0.19.1289

func (c *Client) LoadAccountPermissions(ctx context.Context, account *app.Account) (*permissions.AccountPermissions, error)

func (*Client) LoadAuthority

func (c *Client) LoadAuthority(ctx context.Context, identity Identity) (*Authority, error)

LoadAuthority builds the request's authority from the account's native bindings in the selected org. It requires an authenticated identity: the caller validates the credential, its account association and its restrictions before loading.

func (*Client) LoadBindingGrants

func (c *Client) LoadBindingGrants(ctx context.Context, orgID, accountID string) ([]*permissions.CompiledGrant, error)

LoadBindingGrants compiles live assignments from a consistent database snapshot. Invalid or stale bindings contribute no authority but remain stored for inspection and restoration. Database errors fail the whole load instead of returning partial grants.

func (*Client) RemoveAccountOrgRoleByType added in v0.19.1149

func (h *Client) RemoveAccountOrgRoleByType(ctx context.Context, roleType app.RoleType, orgID, accountID string) error

RemoveAccountOrgRoleByType drops one role binding, unlike RemoveAccountOrgRoles, which clears every binding in an org.

func (*Client) RemoveAccountOrgRoles

func (h *Client) RemoveAccountOrgRoles(ctx context.Context, orgID, accountID string) error

func (*Client) RequireAnyOrgOperation

func (c *Client) RequireAnyOrgOperation(ctx context.Context, orgID string, operations ...permissions.OperationID) error

RequireAnyOrgOperation authorizes org-level management when the caller has at least one listed capability scoped to the org.

func (*Client) RequireOrgOperation

func (c *Client) RequireOrgOperation(ctx context.Context, orgID string, operation permissions.OperationID) error

func (*Client) RequireOrgRoleGrant

func (c *Client) RequireOrgRoleGrant(ctx context.Context, orgID, roleID string) error

RequireOrgRoleGrant verifies that the caller has org-wide authority for every operation in the role. Callers also authorize the management operation and hold the relevant locks through both checks and the mutation.

func (*Client) ResolveAssignableRole added in v0.19.1115

func (c *Client) ResolveAssignableRole(ctx context.Context, orgID string, roleType app.RoleType, roleContext string) (*app.Role, error)

ResolveAssignableRole validates that roleType is offerable on the given surface in the org and returns its role row. The error lists the roles that are assignable there.

func (*Client) SetAccountOrgRole added in v0.19.1075

func (h *Client) SetAccountOrgRole(ctx context.Context, orgID, accountID string, roleType app.RoleType) error

SetAccountOrgRole replaces an account's role(s) in an org with a single role of the given type. Unlike RemoveAccountOrgRoles it does not touch the account's OrgInvite records, so it is safe for in-place role changes.

func (*Client) StandardRole

func (c *Client) StandardRole(ctx context.Context, orgID string, key roles.Key) (*app.RoleDefinition, error)

func (*Client) ValidateBindingScope

func (c *Client) ValidateBindingScope(ctx context.Context, binding app.RoleBinding) error

type Identity

type Identity struct {
	AccountID    string
	CredentialID string
	OrgID        string
}

Identity ties an authority snapshot to an authenticated credential and selected org.

type OrgRoleClassification added in v0.19.1295

type OrgRoleClassification struct {
	Status      string
	Reason      string
	Permissions permissions.PermissionSet
	LegacyAPI   *permissions.API
	Policy      *permissions.Policy
}

func ClassifyOrgRole added in v0.19.1295

func ClassifyOrgRole(source OrgRoleSnapshot) (OrgRoleClassification, error)

type OrgRoleSnapshot added in v0.19.1295

type OrgRoleSnapshot struct {
	Role     app.Role
	Bindings []app.AccountRole
}

type Params

type Params struct {
	fx.In

	Cfg             *internal.Config
	DB              *gorm.DB `name:"psql"`
	V               *validator.Validate
	AnalyticsClient analytics.Writer
}

type Requirement

type Requirement struct {
	Operation permissions.OperationID
	Target    permissions.Target
}

Requirement pairs an operation with a canonical target resolved by the caller. Target ownership and ancestry come from trusted resource lookups.

type Resources

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

Resources describes a domain-owned query of live resources and their verified ancestry. The query projects id, org_id, app_id, install_id, runner_job_id and runner_id, using NULL for absent relationships and one row per association. Callers apply pagination and aggregation to the filtered consumer query.

func NewResources

func NewResources(query *gorm.DB, kind permissions.ResourceKind, orgID string) (*Resources, error)

type Selection

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

Selection applies authorized resource IDs to a consumer query. Applying its scope during query execution records consumption for the transport guard.

func (*Selection) Applied

func (s *Selection) Applied() bool

func (*Selection) Scope

func (s *Selection) Scope(column clause.Column) func(*gorm.DB) *gorm.DB

Scope filters the consumer's ID column before its count, pagination or aggregate. Pass a qualified column when the consumer selects a child or joins other tables.

Directories

Path Synopsis
Package require applies existing RBAC permissions to HTTP routes and non-HTTP callers.
Package require applies existing RBAC permissions to HTTP routes and non-HTTP callers.

Jump to

Keyboard shortcuts

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