model

package
v1.0.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 4 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

Overview

Package iam holds the identity and access-management entities.

Index

Constants

View Source
const (
	RoleSuperAdmin = role.SuperAdmin
	RoleAdmin      = role.Admin
	RoleUser       = role.User
)

The roles, re-exported so callers working with users do not need a second import.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthMethod

type AuthMethod string

AuthMethod identifies how a user authenticates.

Java: org.apache.airavata.iam.model.enums.AuthMethod

const (
	AuthMethodCILogon AuthMethod = "CILOGON"
	AuthMethodSystem  AuthMethod = "SYSTEM"

	// AuthMethodServiceAccount marks a non-human account that authenticates with an
	// Airavata-issued token. Such users are created only through the service account
	// API, never through user registration.
	AuthMethodServiceAccount AuthMethod = "SERVICE_ACCOUNT"
)

func (AuthMethod) Valid

func (m AuthMethod) Valid() bool

Valid reports whether m is a recognised AuthMethod.

type Group

type Group struct {
	ID   string  `gorm:"column:group_id;primaryKey;type:varchar(36)" json:"groupId"`
	Name *string `gorm:"column:group_name;type:varchar(255)" json:"groupName,omitempty"`

	// OwnerID is named for its role rather than for the column, because ownership —
	// not mere reference — is what the authorisation checks read. RESTRICT: a user who
	// still owns groups cannot be deleted out from under them.
	OwnerID *string `gorm:"column:user_id;type:varchar(255);index" json:"ownerId,omitempty"`
	Owner   *User   `gorm:"references:ID;constraint:OnDelete:RESTRICT,OnUpdate:CASCADE" json:"-"`

	// CreatedAt is epoch milliseconds, matching User.CreatedAt. It is set imperatively
	// at creation, not by a lifecycle callback.
	CreatedAt int64 `gorm:"column:created_at;not null" json:"createdAt"`

	// Members are owned by the group: deleting a group deletes its membership rows.
	// Like Cluster.Partitions this is a read-side projection — the services write
	// through the membership repository rather than mutating the collection.
	Members []GroupMember `gorm:"foreignKey:GroupID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE" json:"members,omitempty"`
}

Group is a named collection of users that resources can be shared with.

The owner is the user who created it and is not transferable through the API: the data-sharing tables grant access by group id, so handing a group to someone else would silently hand over everything shared with it. The owner always holds an ADMIN membership row as well, created alongside the group.

func (*Group) BeforeCreate

func (g *Group) BeforeCreate(*gorm.DB) error

BeforeCreate assigns a UUID when none was supplied.

func (*Group) OwnedBy

func (g *Group) OwnedBy(userID string) bool

OwnedBy reports whether userID owns this group. A group with no owner is owned by nobody, so it must not match the empty principal name.

func (Group) TableName

func (Group) TableName() string

TableName returns the table backing Group.

type GroupMember

type GroupMember struct {
	GroupID           string            `gorm:"column:group_id;primaryKey;type:varchar(36)" json:"groupId"`
	UserID            string            `gorm:"column:user_id;primaryKey;type:varchar(255)" json:"userId"`
	GroupRole         GroupRole         `gorm:"column:group_role;type:varchar(32)" json:"groupRole"`
	GroupMemberStatus GroupMemberStatus `gorm:"column:group_member_status;type:varchar(32)" json:"groupMemberStatus"`
}

GroupMember places one user in one group. The primary key is the (group, user) pair: a user holds at most one role in a given group.

func (*GroupMember) BeforeSave

func (m *GroupMember) BeforeSave(*gorm.DB) error

BeforeSave rejects unrecognised roles and statuses, the same way UserRole does: the columns are plain varchars, so validating on write is what keeps an unknown constant out of the table.

func (*GroupMember) CanManageMembers

func (m *GroupMember) CanManageMembers() bool

CanManageMembers reports whether this membership may add, change and remove other memberships. Moderators can, so that a group does not depend on its owner being available to admit people.

func (*GroupMember) IsActive

func (m *GroupMember) IsActive() bool

IsActive reports whether the membership currently grants anything. An INACTIVE row keeps the user's place in the group without letting them read through it.

func (GroupMember) TableName

func (GroupMember) TableName() string

TableName returns the table backing GroupMember.

type GroupMemberStatus

type GroupMemberStatus string
const (
	GroupMemberStatusActive   GroupMemberStatus = "ACTIVE"
	GroupMemberStatusInactive GroupMemberStatus = "INACTIVE"
)

func (GroupMemberStatus) Valid

func (s GroupMemberStatus) Valid() bool

type GroupRole

type GroupRole string
const (
	GroupRoleAdmin     GroupRole = "ADMIN"
	GroupRoleMember    GroupRole = "MEMBER"
	GroupRoleModerator GroupRole = "MODERATOR"
)

func (GroupRole) Valid

func (r GroupRole) Valid() bool

type Role

type Role = role.Role

Role is the granted authority stored on UserRole. It is an alias rather than a distinct type so that a role read from the database and a role compared by the auth guards are the same value, with no conversion between them.

type RolePermission

type RolePermission struct {
	Role       Role                  `gorm:"column:role;primaryKey;type:varchar(32)" json:"role"`
	Permission permission.Permission `gorm:"column:permission;primaryKey;type:varchar(64)" json:"permission"`
}

RolePermission grants one permission to every holder of one role. The primary key is the (role, permission) pair, so a role holds each permission at most once.

There is no foreign key to a roles table because roles are a fixed set (see internal/role), validated where a user is given one. There is none to a permissions table either: the catalogue is in code, since a handler can only ask for a permission the code knows about.

func (*RolePermission) BeforeSave

func (r *RolePermission) BeforeSave(*gorm.DB) error

BeforeSave rejects an unrecognised role or permission, so a typo cannot be stored as a grant that silently never matches anything.

func (RolePermission) TableName

func (RolePermission) TableName() string

TableName returns the table backing RolePermission.

type ServiceAccount

type ServiceAccount struct {
	UserID string `gorm:"column:user_id;primaryKey;type:varchar(255)" json:"userId"`

	Description *string `gorm:"column:description;type:varchar(1024)" json:"description,omitempty"`

	// CreatedBy is the admin who created the account. It is a plain record, not a
	// reference: the account outlives its creator's user row.
	CreatedBy string `gorm:"column:created_by;type:varchar(255);not null" json:"createdBy"`

	// TokenHash is the hex SHA-256 of the token. The token itself is never stored.
	TokenHash      string `gorm:"column:token_hash;type:varchar(64);not null;uniqueIndex:uk_service_account_token_hash" json:"-"`
	TokenIssuedAt  int64  `gorm:"column:token_issued_at;not null" json:"tokenIssuedAt"`
	TokenExpiresAt int64  `gorm:"column:token_expires_at;not null" json:"tokenExpiresAt"`

	// Permissions is what the account is allowed to do beyond acting on its own
	// records. Owned by the account: deleting it deletes the rows. Services write them
	// through the permission set operations, not by mutating this slice.
	Permissions []ServiceAccountPermission `gorm:"foreignKey:UserID;references:UserID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE" json:"-"`
}

ServiceAccount is the token side of a non-human user.

The account itself is an ordinary users row (AuthMethod SERVICE_ACCOUNT), which is what lets it own resources, receive shares and join groups with no special casing anywhere else. This row holds only what a person does not have: the digest of the one active token, when it was issued and when it stops working.

There is one token per account. Renewing moves its expiry; regenerating replaces it, which revokes the old one in the same write.

func (*ServiceAccount) ExpiredAt

func (s *ServiceAccount) ExpiredAt(nowMillis int64) bool

ExpiredAt reports whether the token has expired at nowMillis.

func (ServiceAccount) TableName

func (ServiceAccount) TableName() string

TableName pins the table name.

type ServiceAccountPermission

type ServiceAccountPermission struct {
	UserID     string                `gorm:"column:user_id;primaryKey;type:varchar(255)" json:"userId"`
	Permission permission.Permission `gorm:"column:permission;primaryKey;type:varchar(64)" json:"permission"`
}

ServiceAccountPermission grants one permission to one service account. The primary key is the (user_id, permission) pair, so an account holds each permission at most once.

A service account's permissions are exactly these rows. It holds no role that grants any, so granting a permission to a role never reaches a service account, and each account can differ from the next. The rows belong to the account and go with it.

func (*ServiceAccountPermission) BeforeSave

func (p *ServiceAccountPermission) BeforeSave(*gorm.DB) error

BeforeSave rejects a permission that does not exist or that no service account may hold, so neither can be stored by any path, including one that skips the service.

func (ServiceAccountPermission) TableName

func (ServiceAccountPermission) TableName() string

TableName returns the table backing ServiceAccountPermission.

type User

type User struct {
	ID string `gorm:"column:user_id;primaryKey;type:varchar(255)" json:"userId"`

	AuthMethod *AuthMethod `gorm:"column:auth_method;type:varchar(32)" json:"authMethod,omitempty"`

	Email     *string `gorm:"column:email;type:varchar(255)" json:"email,omitempty"`
	FirstName *string `gorm:"column:first_name;type:varchar(255)" json:"firstName,omitempty"`
	LastName  *string `gorm:"column:last_name;type:varchar(255)" json:"lastName,omitempty"`

	Status *UserStatus `gorm:"column:status;type:varchar(32)" json:"status,omitempty"`

	// CreatedAt is epoch milliseconds, matching the Java primitive long. It is set
	// imperatively at registration, not by a lifecycle callback.
	CreatedAt int64 `gorm:"column:created_at;not null" json:"createdAt"`

	// Roles are owned by the user: deleting a user deletes its role rows, rather than
	// relying on every caller to clean up user_roles separately.
	Roles []UserRole `gorm:"foreignKey:UserID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE" json:"roles,omitempty"`

	// Memberships are owned by the user the same way roles are: a membership is a
	// statement about this account, so deleting the account withdraws it. Owning a
	// group is a different matter and is deliberately RESTRICT — see Group.OwnerID.
	Memberships []GroupMember `gorm:"foreignKey:UserID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE" json:"-"`

	// ServiceAccount is set only for a user whose AuthMethod is SERVICE_ACCOUNT, and
	// carries its token. It goes with the user.
	ServiceAccount *ServiceAccount `gorm:"foreignKey:UserID;references:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE" json:"-"`
}

User is an Airavata account.

ID is supplied by the caller rather than generated: CILogon subjects are normalised to "cilogon:12345" for consistent lookup, while system users get a UUID chosen by the registration path. This is the one entity with no ID hook — every other entity generates its key in BeforeCreate.

Every service that resolves ownership assumes the authenticated principal's name is exactly this ID. That assumption is load-bearing in SlurmClusterConfig and SCPDataStorage authorisation.

func (*User) HasRole

func (u *User) HasRole(r Role) bool

HasRole reports whether the user holds role r.

func (*User) IsAdmin

func (u *User) IsAdmin() bool

IsAdmin reports whether the user holds ADMIN or SUPER_ADMIN. A service account never does, whatever its role rows say.

func (*User) IsServiceAccount

func (u *User) IsServiceAccount() bool

IsServiceAccount reports whether the user is a service account.

func (User) TableName

func (User) TableName() string

TableName pins the table name, matching the Java @Entity(name = "users").

type UserRole

type UserRole struct {
	UserID string `gorm:"column:user_id;primaryKey;type:varchar(255)" json:"userId"`
	Role   Role   `gorm:"column:role;primaryKey;type:varchar(32)" json:"role"`
}

UserRole grants one role to one user. The primary key is the (user_id, role) pair: a user may hold several roles, but not the same role twice.

The Java entity carried a read-only ManyToOne back to UserEntity purely so JPA's cascade could reach it. Here the cascade is a database-level constraint declared on User.Roles, so the back-reference would be redundant and is omitted.

Java: org.apache.airavata.iam.model.UserRoleEntity (@IdClass(UserRoleId.class))

func (*UserRole) BeforeSave

func (r *UserRole) BeforeSave(*gorm.DB) error

BeforeSave rejects unrecognised roles. Hibernate stored these by name and would fail on read for an unknown constant; validating on write is the closer analogue now that the column is a plain varchar.

func (UserRole) TableName

func (UserRole) TableName() string

TableName pins the table name, matching the Java @Entity(name = "user_roles").

type UserStatus

type UserStatus string

UserStatus is the account lifecycle state.

Java: org.apache.airavata.iam.model.enums.UserStatus

const (
	UserStatusActive    UserStatus = "ACTIVE"
	UserStatusInactive  UserStatus = "INACTIVE"
	UserStatusSuspended UserStatus = "SUSPENDED"
)

func (UserStatus) Valid

func (s UserStatus) Valid() bool

Valid reports whether s is a recognised UserStatus.

Jump to

Keyboard shortcuts

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