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 ¶
- Variables
- type AccessLockPolicy
- type GroupPatch
- type Service
- func (s *Service) AccessLockPolicy(ctx context.Context) (AccessLockPolicy, error)
- func (s *Service) ChangePassword(ctx context.Context, name, oldPassword, newPassword, confirm string) error
- func (s *Service) CreateGroup(ctx context.Context, g types.Group, members []string) error
- func (s *Service) CreateUser(ctx context.Context, u types.User, password string) error
- func (s *Service) DeleteGroup(ctx context.Context, name string) error
- func (s *Service) DeleteUser(ctx context.Context, name string) error
- func (s *Service) ExpirationPolicy(ctx context.Context) (types.PasswordExpirationPolicy, error)
- func (s *Service) ExpireAllPasswords(ctx context.Context) error
- func (s *Service) ExpirePasswords(ctx context.Context, names []string) ([]string, error)
- func (s *Service) Group(ctx context.Context, name string) (types.Group, error)
- func (s *Service) Groups(ctx context.Context) ([]types.Group, error)
- func (s *Service) LockPolicy(ctx context.Context) (types.UserLockPolicy, error)
- func (s *Service) Locked(ctx context.Context) ([]string, error)
- func (s *Service) PasswordPolicy(ctx context.Context) (types.PasswordPolicy, error)
- func (s *Service) PatchGroup(ctx context.Context, name string, p GroupPatch) error
- func (s *Service) PatchUser(ctx context.Context, name string, p UserPatch) error
- func (s *Service) PutGroup(ctx context.Context, g types.Group, members *[]string) (bool, error)
- func (s *Service) PutUser(ctx context.Context, u types.User, password string) (bool, error)
- func (s *Service) SetAccessLockPolicy(ctx context.Context, p AccessLockPolicy) (AccessLockPolicy, error)
- func (s *Service) SetExpirationPolicy(ctx context.Context, p types.PasswordExpirationPolicy) (types.PasswordExpirationPolicy, error)
- func (s *Service) SetLockPolicy(ctx context.Context, p types.UserLockPolicy) error
- func (s *Service) SetPassword(ctx context.Context, name, password string) error
- func (s *Service) SetPasswordPolicy(ctx context.Context, p types.PasswordPolicy) error
- func (s *Service) UnexpireAllPasswords(ctx context.Context) error
- func (s *Service) UnexpirePassword(ctx context.Context, name string) error
- func (s *Service) Unlock(ctx context.Context, names []string) error
- func (s *Service) UnlockAll(ctx context.Context) error
- func (s *Service) UpdateGroupMembers(ctx context.Context, name string, add, remove []string) ([]string, error)
- func (s *Service) UpdateUserGroups(ctx context.Context, name string, add, remove []string) ([]string, error)
- func (s *Service) User(ctx context.Context, name string) (types.User, error)
- func (s *Service) Users(ctx context.Context) ([]types.User, error)
- type UserPatch
Constants ¶
This section is empty.
Variables ¶
var ErrExists = errors.New("identity: already exists")
ErrExists answers a create-only call for a name already taken (409).
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.
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 ¶
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 ¶
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 ¶
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 ¶
DeleteUser removes a user, its group memberships and its tokens. The seeded admin and anonymous users and the last administrator stay.
func (*Service) ExpirationPolicy ¶
ExpirationPolicy returns the password expiration policy.
func (*Service) ExpireAllPasswords ¶
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 ¶
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) LockPolicy ¶
LockPolicy returns the user lock policy.
func (*Service) PasswordPolicy ¶
PasswordPolicy returns the stored policy, or types.DefaultPasswordPolicy while none is stored.
func (*Service) PatchGroup ¶
PatchGroup changes the fields p carries; Members, when present, replaces the membership.
func (*Service) PatchUser ¶
PatchUser changes the fields p carries; Groups, when present, replaces the membership.
func (*Service) PutGroup ¶
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 ¶
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 ¶
func (s *Service) SetExpirationPolicy( ctx context.Context, p types.PasswordExpirationPolicy, ) (types.PasswordExpirationPolicy, error)
SetExpirationPolicy stores p and returns what was stored.
func (*Service) SetLockPolicy ¶
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 ¶
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 ¶
SetPasswordPolicy stores p. The policy applies when a password is set or changed, not to passwords already stored.
func (*Service) UnexpireAllPasswords ¶
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 ¶
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 ¶
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) 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.
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.