identity

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package identity manages internal users and groups and the account policies (decision 0005): creation and replacement with hashed passwords, group membership and auto-join, the user lock and password expiration policies, locks and forced password changes. The legacy security API and Access v2 serve it in their own shapes.

Index

Constants

This section is empty.

Variables

View Source
var ErrExists = errors.New("identity: already exists")

ErrExists answers a create-only call for a name already taken (409).

View Source
var ErrInvalid = errors.New("identity: invalid")

ErrInvalid reports a request the caller must change: a missing or mismatched field, an unknown group or member, or a change to a protected principal. Handlers answer it 400.

View Source
var ErrProtected = errors.New("identity: protected")

ErrProtected marks the ErrInvalid errors that refuse a change to a built-in principal. The legacy API answers them 400 like any ErrInvalid; Access v2 documents 403 for deleting a built-in user.

Functions

This section is empty.

Types

type AccessLockPolicy

type AccessLockPolicy struct {
	// Attempts is the lock limit while locking is on, and 0 while it is off.
	Attempts int
	// PasswordExpiryDays is the maximum password age while expiry is on,
	// and 0 while it is off.
	PasswordExpiryDays int
	types.AccessLockSettings
}

AccessLockPolicy is the Access user lock policy: one document over the lock policy, the password expiration policy and the AccessLockSettings, so the Access and Artifactory APIs read and write the same state.

type GroupPatch

type GroupPatch struct {
	Description     *string
	AutoJoin        *bool
	AdminPrivileges *bool
	Members         *[]string
	WatchManager    *bool
	PolicyManager   *bool
	ReportsManager  *bool
	// The fields only Access v2 sets; the legacy API leaves them nil.
	ExternalID       *string
	PolicyViewer     *bool
	ResourcesManager *bool
	ManageWebhook    *bool
}

GroupPatch holds the fields an update changes; nil leaves a field as it is.

type Service

type Service struct {
	Store store.Store
	// Hash is the password hash cost; the zero value is production's.
	Hash auth.HashParams
	// Now supplies the time; nil means time.Now.
	Now func() time.Time
}

Service manages users, groups and the account policies.

func (*Service) AccessLockPolicy

func (s *Service) AccessLockPolicy(ctx context.Context) (AccessLockPolicy, error)

AccessLockPolicy returns the Access view of the policies, mapped as JFrog documents: enabled with loginAttempts is attempts, disabled is 0.

func (*Service) ChangePassword

func (s *Service) ChangePassword(
	ctx context.Context,
	name, oldPassword, newPassword, confirm string,
) error

ChangePassword replaces name's password with newPassword once oldPassword verifies, which the legacy password change asks of every caller, administrators included. An expired old password still verifies: changing it is how an expired password is replaced. confirm must repeat newPassword, and the password policy applies as for any password set.

A wrong old password counts against the user lock policy as a wrong login does. The request is already authenticated, possibly by a token, so without the count this would be a way to guess the password without limit.

func (*Service) CreateGroup

func (s *Service) CreateGroup(ctx context.Context, g types.Group, members []string) error

CreateGroup creates g with members, as PutGroup does for a new name, and answers ErrExists when the name is taken instead of replacing the group. An unknown member is store.ErrNotFound, which Access v2 documents as 404; the legacy PutGroup answers it 400.

func (*Service) CreateUser

func (s *Service) CreateUser(ctx context.Context, u types.User, password string) error

CreateUser creates u with password, as PutUser does for a new name, and answers ErrExists when the name is taken instead of replacing the user.

func (*Service) DeleteGroup

func (s *Service) DeleteGroup(ctx context.Context, name string) error

DeleteGroup removes a group, its memberships and, in the same transaction, its grants in every permission: a grant left behind would pass to a later group of the same name. The seeded readers group is no exception (no JFrog source protects it, and jf rt group-delete makes none); seeding runs once, so it does not come back.

func (*Service) DeleteUser

func (s *Service) DeleteUser(ctx context.Context, name string) error

DeleteUser removes a user, its group memberships and its tokens. The seeded admin and anonymous users and the last administrator stay.

func (*Service) ExpirationPolicy

func (s *Service) ExpirationPolicy(ctx context.Context) (types.PasswordExpirationPolicy, error)

ExpirationPolicy returns the password expiration policy.

func (*Service) ExpireAllPasswords

func (s *Service) ExpireAllPasswords(ctx context.Context) error

ExpireAllPasswords forces every internal user with a password to set a new one, and revokes their encrypted passwords as ExpirePasswords does, so UnexpireAllPasswords cannot bring an old one back; users whose internal password is disabled are unaffected.

func (*Service) ExpirePasswords

func (s *Service) ExpirePasswords(ctx context.Context, names []string) ([]string, error)

ExpirePasswords forces each named user to set a new password before the next login, revokes their encrypted passwords, and returns the names that matched no user.

func (*Service) Group

func (s *Service) Group(ctx context.Context, name string) (types.Group, error)

Group returns one group with its members.

func (*Service) Groups

func (s *Service) Groups(ctx context.Context) ([]types.Group, error)

Groups returns every group, ordered by name.

func (*Service) LockPolicy

func (s *Service) LockPolicy(ctx context.Context) (types.UserLockPolicy, error)

LockPolicy returns the user lock policy.

func (*Service) Locked

func (s *Service) Locked(ctx context.Context) ([]string, error)

Locked returns the names of locked users.

func (*Service) PasswordPolicy

func (s *Service) PasswordPolicy(ctx context.Context) (types.PasswordPolicy, error)

PasswordPolicy returns the stored policy, or types.DefaultPasswordPolicy while none is stored.

func (*Service) PatchGroup

func (s *Service) PatchGroup(ctx context.Context, name string, p GroupPatch) error

PatchGroup changes the fields p carries; Members, when present, replaces the membership.

func (*Service) PatchUser

func (s *Service) PatchUser(ctx context.Context, name string, p UserPatch) error

PatchUser changes the fields p carries; Groups, when present, replaces the membership.

func (*Service) PutGroup

func (s *Service) PutGroup(ctx context.Context, g types.Group, members *[]string) (bool, error)

PutGroup creates g, or replaces every field of an existing group, and reports whether it created it. members, when not nil, replaces the membership; otherwise an existing group keeps its members.

func (*Service) PutUser

func (s *Service) PutUser(ctx context.Context, u types.User, password string) (bool, error)

PutUser creates u, or replaces every field an existing user's document carries, and reports whether it created it. password is the clear-text password, required unless u.InternalPasswordDisabled. A new user also joins every auto-join group.

func (*Service) SetAccessLockPolicy

func (s *Service) SetAccessLockPolicy(
	ctx context.Context,
	p AccessLockPolicy,
) (AccessLockPolicy, error)

SetAccessLockPolicy stores p and returns it. A 0 turns locking or expiry off but keeps the stored limit or age, which the Artifactory API goes on reporting beside enabled false. Turning locking off clears every lock, as SetLockPolicy does.

func (*Service) SetExpirationPolicy

SetExpirationPolicy stores p and returns what was stored.

func (*Service) SetLockPolicy

func (s *Service) SetLockPolicy(ctx context.Context, p types.UserLockPolicy) error

SetLockPolicy stores p. Disabling the policy also clears every lock, as Artifactory does, so turning it off is never a way to strand users.

func (*Service) SetPassword

func (s *Service) SetPassword(ctx context.Context, name, password string) error

SetPassword replaces the user's password. It must satisfy the policy and, when the policy forbids reuse, differ from the current one. A new password clears an expiry.

func (*Service) SetPasswordPolicy

func (s *Service) SetPasswordPolicy(ctx context.Context, p types.PasswordPolicy) error

SetPasswordPolicy stores p. The policy applies when a password is set or changed, not to passwords already stored.

func (*Service) UnexpireAllPasswords

func (s *Service) UnexpireAllPasswords(ctx context.Context) error

UnexpireAllPasswords makes every expired internal password valid again and restarts its age, so the expiration policy does not expire it again at once.

func (*Service) UnexpirePassword

func (s *Service) UnexpirePassword(ctx context.Context, name string) error

UnexpirePassword clears an administrator's forced password change and restarts the password's age, so the policy does not expire it again at once.

func (*Service) Unlock

func (s *Service) Unlock(ctx context.Context, names []string) error

Unlock unlocks the named users; unknown names are ignored. An empty list is refused, so a client bug cannot read as "unlock nobody".

func (*Service) UnlockAll

func (s *Service) UnlockAll(ctx context.Context) error

UnlockAll unlocks every locked user.

func (*Service) UpdateGroupMembers

func (s *Service) UpdateGroupMembers(
	ctx context.Context,
	name string,
	add, remove []string,
) ([]string, error)

UpdateGroupMembers applies add, then remove, to the group's members and returns the resulting member list. Unknown users in add are store.ErrNotFound, which Access v2 answers 404.

func (*Service) UpdateUserGroups

func (s *Service) UpdateUserGroups(
	ctx context.Context,
	name string,
	add, remove []string,
) ([]string, error)

UpdateUserGroups applies add, then remove, to the user's memberships and returns the resulting groups. A name in both lists ends up removed; an unknown group in add is ErrInvalid.

func (*Service) User

func (s *Service) User(ctx context.Context, name string) (types.User, error)

User returns one user.

func (*Service) Users

func (s *Service) Users(ctx context.Context) ([]types.User, error)

Users returns every user, ordered by name.

type UserPatch

type UserPatch struct {
	Email                    *string
	Password                 *string
	Admin                    *bool
	ProfileUpdatable         *bool
	DisableUIAccess          *bool
	InternalPasswordDisabled *bool
	Groups                   *[]string
	PolicyViewer             *bool
	PolicyManager            *bool
	WatchManager             *bool
	ReportsManager           *bool
	// The flags only Access v2 sets; the legacy API leaves them nil.
	ResourcesManager *bool
	ManageWebhook    *bool
	PlatformAuditor  *bool
}

UserPatch holds the fields an update changes; nil leaves a field as it is.

Jump to

Keyboard shortcuts

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