rbac

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 11 Imported by: 1 module, 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 (

	// Platform tiers: the server mirrors them onto the legacy is_staff/is_superuser flags,
	// creates the admin companion when superuser is granted, and refuses to leave a workspace
	// without a holder of either.
	RoleAdmin     = "admin"
	RoleSuperuser = "superuser"

	CodeRoleAssignmentDuplicate = "rbac_role_assignment_duplicate"
)
View Source
const (
	ReachOrg   = api.ReachOrg
	ReachBound = api.ReachBound
	ReachSelf  = api.ReachSelf
	ReachNone  = api.ReachNone
)

Variables

View Source
var ErrBlankName = api.ErrBlankName

ErrBlankName is re-exported so a caller can tell ResolveRole's blank-name refusal from an ordinary not-found.

View Source
var ErrNotFound = api.ErrNotFound

ErrNotFound is re-exported for the same reason: ResolveRole's miss, told from a failed request.

Functions

func CheckPermission

func CheckPermission(ac *client.AlpaconClient, userID, permission string) (bool, error)

CheckPermission asks a workspace-wide question only: a permission held through an object-scoped binding answers false here, because no object is named.

func ExplainPermission

func ExplainPermission(ac *client.AlpaconClient, userID, permission string) ([]byte, error)

func GetRoleHistory

func GetRoleHistory(ac *client.AlpaconClient, userID string, limit int) ([]RoleAuditLogResponse, Reach, error)

GetRoleHistory returns the rows whose subject is the user, and the reach the server read them at. The filter keeps only that user's rows; the reach decides which of them come back.

func GrantRole

func GrantRole(ac *client.AlpaconClient, request BindingCreateRequest) error

func HoldsWorkspaceRole

func HoldsWorkspaceRole(bindings []UserRoleResponse, roleName string) bool

func IsDuplicateBinding

func IsDuplicateBinding(err error) bool

func IsPlatformTier

func IsPlatformTier(roleName string) bool

func RevokeRole

func RevokeRole(ac *client.AlpaconClient, bindingID, reason string) error

func WorkspaceRoleNames

func WorkspaceRoleNames(bindings []UserRoleResponse) []string

Types

type AuditActor

type AuditActor struct {
	ID    *string `json:"id"`
	Label string  `json:"label"`
}

type AuditContext added in v1.20.0

type AuditContext struct {
	// ScopeContentType names the binding target's kind as a dotted label, e.g. servers.server.
	// It stays on a row whose target is withheld: it names a kind, not an object.
	ScopeContentType *string
	// ScopeObjectID is the target's id as sent; a number is kept as its text.
	ScopeObjectID *string
	// Erased marks a row whose personal data was erased, so an empty Reason is not one never
	// given. Only a JSON true counts.
	Erased bool
}

AuditContext is the part of a row's context the CLI reads; the server may send more keys. It decodes leniently, a key of another shape reading as absent, so one odd row cannot fail a page.

func (*AuditContext) UnmarshalJSON added in v1.20.0

func (c *AuditContext) UnmarshalJSON(data []byte) error

type AuditPrincipal

type AuditPrincipal struct {
	Type  *string `json:"type"`
	ID    string  `json:"id"`
	Label string  `json:"label"`
}

type BindingCreateRequest

type BindingCreateRequest struct {
	User        string   `json:"user"`
	Role        string   `json:"role"`
	ContentType *int     `json:"content_type,omitempty"`
	ObjectID    []string `json:"object_id,omitempty"`
	Reason      string   `json:"reason,omitempty"`
}

BindingCreateRequest keeps User and Role scalar on purpose: more than one value in any of the three fields flips the server onto a bulk path that answers 201 with an empty body even when it created nothing, and never reports a duplicate. ContentType and ObjectID are unset for now, kept for later object-scoped writes.

type BindingRevokeRequest

type BindingRevokeRequest struct {
	Reason string `json:"reason"`
}

BindingRevokeRequest carries the justification in the DELETE body, not a query parameter, so it stays out of access and proxy logs.

type EffectivePermissionsResponse

type EffectivePermissionsResponse struct {
	User        types.UserSummary  `json:"user"`
	Summary     EffectiveSummary   `json:"summary"`
	Roles       []EffectiveRole    `json:"roles"`
	Permissions RoleScopesResponse `json:"permissions"`
}

EffectivePermissionsResponse omits object-scoped bindings from Roles: their number grows with the number of objects, so the payload would be unbounded.

func GetEffectivePermissions

func GetEffectivePermissions(ac *client.AlpaconClient, userID string) (*EffectivePermissionsResponse, error)

GetEffectivePermissions reads the IAM user endpoint, not /api/rbac/: an API token reaches it where the RBAC routes refuse one.

type EffectiveRole

type EffectiveRole struct {
	Role RoleNested `json:"role"`
	// Source is "user" for a role bound directly, "group" for one inherited.
	Source string       `json:"source"`
	Group  *GroupNested `json:"group"`
	// Scope is "global" or "content_type"; see EffectivePermissionsResponse.
	Scope string `json:"scope"`
}

type EffectiveRoleAttributes

type EffectiveRoleAttributes struct {
	Role   string `json:"role"`
	Source string `json:"source"`
	Group  string `json:"group"`
	Scope  string `json:"scope"`
}

func EffectiveRoleAttributesFrom

func EffectiveRoleAttributesFrom(roles []EffectiveRole) []EffectiveRoleAttributes

type EffectiveSummary

type EffectiveSummary struct {
	PermissionCount int `json:"permission_count"`
	RoleCount       int `json:"role_count"`
	GroupCount      int `json:"group_count"`
}

type GroupNested

type GroupNested struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
}

type PermissionCheckResponse

type PermissionCheckResponse struct {
	Allowed bool `json:"allowed"`
}

PermissionCheckResponse is what GET /api/iam/users/{id}/permissions/ answers when a permission query parameter is sent.

type PermissionPatternAttributes

type PermissionPatternAttributes struct {
	Permission string `json:"permission"`
	Scope      string `json:"scope"`
}

func PermissionPatternAttributesFrom

func PermissionPatternAttributesFrom(patterns *PermissionPatternsResponse) []PermissionPatternAttributes

type PermissionPatternsResponse

type PermissionPatternsResponse struct {
	Global       []string `json:"global"`
	ObjectScoped []string `json:"object_scoped"`
}

PermissionPatternsResponse splits patterns by scope; ObjectScoped says the user holds the pattern somewhere, never on what object.

func GetPermissionPatterns

func GetPermissionPatterns(ac *client.AlpaconClient, userID string) (*PermissionPatternsResponse, error)

type Reach added in v1.20.0

type Reach = api.Reach

Reach and its values are re-exported so a caller of GetRoleHistory need not import api.

type RoleAttributes

type RoleAttributes struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

func RoleAttributesFrom

func RoleAttributesFrom(roles []RoleResponse) []RoleAttributes

type RoleAuditAttributes

type RoleAuditAttributes struct {
	Action        string          `json:"action"`
	Role          string          `json:"role"`
	Scope         string          `json:"scope"`
	Target        string          `json:"-" table:"Target"`
	TargetType    *string         `json:"target_type" table:"-"`
	TargetID      *string         `json:"target_id" table:"-"`
	TargetsHidden int             `json:"targets_hidden" table:"-"`
	ChangedBy     string          `json:"changed_by" table:"Changed By"`
	Reason        string          `json:"reason" table:"-"`
	Erased        bool            `json:"erased" table:"-"`
	ReasonCell    string          `json:"-" table:"Reason"`
	At            utils.Timestamp `json:"at"`
}

RoleAuditAttributes keeps Target and ReasonCell for the table alone, which word a hidden target or a withheld or erased reason; JSON carries the fields as sent, so an empty reason stays "" and a withheld target_id stays null.

func AuditAttributesFrom

func AuditAttributesFrom(entries []RoleAuditLogResponse, zone *time.Location) []RoleAuditAttributes

type RoleAuditLogResponse

type RoleAuditLogResponse struct {
	ID          string          `json:"id"`
	RecordClass string          `json:"record_class"`
	Action      string          `json:"action"`
	Role        *RoleNested     `json:"role"`
	RoleName    string          `json:"role_name"`
	Principal   *AuditPrincipal `json:"principal"`
	Scope       string          `json:"scope"`
	ChangedBy   *AuditActor     `json:"changed_by"`
	Reason      string          `json:"reason"`
	Context     AuditContext    `json:"context"`
	// TargetsHidden counts the binding targets withheld from this reader, whose id is then left
	// out of Context and whose Reason is sent empty; a server that predates it decodes as 0.
	TargetsHidden int       `json:"targets_hidden"`
	AddedAt       time.Time `json:"added_at"`
}

RoleAuditLogResponse is the only surface carrying the justification and the actor—a binding read carries neither. Role, Principal and ChangedBy answer null where there is nothing left to name, so the row keeps value snapshots like RoleName.

type RoleHolderAttributes

type RoleHolderAttributes struct {
	User      string          `json:"user"`
	Scope     string          `json:"scope"`
	GrantedAt utils.Timestamp `json:"granted_at" table:"Granted At"`
}

func HolderAttributesFrom

func HolderAttributesFrom(bindings []UserRoleResponse, usernames map[string]string, zone *time.Location) []RoleHolderAttributes

HolderAttributesFrom labels holders by username. A nil usernames map means names were never resolved, so the id—the value other commands accept—stands in; the display name is a fallback only when resolution ran and missed.

type RoleNested

type RoleNested struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type RoleResponse

type RoleResponse struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	AddedAt     time.Time `json:"added_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func GetRoleCatalog

func GetRoleCatalog(ac *client.AlpaconClient, autoAssigned *bool) ([]RoleResponse, error)

GetRoleCatalog sends auto_assigned when set, asking the server which roles it counts as assigned on its own; false is not a list of what the caller may grant. Which roles count differs by Alpacon release and the response carries no such field, so only the server can tell.

func ResolveRole

func ResolveRole(ac *client.AlpaconClient, nameOrID string) (*RoleResponse, error)

type RoleScopeAttributes

type RoleScopeAttributes struct {
	Name    string `json:"name" table:"Resource"`
	Actions string `json:"actions"`
	ACL     string `json:"acl" table:"ACL"`
}

func ScopeAttributesFrom

func ScopeAttributesFrom(scopes *RoleScopesResponse) []RoleScopeAttributes

ScopeAttributesFrom lists wildcards first: they subsume the concrete rows below them.

type RoleScopeResource

type RoleScopeResource struct {
	Name    string   `json:"name"`
	Actions []string `json:"actions"`
	ACL     []string `json:"acl"`
}

type RoleScopesResponse

type RoleScopesResponse struct {
	Resources []RoleScopeResource `json:"resources"`
	Wildcards []string            `json:"wildcards"`
}

func GetRoleScopes

func GetRoleScopes(ac *client.AlpaconClient, roleID string) (*RoleScopesResponse, error)

type TroubleshootRequest

type TroubleshootRequest struct {
	UserID     string `json:"user_id"`
	Permission string `json:"permission"`
}

TroubleshootRequest is the body of POST /api/rbac/troubleshoot/, which reads rather than writes, despite the verb.

type UserRoleAttributes

type UserRoleAttributes struct {
	Role      string          `json:"role"`
	Scope     string          `json:"scope"`
	GrantedAt utils.Timestamp `json:"granted_at" table:"Granted At"`
}

func BindingAttributesFrom

func BindingAttributesFrom(bindings []UserRoleResponse, zone *time.Location) []UserRoleAttributes

type UserRoleResponse

type UserRoleResponse struct {
	ID          string            `json:"id"`
	User        types.UserSummary `json:"user"`
	Role        RoleNested        `json:"role"`
	ContentType *int              `json:"content_type"`
	ObjectID    *string           `json:"object_id"`
	AddedAt     time.Time         `json:"added_at"`
	UpdatedAt   time.Time         `json:"updated_at"`
}

UserRoleResponse is a role binding. Only a workspace-wide binding makes someone an admin or a superuser.

func FindWorkspaceBinding

func FindWorkspaceBinding(bindings []UserRoleResponse, roleID string) *UserRoleResponse

FindWorkspaceBinding returns the user's workspace-wide binding of roleID. The server refuses a second binding of the same role with both scope fields unset, so the first match is the only one.

func FindWorkspaceBindingByName

func FindWorkspaceBindingByName(bindings []UserRoleResponse, roleName string) *UserRoleResponse

FindWorkspaceBindingByName matches by name, so a revoke can find the admin companion without resolving a second role.

func GetRoleHolders

func GetRoleHolders(ac *client.AlpaconClient, roleID string) ([]UserRoleResponse, error)

func GetUserBindings

func GetUserBindings(ac *client.AlpaconClient, userID string) ([]UserRoleResponse, error)

GetUserBindings lists the user's bindings at every scope; the endpoint offers no scope filter. The list is narrowed to what the caller may see and answered 200, never 403, so an empty result reads exactly like "holds nothing"—no caller may take it as proof of absence.

func (UserRoleResponse) IsWorkspaceWide

func (b UserRoleResponse) IsWorkspaceWide() bool

IsWorkspaceWide reports whether b is unscoped. An unscoped binding answers null or an empty ObjectID, so a nil check alone would miss one.

func (UserRoleResponse) ScopeLabel

func (b UserRoleResponse) ScopeLabel() string

ScopeLabel prints content types as their numeric id: no CLI command grants an object-scoped role, so resolving names via /api/rbac/content-types/ would not earn a request.

Jump to

Keyboard shortcuts

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