Documentation
¶
Overview ¶
Package authz evaluates Artifactory's permission model (decision 0006) for one subject: the admin flag, the union of grants to a user and its groups, permission targets with Ant include and exclude patterns, the anonymous user, and token scopes, which only ever remove actions but for applied-permissions/admin, an administrator's token whatever its subject.
Role ¶
access module, core layer: the native permission evaluator, which checks permission targets, token scopes and the admin rules for one subject. It is a library: the authenticator and the access handlers build a Decider per request with New and ask it questions. Other modules reach it only as the access/api Decider (AsAPI), which holds the questions they ask; the questions about permission documents and the subject's own grants (Holds, Grantable, Self and ManagesResources) and the evaluator's building blocks (Actions and RepoConfig) stay on the concrete Decider, which only access code imports. The package imports the standard library, the kernel and kernel/antpath, the module's api, core/model and core/port, and artifacts/api/repo for ResolveKey alone, which maps a remote repository's cache key to the repository a target names.
Inputs ¶
- New: Sources (the permission and group stores, read once, and the anonymous access setting) and the accessapi.Subject the request acts as, with the scope of the token it carries, if any.
- ManagesResources: the user and group stores, whose role flags it reads.
- FromAPI: an accessapi.Decider to get the evaluator back from.
Outputs ¶
- *Decider, from New: the answers for one subject from one snapshot of the permissions. VisibleRepos describes the repositories IsRepoVisible admits as an accessapi.RepoVisibility, which a listing's store applies as a filter.
- AsAPI: the Decider as an accessapi.Decider, and FromAPI, the evaluator behind one.
- TargetAllows: whether a permission target's include and exclude patterns admit a path.
Invariants ¶
- A token scope only removes actions: a scoped subject is never allowed what the same subject without the scope is refused, except that applied-permissions/admin acts as an administrator (decision 0005).
- New reads the permissions once, and the Decider answers from that snapshot without writing, so one Decider may serve several goroutines and a permission change applies from the next request's Decider.
- A permission target naming a repository that no longer exists never matches, as Artifactory keeps such targets and ignores them, and a key "<remote>-cache" is judged as its remote.
- Every error starts "authz: " and names the read that failed: the subject's permissions, a user or a group.
- VisibleRepos().Has(r) equals IsRepoVisible(r) for every stored repository r: a listing filtered in its store shows exactly what one that asked about each repository showed.
References ¶
- Decision 0005: docs/research/decisions/0005-authentication-and-tokens.md (token scopes only narrow).
- Decision 0006: docs/research/decisions/0006-authorization-native-permission-model.md.
- Decision 0043: docs/research/decisions/0043-api-reliability.md, "Paging classes and the next pointer" (the store applies the caller's visibility).
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md ("Public types and published api surface": Decider is an interface in access/api; "Names the migration introduces", which lists AsAPI and FromAPI).
- Target layout: docs/research/architecture-options/5-modular-monolith.md, lines 272 to 288 (access core, authz at line 279), line 540 (authz.go with Decider and New) and line 990 (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/1063
Status ¶
Implemented P4: the evaluator with token scopes and the permission wire forms (pull request 92). Later changes limited a MANAGE holder's grants to the actions it holds (pull request 435), aligned the admin scope with 7.x (pull request 449), refused a MANAGE holder's changes to its own entries (pull request 459) and added the Manage Resources role (pull request 470). Moved here in P9d, which added AsAPI and FromAPI (pull request 1127). #1408 added VisibleRepos, so Get Repositories counts and pages what the caller sees in its store query (decision 0043).
Testing ¶
- authz_test.go: TestUnitEvaluation (every evaluation rule over one permission world, with and without token scopes), TestUnitScopedConfigurationAndSystem, TestUnitScopeLettersMapToActions, TestUnitNewReportsStoreFailures, TestUnitWireFormsEvaluateAlike, TestUnitRepoVisibleAndGroups, TestUnitTargetAllows, TestUnitHolds, TestUnitGrantable, TestUnitSelf and TestUnitManagesResources.
- api_test.go: TestUnitAsAPIAndFromAPI (the access/api view answers as the evaluator does, and a nil or foreign Decider converts to nothing).
- visibility_test.go: TestUnitVisibleReposDescribesIsRepoVisible (over a matrix of subjects, token scopes and repositories, the set VisibleRepos describes holds exactly what IsRepoVisible admits).
- username_test.go: TestUnitUsernameFolds (a subject named in another case holds the grants of its folded name, #1432).
The tests build the permission world on the access module's in-memory adapter.
Index ¶
- func AsAPI(d *Decider) accessapi.Decider
- func TargetAllows(t model.Target, path string, folder bool) bool
- type Decider
- func (d *Decider) Actions(rt accessapi.ResourceType, repo accessapi.Repo, path string, folder bool) accessapi.Actions
- func (d *Decider) Allows(rt accessapi.ResourceType, repo accessapi.Repo, path string, ...) bool
- func (d *Decider) AllowsAll(rt accessapi.ResourceType, repo accessapi.Repo, folder string, ...) bool
- func (d *Decider) AllowsFolder(rt accessapi.ResourceType, repo accessapi.Repo, path string, ...) bool
- func (d *Decider) Grantable(g model.Grants) accessapi.Actions
- func (d *Decider) Groups() []string
- func (d *Decider) Holds(g model.Grants, want accessapi.Actions) bool
- func (d *Decider) IsAdmin() bool
- func (d *Decider) IsRepoVisible(repo accessapi.Repo) bool
- func (d *Decider) ManagesResources(ctx context.Context, users port.UserStore, groups port.GroupStore) (bool, error)
- func (d *Decider) RepoConfig(key string) bool
- func (d *Decider) Self() (user string, groups []string)
- func (d *Decider) System(area string, want kernel.ScopeActions) bool
- func (d *Decider) VisibleRepos() accessapi.RepoVisibility
- type Sources
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Decider ¶
type Decider struct {
// contains filtered or unexported fields
}
Decider answers permission questions for one subject from one snapshot of the permissions. Its methods only read that snapshot, so one Decider may be used from several goroutines. The zero Decider holds no action and is no administrator.
func FromAPI ¶
FromAPI returns the evaluator behind d, for the questions only it answers (Holds, Grantable, Self, Actions, RepoConfig and ManagesResources), and true when d holds a non-nil *Decider. A nil d, a typed nil and any other implementation, such as a test fake, give nil and false.
func New ¶
New reads the permissions that apply to s and returns its Decider. An anonymous subject while anonymous access is off gets the zero Decider, without a read. A group of s that no longer exists grants nothing; any other failure to read a group or the permissions is returned, wrapped, with no Decider.
func (*Decider) Actions ¶
func (d *Decider) Actions( rt accessapi.ResourceType, repo accessapi.Repo, path string, folder bool, ) accessapi.Actions
Actions returns every action the subject holds on path in repo's resource. folder is true for a folder, which is also visible when a permitted path lies below it. Allows and AllowsFolder are built on it; accessapi.Decider leaves it out because other modules ask for the actions they need, never for the whole set.
func (*Decider) Allows ¶
func (d *Decider) Allows( rt accessapi.ResourceType, repo accessapi.Repo, path string, want accessapi.Actions, ) bool
Allows reports whether the subject holds every action in want on a file at path.
func (*Decider) AllowsAll ¶
func (d *Decider) AllowsAll( rt accessapi.ResourceType, repo accessapi.Repo, folder string, want accessapi.Actions, ) bool
AllowsAll reports whether the subject holds every action in want on every path below folder (accessapi.Decider.AllowsAll). It takes the actions of each rule whose include patterns match every path below the folder and none of whose exclude patterns can match one, and narrows them by the token scope's entries that cover the folder the same way, so each action it counts holds at each path below the folder, as Actions would find it there.
func (*Decider) AllowsFolder ¶
func (d *Decider) AllowsFolder( rt accessapi.ResourceType, repo accessapi.Repo, path string, want accessapi.Actions, ) bool
AllowsFolder is Allows for a folder.
func (*Decider) Grantable ¶
Grantable returns the actions the subject may grant or revoke in a permission section whose grants are g. An administrator may change any. A holder of MANAGE in g may change only the other actions it holds in g: Artifactory 7.x's default exclude-manage rule, without which a holder could hand out rights it lacks, or appoint and remove other managers (decision 0006). Anyone else may change none, so a holder of MANAGE in one section changes nothing in another. Only the permission service asks it, so accessapi.Decider leaves it out.
func (*Decider) Groups ¶
Groups returns the groups the subject acts through: all of its groups, or those a token scope names.
func (*Decider) Holds ¶
Holds reports whether g grants every action in want to the subject, directly or through a group it acts as. It answers questions about a permission document itself (who may manage it), not about content, which only the permission handlers ask, so accessapi.Decider leaves it out.
func (*Decider) IsRepoVisible ¶
IsRepoVisible reports whether the subject may see repo in a listing and read its configuration (decision 0006). An administrator sees everything. A token scope with repo entries sees exactly the repositories they name. Otherwise the subject sees a repository it may read anywhere in, and every repository through the system:info:r scope.
func (*Decider) ManagesResources ¶
func (d *Decider) ManagesResources( ctx context.Context, users port.UserStore, groups port.GroupStore, ) (bool, error)
ManagesResources reports whether the subject holds the Manage Resources role (the user's resources_manager, a group's manage_resources), which lets it manage every permission (decision 0006). The role follows the identities the subject acts as, as a group's admin privileges do: the user's own flag needs a scope that keeps the user, a group's a scope that keeps the group, and a scope of resource entries alone keeps neither. The flags are read here, not in New, because only the permission APIs ask, which is also why accessapi.Decider leaves it out.
func (*Decider) RepoConfig ¶
RepoConfig reports whether a token scope lets the subject read a repository's configuration. Without a scope, or with applied permissions and no repo entries, the permissions alone decide; repo entries (repo:<key>:r) narrow that to the repositories they name. accessapi.Decider leaves it out because other modules ask IsRepoVisible, which applies it with the permissions.
func (*Decider) Self ¶
Self returns the user the subject is and the groups it belongs to or acts through, whose entries in a permission are its own (decision 0006). A token scope does not narrow them: a token that acts only through a group is still its user's, so editing the user's entry with it is still a holder editing its own grants. Only the permission service asks it, so accessapi.Decider leaves it out.
func (*Decider) System ¶
func (d *Decider) System(area string, want kernel.ScopeActions) bool
System reports whether the subject may use a system capability (an area such as "info", "metrics" or "identities"): administrators may; anyone else only through a token's system scope covering the area and actions.
func (*Decider) VisibleRepos ¶
func (d *Decider) VisibleRepos() accessapi.RepoVisibility
VisibleRepos describes the repositories IsRepoVisible admits, step by step as it decides, so a listing's store can filter by it: an administrator's and a system:info:r scope's are every repository; repo entries' are the keys they name with read; otherwise the repositories a read rule's target covers at the root, narrowed by a token's artifact entries. Every rule grants the same root folder in every repository it covers, because its include and exclude patterns name paths, not repositories, so each one contributes its whole target.
type Sources ¶
type Sources struct {
Permissions port.PermissionStore
Groups port.GroupStore
// AnonymousEnabled is the security.anonymous_access setting; the
// anonymous user's grants apply only while it is on.
AnonymousEnabled bool
}
Sources is what New reads once per request: the permissions that apply to the subject and the groups it acts through, which may grant admin privileges. New calls each store in the caller's context, so the reads join the caller's transaction, if there is one.