Documentation
¶
Overview ¶
Package usermodel provides user domain models.
Index ¶
- Constants
- func AllActions() []string
- func NamespaceScopedResources() []string
- func ReadOnlyActions() []string
- type Permission
- type PermissionMetadata
- type PermissionSpec
- type PermissionStatus
- type RBACPolicy
- type RBACPolicyMetadata
- type RBACPolicySpec
- type RBACPolicyStatus
- type Role
- type RoleBinding
- type RoleBindingMetadata
- type RoleBindingSpec
- type RoleBindingStatus
- type RoleMetadata
- type RoleRef
- type RoleSpec
- type RoleStatus
- type User
- func (u *User) AddIdentity(identity UserIdentity)
- func (u *User) Delete()
- func (u *User) GetIdentity(provider string) *UserIdentity
- func (u *User) GetLabel(key string) (string, bool)
- func (u *User) HasIdentity(provider string) bool
- func (u *User) IsDeleted() bool
- func (u *User) RemoveIdentity(provider, providerUserID string)
- func (u *User) RemoveLabel(key string)
- func (u *User) Restore()
- func (u *User) SetLabel(key, value string)
- type UserIdentity
- type UserMetadata
- type UserRole
- type UserRoleMetadata
- type UserRoleSpec
- type UserRoleStatus
- type UserSpec
- type UserStatus
Constants ¶
const ( IdentityProviderGitHub = "github" IdentityProviderGoogle = "google" IdentityProviderLDAP = "ldap" IdentityProviderOIDC = "oidc" IdentityProviderBasic = "basic" )
IdentityProvider constants for supported authentication providers.
const ( ActionGet = "GET" ActionList = "LIST" ActionCreate = "CREATE" ActionUpdate = "UPDATE" ActionDelete = "DELETE" )
Actions for RBAC permission checks.
const ( ResourceAgent = "agent" ResourceAgentGroup = "agentgroup" ResourceAgentPackage = "agentpackage" ResourceAgentRemoteConfig = "agentremoteconfig" ResourceCertificate = "certificate" ResourceRoleBinding = "rolebinding" )
Namespace-scoped resource types controlled by RBAC.
const ( ResourceServer = "server" ResourceUser = "user" ResourceRole = "role" ResourcePermission = "permission" )
Global resource types (not namespace-scoped).
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.
const ( LabelLoginType = "login-type" // e.g. "github", "basic" LabelGitHubOrg = "github-org-" // prefix; full key = "github-org-{orgname}" )
Label keys added to users on login.
const DefaultNamespace = "default"
DefaultNamespace is the namespace used for built-in default role assignments.
const WildcardAll = "*"
WildcardAll represents a wildcard matching all values in RBAC policies.
Variables ¶
This section is empty.
Functions ¶
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) 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 ¶
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) 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 ¶
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 (*Role) AddPermission ¶
AddPermission adds a permission to the role.
func (*Role) HasPermission ¶
HasPermission checks if the role has a permission.
func (*Role) RemovePermission ¶
RemovePermission removes a permission 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.LabelSelector to define the set of users 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) 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 ¶
RoleBindingSpec defines the role binding details. LabelSelector binds the role to any user whose labels match all specified key/value pairs.
type RoleBindingStatus ¶
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 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 ¶
RoleStatus represents the current state of the role.
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 NewUserWithIdentity ¶
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) 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
GetLabel returns the value of a label from the user's metadata.
func (*User) HasIdentity ¶
HasIdentity checks if the user has an identity from the given provider.
func (*User) RemoveIdentity ¶
RemoveIdentity removes an identity provider link from this user.
func (*User) RemoveLabel ¶ added in v0.1.37
RemoveLabel removes a label from 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; used for label-selector based role bindings
}
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 ¶
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.
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 ¶
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 ¶
UserStatus represents the current state of the user.