usermodel

package
v0.1.38 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 4 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

Overview

Package usermodel provides user domain models.

Index

Constants

View Source
const (
	IdentityProviderGitHub = "github"
	IdentityProviderGoogle = "google"
	IdentityProviderLDAP   = "ldap"
	IdentityProviderOIDC   = "oidc"
	IdentityProviderBasic  = "basic"
)

IdentityProvider constants for supported authentication providers.

View Source
const (
	ActionGet    = "GET"
	ActionList   = "LIST"
	ActionCreate = "CREATE"
	ActionUpdate = "UPDATE"
	ActionDelete = "DELETE"
)

Actions for RBAC permission checks.

View Source
const (
	ResourceAgent             = "agent"
	ResourceAgentGroup        = "agentgroup"
	ResourceAgentPackage      = "agentpackage"
	ResourceAgentRemoteConfig = "agentremoteconfig"
	ResourceCertificate       = "certificate"
	ResourceRoleBinding       = "rolebinding"
)

Namespace-scoped resource types controlled by RBAC.

View Source
const (
	ResourceServer     = "server"
	ResourceUser       = "user"
	ResourceRole       = "role"
	ResourcePermission = "permission"
)

Global resource types (not namespace-scoped).

View Source
const (
	RoleSuperAdmin = "SuperAdmin"
	RoleAdmin      = "Admin"
	RoleViewer     = "Viewer"
	RoleDefault    = "default" // default role assigned to all new users; undeletable but permissions can be changed
)

Built-in role names.

View Source
const (
	LabelLoginType = "login-type"  // e.g. "github", "basic"
	LabelGitHubOrg = "github-org-" // prefix; full key = "github-org-{orgname}"
)

Label keys added to users on login.

View Source
const DefaultNamespace = "default"

DefaultNamespace is the namespace used for built-in default role assignments.

View Source
const SubjectKindUser = "User"

SubjectKindUser identifies a Subject that names an individual user by email.

View Source
const WildcardAll = "*"

WildcardAll represents a wildcard matching all values in RBAC policies.

Variables

This section is empty.

Functions

func AllActions

func AllActions() []string

AllActions returns all RBAC actions.

func NamespaceScopedResources

func NamespaceScopedResources() []string

NamespaceScopedResources returns all namespace-scoped resources controlled by RBAC.

func ReadOnlyActions

func ReadOnlyActions() []string

ReadOnlyActions returns read-only RBAC actions.

Types

type Permission

type Permission struct {
	Metadata PermissionMetadata
	Spec     PermissionSpec
	Status   PermissionStatus
}

Permission represents a permission in the system.

func NewPermission

func NewPermission(resource, action string, isBuiltIn bool) *Permission

NewPermission creates a new permission with the given resource and action.

func (*Permission) Delete

func (p *Permission) Delete()

Delete marks the permission as deleted.

func (*Permission) IsDeleted

func (p *Permission) IsDeleted() bool

IsDeleted returns whether the permission is deleted.

func (*Permission) Restore

func (p *Permission) Restore()

Restore removes the deletion mark from the permission.

type PermissionMetadata

type PermissionMetadata struct {
	UID       uuid.UUID
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

PermissionMetadata contains metadata about the permission.

type PermissionSpec

type PermissionSpec struct {
	Name        string // e.g., "agent:read", "agent:write"
	Description string
	Resource    string // e.g., "agent", "agentgroup", "certificate"
	Action      string // e.g., "read", "write", "delete", "execute"
	IsBuiltIn   bool
}

PermissionSpec defines the permission details.

type PermissionStatus

type PermissionStatus struct {
	Conditions []model.Condition
}

PermissionStatus represents the current state of the permission.

type RBACPolicy

type RBACPolicy struct {
	Metadata RBACPolicyMetadata
	Spec     RBACPolicySpec
	Status   RBACPolicyStatus
}

RBACPolicy represents RBAC policy rules stored in the system. This model is used to persist Casbin policy rules to MongoDB.

func NewRBACPolicy

func NewRBACPolicy(policyType string, rules [][]string) *RBACPolicy

NewRBACPolicy creates a new RBAC policy.

func (*RBACPolicy) AddRule

func (p *RBACPolicy) AddRule(rule []string)

AddRule adds a rule to the policy.

func (*RBACPolicy) Delete

func (p *RBACPolicy) Delete()

Delete marks the RBAC policy as deleted.

func (*RBACPolicy) IsDeleted

func (p *RBACPolicy) IsDeleted() bool

IsDeleted returns whether the RBAC policy is deleted.

func (*RBACPolicy) RemoveRule

func (p *RBACPolicy) RemoveRule(rule []string)

RemoveRule removes a rule from the policy.

func (*RBACPolicy) Restore

func (p *RBACPolicy) Restore()

Restore removes the deletion mark from the RBAC policy.

func (*RBACPolicy) UpdateSyncTime

func (p *RBACPolicy) UpdateSyncTime()

UpdateSyncTime updates the last sync time to now.

type RBACPolicyMetadata

type RBACPolicyMetadata struct {
	UID       uuid.UUID
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

RBACPolicyMetadata contains metadata about the RBAC policy.

type RBACPolicySpec

type RBACPolicySpec struct {
	PolicyType string     // "p" (policy) or "g" (grouping/role inheritance)
	Rules      [][]string // Casbin policy rules, e.g., []{"admin", "agent", "write"}
}

RBACPolicySpec defines the RBAC policy rules.

type RBACPolicyStatus

type RBACPolicyStatus struct {
	Conditions   []model.Condition
	LastSyncedAt time.Time
}

RBACPolicyStatus represents the current state of the RBAC policy.

type Role

type Role struct {
	Metadata RoleMetadata
	Spec     RoleSpec
	Status   RoleStatus
}

Role represents a role that can be assigned to users.

func NewRole

func NewRole(displayName string, isBuiltIn bool) *Role

NewRole creates a new role with the given display name.

func (*Role) AddPermission

func (r *Role) AddPermission(permissionID string)

AddPermission adds a permission to the role.

func (*Role) Delete

func (r *Role) Delete()

Delete marks the role as deleted.

func (*Role) HasPermission

func (r *Role) HasPermission(permissionID string) bool

HasPermission checks if the role has a permission.

func (*Role) IsDeleted

func (r *Role) IsDeleted() bool

IsDeleted returns whether the role is deleted.

func (*Role) RemovePermission

func (r *Role) RemovePermission(permissionID string)

RemovePermission removes a permission from the role.

func (*Role) Restore

func (r *Role) Restore()

Restore removes the deletion mark from the role.

type RoleBinding

type RoleBinding struct {
	Metadata RoleBindingMetadata
	Spec     RoleBindingSpec
	Status   RoleBindingStatus
}

RoleBinding represents a binding of a role to a user within a namespace.

func NewRoleBinding

func NewRoleBinding(namespace, name string, roleRef RoleRef) *RoleBinding

NewRoleBinding creates a new RoleBinding instance. Set Spec.Subjects to define the set of principals this binding applies to.

func (*RoleBinding) IsDeleted

func (rb *RoleBinding) IsDeleted() bool

IsDeleted returns whether the role binding is soft-deleted.

func (*RoleBinding) MarkDeleted

func (rb *RoleBinding) MarkDeleted()

MarkDeleted marks the role binding as deleted.

func (*RoleBinding) MatchesUser added in v0.1.38

func (rb *RoleBinding) MatchesUser(user *User) bool

MatchesUser returns true when any of the binding's Subjects names the given user. Currently only Subject.Kind == "User" is supported, matching against the user's email. Subjects with empty Name and users with empty Email never match — guards against an "" == "" false positive on malformed input.

func (*RoleBinding) SetUpdatedAt

func (rb *RoleBinding) SetUpdatedAt(t time.Time)

SetUpdatedAt sets the updatedAt timestamp.

type RoleBindingMetadata

type RoleBindingMetadata struct {
	Namespace string
	Name      string
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

RoleBindingMetadata contains metadata about the role binding.

type RoleBindingSpec

type RoleBindingSpec struct {
	RoleRef  RoleRef
	Subjects []Subject
}

RoleBindingSpec defines the role binding details. Subjects enumerates the principals (e.g. Users) that this binding grants the referenced role to.

type RoleBindingStatus

type RoleBindingStatus struct {
	Conditions []model.Condition
}

RoleBindingStatus represents the current state of the role binding.

type RoleMetadata

type RoleMetadata struct {
	UID       uuid.UUID
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

RoleMetadata contains metadata about the role.

type RoleRef

type RoleRef struct {
	Kind string
	Name string
}

RoleRef references a role by kind and name.

type RoleSpec

type RoleSpec struct {
	DisplayName string
	Description string
	Permissions []string // Permission names (e.g., "agent:read")
	IsBuiltIn   bool
}

RoleSpec defines the desired state of the role.

type RoleStatus

type RoleStatus struct {
	Conditions []model.Condition
}

RoleStatus represents the current state of the role.

type Subject

type Subject struct {
	Kind       string
	Name       string
	APIVersion string
}

Subject names a principal that a RoleBinding grants its role to. Kind is e.g. "User"; Name is the principal identifier (for User, the email address).

type User

type User struct {
	Metadata UserMetadata
	Spec     UserSpec
	Status   UserStatus
}

User represents an authenticated user in the system. A user can be linked to multiple identity providers (GitHub, Google, LDAP, etc.).

func NewUser

func NewUser(email, username string) *User

NewUser creates a new user with the given email and username.

func NewUserWithIdentity

func NewUserWithIdentity(provider, providerUserID, email, displayName string) *User

NewUserWithIdentity creates a new user linked to an external identity provider.

func (*User) AddIdentity

func (u *User) AddIdentity(identity UserIdentity)

AddIdentity links an additional identity provider to this user. If an identity with the same provider already exists, it is updated.

func (*User) Delete

func (u *User) Delete()

Delete marks the user as deleted.

func (*User) GetIdentity

func (u *User) GetIdentity(provider string) *UserIdentity

GetIdentity returns the identity for the given provider, if it exists.

func (*User) GetLabel added in v0.1.37

func (u *User) GetLabel(key string) (string, bool)

GetLabel returns the value of a label from the user's metadata.

func (*User) HasIdentity

func (u *User) HasIdentity(provider string) bool

HasIdentity checks if the user has an identity from the given provider.

func (*User) IsDeleted

func (u *User) IsDeleted() bool

IsDeleted returns whether the user is deleted.

func (*User) RemoveIdentity

func (u *User) RemoveIdentity(provider, providerUserID string)

RemoveIdentity removes an identity provider link from this user.

func (*User) RemoveLabel added in v0.1.37

func (u *User) RemoveLabel(key string)

RemoveLabel removes a label from the user's metadata.

func (*User) Restore

func (u *User) Restore()

Restore removes the deletion mark from the user.

func (*User) SetLabel added in v0.1.37

func (u *User) SetLabel(key, value string)

SetLabel sets a label on the user's metadata.

type UserIdentity

type UserIdentity struct {
	Provider       string // e.g., "github", "google", "ldap", "basic"
	ProviderUserID string // unique ID from the external provider
	Email          string // email from this provider (may differ per provider)
	DisplayName    string // display name from this provider
}

UserIdentity represents a linked external identity provider account. A single user can have multiple identities (e.g., GitHub + Google).

type UserMetadata

type UserMetadata struct {
	UID       uuid.UUID
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
	Labels    map[string]string // arbitrary key/value pairs attached to the user (e.g. login-type, github-org-*)
}

UserMetadata contains metadata about the user.

type UserRole

type UserRole struct {
	Metadata UserRoleMetadata
	Spec     UserRoleSpec
	Status   UserRoleStatus
}

UserRole represents the assignment of a role to a user.

func NewUserRole

func NewUserRole(userID, roleID, assignedBy uuid.UUID, namespace string) *UserRole

NewUserRole creates a new user role assignment scoped to a namespace. Use "*" as namespace for a cluster-wide (all namespaces) assignment.

func (*UserRole) Delete

func (ur *UserRole) Delete()

Delete marks the user role assignment as deleted.

func (*UserRole) IsDeleted

func (ur *UserRole) IsDeleted() bool

IsDeleted returns whether the user role assignment is deleted.

func (*UserRole) Restore

func (ur *UserRole) Restore()

Restore removes the deletion mark from the user role assignment.

type UserRoleMetadata

type UserRoleMetadata struct {
	UID       uuid.UUID
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

UserRoleMetadata contains metadata about the user role assignment.

type UserRoleSpec

type UserRoleSpec struct {
	UserID     uuid.UUID
	RoleID     uuid.UUID
	Namespace  string // Namespace scope. "*" = all namespaces, otherwise a specific namespace name.
	AssignedAt time.Time
	AssignedBy uuid.UUID // User who assigned the role
}

UserRoleSpec defines the user role assignment details.

type UserRoleStatus

type UserRoleStatus struct {
	Conditions []model.Condition
}

UserRoleStatus represents the current state of the user role assignment.

type UserSpec

type UserSpec struct {
	Email      string
	Username   string
	IsActive   bool
	Identities []UserIdentity
}

UserSpec defines the desired state of the user.

type UserStatus

type UserStatus struct {
	Conditions []model.Condition
	Roles      []string // Role IDs
}

UserStatus represents the current state of the user.

Jump to

Keyboard shortcuts

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