Help us shape the future of Go! Take the 2026 Go Developer Survey

authz

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package authz evaluates Artifactory's permission model (decision 0006): the admin flag, the union of grants to a user and their 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. It is a library: handlers build a Decider per request and ask it questions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TargetAllows

func TargetAllows(t types.Target, path string, folder bool) bool

TargetAllows reports whether a permission target's include and exclude patterns admit path, a folder admitting what lies below it.

Types

type Decider

type Decider struct {
	// contains filtered or unexported fields
}

Decider answers permission questions for one subject from one snapshot of the permissions.

func New

func New(ctx context.Context, src Sources, s Subject) (*Decider, error)

New reads the permissions that apply to s and returns its Decider.

func (*Decider) Actions

func (d *Decider) Actions(
	rt types.ResourceType,
	repo Repo,
	path string,
	folder bool,
) types.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.

func (*Decider) Admin

func (d *Decider) Admin() bool

Admin reports whether the subject acts as an administrator.

func (*Decider) Allows

func (d *Decider) Allows(rt types.ResourceType, repo Repo, path string, want types.Actions) bool

Allows reports whether the subject holds every action in want on a file at path.

func (*Decider) AllowsFolder

func (d *Decider) AllowsFolder(
	rt types.ResourceType,
	repo Repo,
	path string,
	want types.Actions,
) bool

AllowsFolder is Allows for a folder.

func (*Decider) Grantable

func (d *Decider) Grantable(g types.Grants) types.Actions

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.

func (*Decider) Groups

func (d *Decider) Groups() []string

Groups returns the groups the subject acts through: all of its groups, or those a token scope names.

func (*Decider) Holds

func (d *Decider) Holds(g types.Grants, want types.Actions) bool

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.

func (*Decider) ManagesResources

func (d *Decider) ManagesResources(
	ctx context.Context,
	users store.UserStore,
	groups store.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.

func (*Decider) RepoConfig

func (d *Decider) RepoConfig(key string) bool

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.

func (*Decider) RepoVisible

func (d *Decider) RepoVisible(repo Repo) bool

RepoVisible 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) Self

func (d *Decider) Self() (user string, groups []string)

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.

func (*Decider) System

func (d *Decider) System(area string, want types.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.

type Pattern

type Pattern struct {
	// contains filtered or unexported fields
}

Pattern is a compiled Ant-style path pattern: '/' separates segments, "**" matches zero or more segments, '*' any run of characters within a segment, '?' exactly one character. Matching is case-sensitive and paths are relative to the repository root.

func CompilePattern

func CompilePattern(p string) Pattern

CompilePattern compiles p. A leading '/' is ignored and a trailing '/' means everything below, as in Ant ("dir/" is "dir/**").

func (Pattern) Match

func (p Pattern) Match(path string) bool

Match reports whether the pattern matches path ("" is the repository root, which only patterns that can match zero segments match).

func (Pattern) MatchBelow

func (p Pattern) MatchBelow(folder string) bool

MatchBelow reports whether the pattern could match some path below folder, so a listing can show the folders that lead to permitted content (Ant's matchPatternStart).

type Repo

type Repo struct {
	Key   string
	Class string
}

Repo identifies a permission target: a repository's key and class (local, remote, virtual, federated, distribution), or the fixed build-info or release-bundle repository of those resources. "<remote>-cache" is accepted for a remote's cache and resolves to the remote.

type RepoPatterns

type RepoPatterns struct {
	// contains filtered or unexported fields
}

RepoPatterns are a repository's include and exclude patterns: Ant patterns, comma-separated in the configuration. AQL filters what it finds with them, and the generic format refuses writes they reject.

func PatternsOf

func PatternsOf(c repo.Config) RepoPatterns

PatternsOf compiles c's patterns. An unset or empty includesPattern includes everything, as Artifactory's default "**/*" does.

func (RepoPatterns) Accepts

func (p RepoPatterns) Accepts(path string, folder bool) bool

Accepts reports whether the patterns admit path. A folder is admitted when an include could match something below it, so the folders leading to included files stay visible.

type Sources

type Sources struct {
	Permissions store.PermissionStore
	Groups      store.GroupStore
	// AnonymousEnabled is the security.anonymous_access setting; the
	// anonymous user's grants apply only while it is on.
	AnonymousEnabled bool
}

Sources is what a Decider reads once per request.

type Subject

type Subject struct {
	Name      string
	Groups    []string
	Admin     bool
	Anonymous bool
	// Scope is the scope of the token the request carries; nil for password
	// authentication, which acts with everything the subject holds.
	Scope *types.Scope
}

Subject is who a request acts as. Groups are the groups the subject belongs to; the token service (#74) may instead put a token's scoped groups here when it mints a token for a subject that is not a user.

Jump to

Keyboard shortcuts

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