identity

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 13 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.

Role

access module, core layer: the identity service. The legacy security API handlers (/artifactory/api/security/users, groups, locks and policies) and the Access v2 user and group handlers in access/adapters/http build a Service over the configured store and call it; other modules reach users and groups only through access/api. The package imports the standard library, the kernel, platform/settings, and the module's core/authn (the password hash and the lock and expiration policy reads), core/model and core/port.

Inputs

  • Service: a Store (the access ports with their unit of work, and the settings store), which the metadata store satisfies; the password hash cost; a clock.
  • Users and groups in model form with clear-text passwords, partial updates (UserPatch, GroupPatch), membership add and remove lists, and the lock, expiration, password and Access lock policies.

Outputs

  • Users and groups in the access stores, with argon2id password hashes and the auto-join groups a new user joins; the policies in the settings store; locks cleared, passwords expired and the encrypted passwords that follow a changed password revoked.
  • ErrInvalid (with ErrProtected for a change to a built-in principal) and ErrExists for a refused request; store errors, kernel.ErrNotFound among them, come back for the handlers to map. The service words an unknown group in a user write, and an unknown member in a legacy group write, itself ("Group 'x' does not exist"), so the answer is the same on every store (#1433).

Invariants

  • A change that takes several store calls runs in one transaction of the Store, so a write that fails part way leaves nothing behind.
  • Every user name a method is given is folded (model.FoldUsername) before it reaches a store, so the stores hold lower-case names only and BOB names bob everywhere (#1432). A user row stored in mixed case before that rule is not rewritten: the preview has no data upgrades, so it is no longer reached by name, and is recreated under the lower-case name instead.
  • The last administrator cannot be deleted or demoted, and the seeded admin and anonymous users cannot be deleted.
  • A changed or expired password revokes the user's encrypted password, so a value issued for the old password stops working.

References

  • Decision 0005: docs/research/decisions/0005-authentication-and-tokens.md.
  • Decision 0019: docs/research/decisions/0019-human-authentication-tiers.md (internal users and passwords are the first tier).
  • Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md (modules reach each other through api packages; module stores).
  • Target layout: docs/research/architecture-options/5-modular-monolith.md, line 280 (core/identity) and line 1028 (the package mapping row).
  • Plan: docs/implementation/plan.md#p4-identity-and-authorization and #p9d-modular-monolith-migration, epic ACC (https://github.com/weaveplatform/artifactweave/issues/940).
  • https://github.com/weaveplatform/artifactweave/issues/1065

Status

Implemented P4: the legacy security API's users, groups and policies (pull request 97), Access v2 users and groups and the password policy (pull request 105), the encrypted password tied to the password (pull request 108), the Access user lock policy (pull request 242), the legacy password endpoints (pull request 466) and login suspension, filters and limits (pull request 470). Moved here in P9d, where Service takes Store. Access v2's create or replace of a group (ReplaceGroup) came with issue 1200, and the user name rule and the service's wording of an unknown group or member with issues 1432 and 1433.

Testing

  • identity_test.go: TestUnitPutUser, TestUnitPatchUser, TestUnitLastAdminAndDeletion, TestUnitGroups, TestUnitLocksAndExpiry, TestUnitPolicies, TestUnitAccessLockPolicy, TestUnitEncryptedPasswordFollowsThePassword, TestUnitChangePassword and TestUnitChangePasswordRaces.
  • access_test.go: TestUnitCreateOnly, TestUnitMemberships, TestUnitPasswordPolicyRules, TestUnitBulkPasswordExpiry, TestUnitBulkExpiryRevokesEncryptedPasswords and TestUnitAccessStoreFailures.
  • fault_test.go: TestUnitStoreFailures and TestUnitAccessLockPolicyStoreFailures.
  • replace_group_test.go: TestUnitReplaceGroupCreates, TestUnitReplaceGroupResetsEachField, TestUnitReplaceGroupSetsEachField, TestUnitReplaceGroupRefusals and TestUnitReplaceGroupOneTransaction.
  • username_test.go: TestUnitUsernamesFold, TestUnitUsernameTokensRevoked, TestUnitUnknownGroupOrMember and TestUnitUnknownGroupStoreFailures (user names in any case, and the service's wording of an unknown group or member, #1432 and #1433).

The tests run on the metadata store's in-memory store, seeded with the built-in principals through a stand-in for the artifacts module's repositories (repositories_test.go).

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 with the message after the sentinel, which the service words itself so that it is the same on every store.

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
	model.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 holds the users, groups and policies. Every change runs in one
	// Tx of Store, and the calls it makes join it through the context.
	Store Store
	// Hash is the password hash cost; the zero value is production's.
	Hash authn.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 model.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. Member names are folded. An unknown member is kernel.ErrNotFound, which Access v2 documents as 404; the legacy PutGroup answers it 400.

func (*Service) CreateUser

func (s *Service) CreateUser(ctx context.Context, u model.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. u.Name is folded, so Bob beside bob is taken.

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, in whatever case the request spells them.

func (*Service) ExpirationPolicy

func (s *Service) ExpirationPolicy(ctx context.Context) (model.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, as the request spelled them.

func (*Service) Group

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

Group returns one group with its members.

func (*Service) GroupPages

func (s *Service) GroupPages() *kernel.Pages[model.Group]

GroupPages walks the groups a store page at a time, in Groups' order, for a list written as it is read.

func (*Service) Groups

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

Groups returns every group, ordered by name.

func (*Service) LockPolicy

func (s *Service) LockPolicy(ctx context.Context) (model.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) LockedPages

func (s *Service) LockedPages() *kernel.Pages[string]

LockedPages walks the locked users' names a store page at a time, in Locked's order, for a list written as it is read.

func (*Service) PasswordPolicy

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

PasswordPolicy returns the stored policy, or model.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 model.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. Member names are folded; the group's name keeps its case.

func (*Service) PutUser

func (s *Service) PutUser(ctx context.Context, u model.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. u.Name is folded (model.FoldUsername), so the legacy PUT of Dan creates or replaces dan.

func (*Service) ReplaceGroup

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

ReplaceGroup creates g with members, as CreateGroup does, when no group has g's name, and otherwise replaces that group with g; it reports whether it created the group. It is Access v2's create or replace, not the legacy PutGroup: JFrog's Replace or Create a Group resets every field a request leaves out to its create default, so g is stored as given (the caller fills the defaults) and members replaces the membership even when empty. What the request cannot carry survives: the realm and realm attributes, which the page says a replacement keeps, and the platform auditor flag, which no group request sets. Member names are folded. An unknown member is kernel.ErrNotFound, which Access v2 documents as 404.

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 model.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 model.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, in whatever case they are spelled; unknown names are ignored. RTFACT-29660 reports that 7.55.13's unlockUsers ignores TEST_user for the user test_user, a bug against Access's own rule, so this does not follow it. 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. Both lists' names are folded. Unknown users in add are kernel.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, worded by requireGroups.

func (*Service) User

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

User returns one user, found by name in any case and named as stored.

func (*Service) UserPages

func (s *Service) UserPages() *kernel.Pages[model.User]

UserPages walks the users a store page at a time, in Users' order, for a list written as it is read.

func (*Service) Users

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

Users returns every user, ordered by name.

type Store

type Store interface {
	port.Store
	// Settings returns the settings store, which holds the user lock,
	// password expiration and password policies. Its calls join the
	// transaction the context carries.
	Settings() settings.SettingsStore
}

Store is what the identity service reads and writes: the access module's stores, of which it uses the user, group, permission and token stores, their unit of work (port.Store's Tx), and the settings that hold the account policies. The application passes its composite store, which satisfies it.

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