Documentation
¶
Overview ¶
Package service holds the identity vertical's business rules: user registration, group ownership and membership, and the root-account bootstrap.
Index ¶
- func EnsureRootUser(ctx context.Context, db *gorm.DB) error
- func RequireCurrentUser(ctx context.Context, repo *repository.UserRepository) (*model.User, error)
- type GroupMemberService
- func (s *GroupMemberService) Add(ctx context.Context, groupID string, req *dto.GroupMemberRequest) (*dto.GroupMemberResponse, error)
- func (s *GroupMemberService) Get(ctx context.Context, groupID, userID string) (*dto.GroupMemberResponse, error)
- func (s *GroupMemberService) List(ctx context.Context, groupID string) ([]dto.GroupMemberResponse, error)
- func (s *GroupMemberService) Remove(ctx context.Context, groupID, userID string) error
- func (s *GroupMemberService) Update(ctx context.Context, groupID, userID string, req *dto.GroupMemberUpdate) (*dto.GroupMemberResponse, error)
- type GroupService
- func (s *GroupService) Create(ctx context.Context, req *dto.GroupRequest) (*dto.GroupResponse, error)
- func (s *GroupService) Delete(ctx context.Context, groupID string) error
- func (s *GroupService) Get(ctx context.Context, groupID string) (*dto.GroupResponse, error)
- func (s *GroupService) List(ctx context.Context) ([]dto.GroupResponse, error)
- func (s *GroupService) ListMine(ctx context.Context) ([]dto.GroupResponse, error)
- func (s *GroupService) Update(ctx context.Context, groupID string, req *dto.GroupRequest) (*dto.GroupResponse, error)
- type PermissionInvalidator
- type PermissionService
- type ServiceAccountService
- func (s *ServiceAccountService) Create(ctx context.Context, req *dto.ServiceAccountCreate) (*dto.ServiceAccountTokenResponse, error)
- func (s *ServiceAccountService) Delete(ctx context.Context, id string) error
- func (s *ServiceAccountService) Get(ctx context.Context, id string) (*dto.ServiceAccountResponse, error)
- func (s *ServiceAccountService) List(ctx context.Context) ([]dto.ServiceAccountResponse, error)
- func (s *ServiceAccountService) RegenerateToken(ctx context.Context, id string, req *dto.ServiceAccountTokenRequest) (*dto.ServiceAccountTokenResponse, error)
- func (s *ServiceAccountService) RenewToken(ctx context.Context, id string, req *dto.ServiceAccountTokenRequest) (*dto.ServiceAccountResponse, error)
- func (s *ServiceAccountService) Update(ctx context.Context, id string, req *dto.ServiceAccountUpdate) (*dto.ServiceAccountResponse, error)
- type UserService
- func (s *UserService) Get(ctx context.Context, userID string) (*dto.UserResponse, error)
- func (s *UserService) List(ctx context.Context) ([]dto.UserAccountResponse, error)
- func (s *UserService) Me(ctx context.Context) (*dto.CurrentUserResponse, error)
- func (s *UserService) Register(ctx context.Context, req *dto.UserRegistration) (*dto.UserResponse, error)
- func (s *UserService) SetAdmin(ctx context.Context, userID string, req *dto.UserAdminUpdate) (*dto.UserAccountResponse, error)
- func (s *UserService) SetStatus(ctx context.Context, userID string, req *dto.UserStatusUpdate) (*dto.UserAccountResponse, error)
- func (s *UserService) Update(ctx context.Context, userID string, req *dto.UserRegistration) (*dto.UserResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureRootUser ¶
EnsureRootUser inserts a users row for the bootstrap root account if none exists yet.
The root token authenticates as a Super Admin without touching this table, so admin actions work from a fresh database with no row at all. Owning resources is different: cluster configs, SCP data and batch job processes resolve the caller to a users row and refuse if none exists. This closes that gap on startup instead of requiring the manual INSERT documented in INSTALL.md.
func RequireCurrentUser ¶
func RequireCurrentUser(ctx context.Context, repo *repository.UserRepository) (*model.User, error)
RequireCurrentUser resolves the authenticated caller to their stored user record.
The principal name is used as the user id directly — that equivalence is what makes every ownership check work, and it is why a token identifying a caller who was never registered fails here rather than silently creating a record.
Three services depend on this: cluster configs, SCP data and batch job processes all derive ownership from the token this way.
Types ¶
type GroupMemberService ¶
type GroupMemberService struct {
// contains filtered or unexported fields
}
GroupMemberService manages memberships as a sub-resource of their group.
Every operation is scoped by the group id from the path, and the membership's user comes from the path too — so a membership can be created, changed or withdrawn, but never moved to a different user or a different group.
func NewGroupMemberService ¶
func NewGroupMemberService(db *gorm.DB, groups *repository.GroupRepository, members *repository.GroupMemberRepository, users *repository.UserRepository) *GroupMemberService
NewGroupMemberService returns a membership service.
func (*GroupMemberService) Add ¶
func (s *GroupMemberService) Add(ctx context.Context, groupID string, req *dto.GroupMemberRequest) (*dto.GroupMemberResponse, error)
Add admits a user to a group.
The user must already be registered: an unknown id would otherwise sit in the table as a membership that can never be exercised, and the foreign key would reject it with an opaque error anyway.
func (*GroupMemberService) Get ¶
func (s *GroupMemberService) Get(ctx context.Context, groupID, userID string) (*dto.GroupMemberResponse, error)
Get returns one membership of a group.
func (*GroupMemberService) List ¶
func (s *GroupMemberService) List(ctx context.Context, groupID string) ([]dto.GroupMemberResponse, error)
List returns every membership of a group, to anyone who may read the group.
func (*GroupMemberService) Remove ¶
func (s *GroupMemberService) Remove(ctx context.Context, groupID, userID string) error
Remove withdraws a membership.
A member may always remove themselves — leaving a group needs nobody's permission, and works from a suspended membership too, which is the one case where an inactive member can still act on the group. The owner's membership cannot be removed at all while they own the group: that would leave the group owned by someone outside it.
func (*GroupMemberService) Update ¶
func (s *GroupMemberService) Update(ctx context.Context, groupID, userID string, req *dto.GroupMemberUpdate) (*dto.GroupMemberResponse, error)
Update changes a member's role or status.
The owner's own membership is reserved to the owner and to platform admins: without that, a moderator could suspend the owner out of their own group.
type GroupService ¶
type GroupService struct {
// contains filtered or unexported fields
}
GroupService manages groups.
Any authenticated user may create one, which is the difference between this and the administrative catalogs: a group belongs to the user who made it rather than to the deployment.
func NewGroupService ¶
func NewGroupService(db *gorm.DB, groups *repository.GroupRepository, members *repository.GroupMemberRepository, users *repository.UserRepository, shares *sharingrepo.Repository) *GroupService
NewGroupService returns a group service.
func (*GroupService) Create ¶
func (s *GroupService) Create(ctx context.Context, req *dto.GroupRequest) (*dto.GroupResponse, error)
Create registers a group owned by the calling user.
The owner is admitted as an ADMIN member in the same transaction, so a group is never left in a state where nobody can administer it. Creation time is set here rather than taken from the request, matching user registration.
func (*GroupService) Delete ¶
func (s *GroupService) Delete(ctx context.Context, groupID string) error
Delete removes a group, taking its membership rows and whatever was shared with it.
The memberships are cascaded away by the database. The shares are not, so they go here, in the same transaction. They would grant nothing once the group is gone — access through a group is resolved from active memberships, and those are being deleted — but they would accumulate, and a listing of a record's shares would name a group that no longer exists.
func (*GroupService) Get ¶
func (s *GroupService) Get(ctx context.Context, groupID string) (*dto.GroupResponse, error)
Get returns one group, to its owner, an active member, or an admin.
func (*GroupService) List ¶
func (s *GroupService) List(ctx context.Context) ([]dto.GroupResponse, error)
List returns every group across every owner. Needs group:list — this exposes who is working with whom.
func (*GroupService) ListMine ¶
func (s *GroupService) ListMine(ctx context.Context) ([]dto.GroupResponse, error)
ListMine returns the groups the caller owns or belongs to.
func (*GroupService) Update ¶
func (s *GroupService) Update(ctx context.Context, groupID string, req *dto.GroupRequest) (*dto.GroupResponse, error)
Update renames a group. The owner is left alone: re-deriving it from the caller's token would hand the group to whichever admin happened to issue the request.
type PermissionInvalidator ¶
type PermissionInvalidator interface {
InvalidateUser(id string)
}
PermissionInvalidator is told when a service account's grants change, so the resolver stops serving the old ones.
type PermissionService ¶
type PermissionService struct{}
PermissionService lists the permissions that exist.
The catalogue is the same for everyone and names nothing about any user, so any signed-in caller may read it; what a caller may grant from it is decided where the grant is made.
func NewPermissionService ¶
func NewPermissionService() *PermissionService
NewPermissionService returns a permission service.
func (*PermissionService) List ¶
func (s *PermissionService) List(ctx context.Context) ([]dto.PermissionResponse, error)
List returns every permission with its description, sorted.
type ServiceAccountService ¶
type ServiceAccountService struct {
// contains filtered or unexported fields
}
ServiceAccountService administers service accounts: non-human users that authenticate with an Airavata-issued, expiring token.
Every operation needs serviceaccount:read or serviceaccount:manage, which ADMIN holds by default. A service account is otherwise an ordinary user — it owns what it creates, can be shared with and can join groups — and what more it may do is the set of permissions granted to that account alone. It holds no role that grants any.
The permissions that manage identities and privileges can never be granted to one, so a service account cannot become an administrator or mint another account. And nobody can grant what they do not hold themselves.
func NewServiceAccountService ¶
func NewServiceAccountService(db *gorm.DB, accounts *repository.ServiceAccountRepository, users *repository.UserRepository, shares *sharingrepo.Repository, perms PermissionInvalidator) *ServiceAccountService
NewServiceAccountService returns a service account service.
func (*ServiceAccountService) Create ¶
func (s *ServiceAccountService) Create(ctx context.Context, req *dto.ServiceAccountCreate) (*dto.ServiceAccountTokenResponse, error)
Create registers a service account and mints its first token. The token is in the response and nowhere else; it cannot be read back later.
func (*ServiceAccountService) Delete ¶
func (s *ServiceAccountService) Delete(ctx context.Context, id string) error
Delete removes a service account, its token, its group memberships and every share granted to it.
An account that still owns records cannot be deleted — ownership is never transferred implicitly — and gets 409. Disabling it (status INACTIVE) revokes its access while keeping what it owns.
func (*ServiceAccountService) Get ¶
func (s *ServiceAccountService) Get(ctx context.Context, id string) (*dto.ServiceAccountResponse, error)
Get returns one service account.
func (*ServiceAccountService) List ¶
func (s *ServiceAccountService) List(ctx context.Context) ([]dto.ServiceAccountResponse, error)
List returns every service account.
func (*ServiceAccountService) RegenerateToken ¶
func (s *ServiceAccountService) RegenerateToken(ctx context.Context, id string, req *dto.ServiceAccountTokenRequest) (*dto.ServiceAccountTokenResponse, error)
RegenerateToken replaces the token with a new one. The old token stops working in the same write; this is how a leaked token is revoked.
func (*ServiceAccountService) RenewToken ¶
func (s *ServiceAccountService) RenewToken(ctx context.Context, id string, req *dto.ServiceAccountTokenRequest) (*dto.ServiceAccountResponse, error)
RenewToken extends the current token's life to validityDays from now. The token itself is unchanged, so whatever holds it keeps working. An expired token can be renewed back into use.
func (*ServiceAccountService) Update ¶
func (s *ServiceAccountService) Update(ctx context.Context, id string, req *dto.ServiceAccountUpdate) (*dto.ServiceAccountResponse, error)
Update changes a service account's display name, description, email, status or permissions. Setting the status to anything but ACTIVE stops its token working immediately, without discarding it, so the account can be re-enabled. Setting the permissions replaces the whole set, and takes effect on the account's next request.
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
UserService is the user management API.
Unlike the other services it predates the @PreAuthorize convention and does its authority checks inline. The checks are also asymmetric in ways worth preserving rather than tidying, because clients depend on them: registration is SUPER_ADMIN only, reading is ADMIN or self, and updating is SUPER_ADMIN or self.
func NewUserService ¶
func NewUserService(db *gorm.DB, repo *repository.UserRepository) *UserService
NewUserService returns a user service.
func (*UserService) Get ¶
func (s *UserService) Get(ctx context.Context, userID string) (*dto.UserResponse, error)
Get returns one user. Admins may read anyone; everyone else may read only themselves.
func (*UserService) List ¶
func (s *UserService) List(ctx context.Context) ([]dto.UserAccountResponse, error)
List returns every user, with the email, auth method and roles an administrator needs to decide on them. Needs user:list.
func (*UserService) Me ¶
func (s *UserService) Me(ctx context.Context) (*dto.CurrentUserResponse, error)
Me describes the caller. It is the one route open to an account that is not active, so the dashboard can tell a suspended user why nothing else works.
func (*UserService) Register ¶
func (s *UserService) Register(ctx context.Context, req *dto.UserRegistration) (*dto.UserResponse, error)
Register creates a user. Only a Super Admin may do this.
Status and creation time are set here rather than taken from the request, so a caller cannot register an account that is already suspended or backdated.
func (*UserService) SetAdmin ¶
func (s *UserService) SetAdmin(ctx context.Context, userID string, req *dto.UserAdminUpdate) (*dto.UserAccountResponse, error)
SetAdmin grants or withdraws the ADMIN role. Needs admin:manage, which only SUPER_ADMIN holds by default.
A Super Admin cannot change their own role, and a Super Admin's standing is not something this call touches: SUPER_ADMIN accounts are rejected. Service accounts never hold administrator rights.
func (*UserService) SetStatus ¶
func (s *UserService) SetStatus(ctx context.Context, userID string, req *dto.UserStatusUpdate) (*dto.UserAccountResponse, error)
SetStatus activates, deactivates or suspends a user. Needs user:set_status.
An administrator cannot change their own status, which would be a way to lock the last administrator out. Only a Super Admin may change another administrator's status, so an ADMIN cannot suspend the people who appoint admins. Service accounts have their own lifecycle under /api/v1/service-accounts.
func (*UserService) Update ¶
func (s *UserService) Update(ctx context.Context, userID string, req *dto.UserRegistration) (*dto.UserResponse, error)
Update changes a user's profile. A Super Admin may update anyone; everyone else may update only themselves.
Only the three profile fields are writable. Auth method, status and roles are deliberately not updatable through this API — letting a self-service update touch them would let any user change their own standing.