rbac

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 10 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"
)

Variables

This section is empty.

Functions

func CheckPermission

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

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 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 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"`
}

User and Role are scalars 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"`
}

The justification rides 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"`
}

Roles omits object-scoped bindings: an owner role is one row per object, so the payload would be unbounded.

func GetEffectivePermissions

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

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"`
}

GET /api/iam/users/{id}/permissions/ answers this 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"`
}

ObjectScoped says the user holds the pattern somewhere, never on what object.

func GetPermissionPatterns

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

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"`
	ChangedBy string `json:"changed_by" table:"Changed By"`
	Reason    string `json:"reason"`
	At        string `json:"at"`
}

func AuditAttributesFrom

func AuditAttributesFrom(entries []RoleAuditLogResponse) []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"`
	AddedAt     time.Time       `json:"added_at"`
}

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.

func GetRoleHistory

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

type RoleHolderAttributes

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

func HolderAttributesFrom

func HolderAttributesFrom(bindings []UserRoleResponse, usernames map[string]string) []RoleHolderAttributes

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)

auto_assigned is a name-suffix match on ':owner', ':master', ':member' and ':manager', not a judgement of assignability: true returns nothing but the object-scoped plumbing roles, and false also hides hand-granted service_token:manager.

func ResolveRole

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

The name filter is exact and case-sensitive. Role lists are narrowed to what the caller may see rather than refused, so an invisible role yields an empty page and never a 403—the not-found message covers both readings.

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

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"`
}

POST /api/rbac/troubleshoot/ reads rather than writes, despite the verb.

type UserRoleAttributes

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

func BindingAttributesFrom

func BindingAttributesFrom(bindings []UserRoleResponse) []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"`
}

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

func FindWorkspaceBinding

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

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

func FindWorkspaceBindingByName

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

Matching by name lets a revoke 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)

The endpoint offers no scope filter, so the workspace-wide row is picked out here. The list is also 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

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

Content types print as their numeric id: the CLI grants nothing object-scoped yet, 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