access

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 access is the access module's constructor: New(Deps) binds every access/api contract over the store and the services app builds, and publishes them as one API for app to hand to the other modules.

Role

access module, module root. Only app imports a module root; other modules reach access through access/api (decision 0044, dependency rules). The bindings wrap access core: the evaluator in access/core/authz, the authenticator in access/core/authn and the token service in access/core/token.

Inputs

Deps, which app passes New:

  • Store, required: the access ports (users, groups, permissions, tokens, keys, projects and API restrictions, with their transactions) and the settings, which the bindings read and write. App passes its composite store, which satisfies it.
  • Authenticator and Tokens, the authenticator and token service app built over the same store; either may be nil.
  • Settings, the access options published with the API.
  • Now and Log, the clock and logger of the services the module builds itself; it builds none yet, so New reads neither.

Outputs

  • Module, whose API returns one binding of each access/api contract: Authenticator, Authorizer, Tokens, Keys, Identity, Restrictions, Projects, Grants and AnonymousAccess, with the Settings.
  • KeysOf, ProjectsOf, AnonymousAccessOf, RestrictionsOf and TokensOf: the store-only bindings, for code that holds a store before any module exists, such as bootstrap, and the multipart upload service and the garbage collector, which app builds before the work queue.

Invariants

  • New does no I/O; it refuses only Deps without a store.
  • API().Authenticator is nil when Deps.Authenticator is, and API().Tokens when Deps.Tokens is: nil interfaces, never typed nils, so a caller's check for an absent service answers as its check of the legacy pointer did. No binding returns a typed nil Decider either.
  • Error texts are observable in API responses and logs, so the bindings keep those of the code they replace byte for byte: Authorize's "auth: permissions: %w", For's "anonymous access setting: %w" and "evaluate permissions: %w", ItemGrants' "permissions with target %s: %w", and the authenticator's, the token service's and the stores' own errors, returned unwrapped so that errors.Is and each caller's wrap still apply. Decide returns the evaluator's error unwrapped, for its caller to wrap.
  • Every binding uses its caller's context for the store, so a call inside a store transaction takes part in it, and reads current state on every call: nothing is cached.
  • Grants keeps the scans' order: ItemGrants tries targets in the order given and counts a permission once, for the first target whose patterns admit the path; AccessChange reads permissions in name order, in pages of its limit, counts each before comparing it, and refuses with accessapi.ErrScanLimit past the limit.

References

  • Context map, access row, as https://github.com/weaveplatform/artifactweave/issues/958 records it: owns users, groups, tokens, permissions, roles, projects, environments, LDAP, SAML, OIDC, sessions and SCIM; phases P4, P11, P12, P21 and P22.
  • Target layout: docs/research/architecture-options/5-modular-monolith.md, "Full package tree", lines 258-300, "Access and identity", lines 529-573, and "Composition root", lines 746-804.
  • Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md, "Placeholders", "Composition and HTTP" and "Names the migration introduces".
  • Decision 0005: docs/research/decisions/0005-authentication-and-tokens.md: the token binding keeps issuance and revocation rules by calling the service.
  • Decision 0006: docs/research/decisions/0006-authorization-native-permission-model.md, "Once per request": Authorize is the middleware's single evaluation, and For evaluates only a principal the middleware did not see.
  • Decision 0013: docs/research/decisions/0013-projects-and-environments.md: Projects returns environments as stored.
  • Decision 0019: docs/research/decisions/0019-human-authentication-tiers.md.
  • Decision 0043: docs/research/decisions/0043-api-reliability.md: Current refreshes the credential that replays recheck, and the API restriction is read on every check.
  • Plan: docs/implementation/plan.md#p9d-modular-monolith-migration, #p4-identity-and-authorization, #p11-projects-webhooks-retention-replication, #p12-descriptor-export-system-configuration-ldap, #p21-browser-and-enterprise-authentication, #p22-scim-and-identity-lifecycle.
  • https://github.com/weaveplatform/artifactweave/issues/966

Status

Implemented P9d: New, Module and the store-only bindings, binding every access/api contract over access core's authenticator, evaluator and token service and the store. The module's routes and background work (target layout, line 533) stay in the server and app for now.

Testing

  • TestUnitNew: a store is required and New calls none of its methods; without the services their fields are nil interfaces and every other contract is bound, and Settings is published.
  • TestUnitAuthenticatorBinding, TestUnitAuthorizerBinding, TestUnitTokensBinding: each method over the in-memory store and access core's services, the rechecks reading the module's token records, and a call inside a transaction taking part in it.
  • TestUnitAuthorizerErrors: Authorize's, For's and Decide's error texts, each with a nil Decider.
  • TestUnitStoreBindings: Keys, Identity, Projects, AnonymousAccess and Restrictions, through API and the store-only constructors, return the store's answers and its errors as it gave them.
  • TestUnitItemGrants, TestUnitAccessChange: the scans' target order and paging, their error texts, and AccessChange at exactly its limit and one past it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnonymousAccessOf

func AnonymousAccessOf(
	st interface{ Settings() settings.SettingsStore },
) accessapi.AnonymousAccess

AnonymousAccessOf returns the AnonymousAccess binding over st alone, for code that holds a store before any module exists, such as applying the bootstrap descriptor. The errors are the store's, unwrapped.

func KeysOf

func KeysOf(st port.Store) accessapi.Keys

KeysOf returns the Keys binding over st alone, for code that holds a store before any module exists, such as bootstrap and reseal. The errors are the store's, unwrapped.

func ProjectsOf

func ProjectsOf(st port.Store) accessapi.Projects

ProjectsOf returns the Projects binding over st alone, for code that holds a store before any module exists. The errors are the store's, unwrapped.

func RestrictionsOf

func RestrictionsOf(st Store) accessapi.Restrictions

RestrictionsOf returns the Restrictions binding over st alone, for code that holds a store before any module exists, such as the multipart upload service, which app builds before the work queue and so before the modules. It reads the stored restriction on every call, as API().Restrictions does.

func TokensOf

func TokensOf(st Store, svc *token.Service) accessapi.Tokens

TokensOf returns the Tokens binding over st and svc, for code that holds a store before any module exists, such as the garbage collector, which app builds before the work queue and so before the modules. It is nil when svc is: a nil interface, never a typed nil, as API().Tokens is. The errors are the service's and the store's, unwrapped.

Types

type Deps

type Deps struct {
	// Store holds the users, groups, permissions, tokens, keys, projects,
	// settings and API restrictions that the bindings read and write. It is
	// required.
	Store Store
	// Authenticator verifies credentials; nil leaves API().Authenticator nil,
	// as a server without authentication has none.
	Authenticator *authn.Authenticator
	// Tokens issues and revokes access tokens; nil leaves API().Tokens nil,
	// which the token endpoints answer 501.
	Tokens *token.Service
	// Settings are the access options that API() publishes to the other
	// modules.
	Settings accessapi.Settings
	// Now is the clock of the services the module builds itself; nil means
	// time.Now. New builds none: Authenticator and Tokens keep the clocks
	// app built them with, and every other binding takes the times it
	// compares from its caller, so New does not read it.
	Now func() time.Time
	// Log receives the logs of the services the module builds itself; nil
	// means slog.Default(). New builds none, and the bindings log nothing:
	// each returns its errors to its caller.
	Log *slog.Logger
}

Deps is what app passes New. The authenticator and the token service of access core are built by app, over the same store, until the module builds them itself.

type Module

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

Module is the access module as app holds it. It is safe for concurrent use: its bindings hold no state of their own beyond what Deps gave them.

func New

func New(d Deps) (*Module, error)

New binds every access/api contract over d's store and services. It does no I/O, so it cannot fail on a store that is unreachable; it refuses only Deps without a store. The bindings keep every error text of the code they replace, and each call uses its caller's context, so a call inside a store transaction takes part in it.

func (*Module) API

func (m *Module) API() accessapi.API

API returns the module's published surface: one binding of each access/api contract, with Authenticator and Tokens nil when New had no such service, and the Settings from Deps.

type Store

type Store interface {
	port.Store
	// Settings holds the anonymous access switch, which AnonymousAccess
	// reads and writes and the authorizer reads.
	Settings() settings.SettingsStore
}

Store is the access data the bindings read and write: the access ports and the settings that hold the anonymous access switch. The application passes its composite store. Every call joins the transaction ctx carries.

Directories

Path Synopsis
Package accesstest gives other modules' tests the real access module over a store: the authenticator, the permission evaluator and the token service that a running server builds, bound through access.New as app binds them, so that a test authenticates and authorises without importing access internals.
Package accesstest gives other modules' tests the real access module over a store: the authenticator, the permission evaluator and the token service that a running server builds, bound through access.New as app binds them, so that a test authenticates and authorises without importing access internals.
adapters
crowd
Package crowd will be the adapter for sign-in through Crowd.
Package crowd will be the adapter for sign-in through Crowd.
http
Package accesshttp is the access module's HTTP adapter: the authentication middleware, the access spec's server and the artifactory spec's security partial, with every access handler, the API restriction middleware and the access contributions to the router's request handling.
Package accesshttp is the access module's HTTP adapter: the authentication middleware, the access spec's server and the artifactory spec's security partial, with every access handler, the API restriction middleware and the access contributions to the router's request handling.
http/login
Package login will serve browser login and the native-client approval endpoints.
Package login will serve browser login and the native-client approval endpoints.
http/scim
Package scim will serve the SCIM endpoints: discovery, users, groups, filters, pagination and PATCH.
Package scim will serve the SCIM endpoints: discovery, users, groups, filters, pagination and PATCH.
httpsso
Package httpsso will be the adapter for trusted-proxy HTTP single sign-on.
Package httpsso will be the adapter for trusted-proxy HTTP single sign-on.
inmem
Package inmem is the in-memory implementation of the access module's stores: users, groups and their memberships, permissions, tokens, key pairs, certificates, trusted and signing keys, projects with their roles, environments, members and repository assignments, and API restrictions.
Package inmem is the in-memory implementation of the access module's stores: users, groups and their memberships, permissions, tokens, key pairs, certificates, trusted and signing keys, projects with their roles, environments, members and repository assignments, and API restrictions.
ldap
Package ldap will be the access module's LDAP client: binding against a directory and reading its users and groups.
Package ldap will be the access module's LDAP client: binding against a directory and reading its users and groups.
oidcidp
Package oidcidp will be the adapter for human sign-in through an OIDC or OAuth identity provider.
Package oidcidp will be the adapter for human sign-in through an OIDC or OAuth identity provider.
saml
Package saml will be the SAML identity-provider adapter of the access module.
Package saml will be the SAML identity-provider adapter of the access module.
sql
Package sql is the SQL implementation of the access module's stores: users, groups and their memberships, permissions, tokens, key pairs, certificates, trusted and signing keys, projects with their roles, environments, members and repository assignments, and API restrictions, with the module's registration with the SQL layer.
Package sql is the SQL implementation of the access module's stores: users, groups and their memberships, permissions, tokens, key pairs, certificates, trusted and signing keys, projects with their roles, environments, members and repository assignments, and API restrictions, with the module's registration with the SQL layer.
sql/migrations
Package migrations holds the access module's migration stream: the SQLite and PostgreSQL schema of the tables the module's SQL adapter owns.
Package migrations holds the access module's migration stream: the SQLite and PostgreSQL schema of the tables the module's SQL adapter owns.
storetest
Package storetest is the contract suite of the access module's stores: one set of expectations that every implementation of the user, group, permission, token, key, project and API restriction stores must meet.
Package storetest is the contract suite of the access module's stores: one set of expectations that every implementation of the user, group, permission, token, key, project and API restriction stores must meet.
api
Package api is the access module's published surface: the permission vocabulary, signing key pairs and certificates, the subject and repository that a permission question names, the helpers that recognise a token by its shape, the contracts through which other modules ask access to verify credentials, evaluate and decide permissions, issue and revoke tokens, and read keys, users, API restrictions, projects, permission grants and the anonymous access setting, and the context accessors that carry a request's principal together with its permission decider.
Package api is the access module's published surface: the permission vocabulary, signing key pairs and certificates, the subject and repository that a permission question names, the helpers that recognise a token by its shape, the contracts through which other modules ask access to verify credentials, evaluate and decide permissions, issue and revoke tokens, and read keys, users, API restrictions, projects, permission grants and the anonymous access setting, and the context accessors that carry a request's principal together with its permission decider.
accessapitest
Package accessapitest provides hand-written fakes of every access/api contract, for tests that need access's answers without a store or the access module: a configurable Decider, Authenticator and Authorizer, a Tokens that records its calls, map-backed Keys, Identity, Projects and AnonymousAccess, and scripted Grants and Restrictions.
Package accessapitest provides hand-written fakes of every access/api contract, for tests that need access's answers without a store or the access module: a configurable Decider, Authenticator and Authorizer, a Tokens that records its calls, map-backed Keys, Identity, Projects and AnonymousAccess, and scripted Grants and Restrictions.
core
authn
Package authn authenticates requests and seeds the built-in principals (decision 0005): a user name and password, an access or reference token and a registry token each become a kernel.Principal, and a principal kept for work that outlives its request is rechecked against current state before that work acts for it.
Package authn authenticates requests and seeds the built-in principals (decision 0005): a user name and password, an access or reference token and a registry token each become a kernel.Principal, and a principal kept for work that outlives its request is rechecked against current state before that work acts for it.
authz
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.
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.
federated
Package federated will link external identities to local subjects: account linking, group and role mapping, the MFA policy and local-admin recovery.
Package federated will link external identities to local subjects: account linking, group and role mapping, the MFA policy and local-admin recovery.
identity
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.
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.
idtoken
Package idtoken verifies ID tokens that an external OpenID Connect provider, typically a CI system, signed: the subject tokens of the Access OIDC token exchange (POST /access/api/v1/oidc/token, research 21).
Package idtoken verifies ID tokens that an external OpenID Connect provider, typically a CI system, signed: the subject tokens of the Access OIDC token exchange (POST /access/api/v1/oidc/token, research 21).
idtoken/idtokentest
Package idtokentest is a fake OpenID Connect provider for tests: it serves a discovery document and a JWKS, as GitHub Actions, GitLab and other CI systems do, and mints ID tokens signed with its current key.
Package idtokentest is a fake OpenID Connect provider for tests: it serves a discovery document and a JWKS, as GitHub Actions, GitLab and other CI systems do, and mints ID tokens signed with its current key.
ldap
Package ldap will hold the access module's LDAP rules: bind and the group synchronisation policy.
Package ldap will hold the access module's LDAP rules: bind and the group synchronisation policy.
model
Package model holds the access module's entity values: users and groups, permissions, roles, projects and environments, access tokens, trusted and signing keys and the access policies, with the conversions between the account and permission values and JFrog's wire forms.
Package model holds the access module's entity values: users and groups, permissions, roles, projects and environments, access tokens, trusted and signing keys and the access policies, with the conversions between the account and permission values and JFrog's wire forms.
oidc
Package oidc is the access module's workload OpenID Connect integration (research 21): the providers whose ID tokens artifactweave trusts, the identity mappings that turn a token's claims into an access token, and the token exchange that CI systems call (POST /access/api/v1/oidc/token).
Package oidc is the access module's workload OpenID Connect integration (research 21): the providers whose ID tokens artifactweave trusts, the identity mappings that turn a token's claims into an access token, and the token exchange that CI systems call (POST /access/api/v1/oidc/token).
permission
Package permission manages permission documents (decision 0006): the single internal shape behind the v1 and v2 permission-target APIs and the Access v2 permissions API.
Package permission manages permission documents (decision 0006): the single internal shape behind the v1 and v2 permission-target APIs and the Access v2 permissions API.
port
Package port declares the access module's store ports: users, groups, permissions, tokens, keys, projects and API restrictions, the values their listings take and return, and Store, every store the module owns.
Package port declares the access module's store ports: users, groups, permissions, tokens, keys, projects and API restrictions, the values their listings take and return, and Store, every store the module owns.
project
Package project will manage projects: membership, quotas and environments, and attaching repositories to projects.
Package project will manage projects: membership, quotas and environments, and attaching repositories to projects.
roles
Package roles manages global roles and global environments: the Access API's /api/v1/roles and /api/v1/environments (issue #77, decision 0013).
Package roles manages global roles and global environments: the Access API's /api/v1/roles and /api/v1/environments (issue #77, decision 0013).
scim
Package scim will hold SCIM provisioning: user and group reconciliation, conflict rules and deprovisioning.
Package scim will hold SCIM provisioning: user and group reconciliation, conflict rules and deprovisioning.
session
Package session will hold browser sessions and native-client approval flows: sessions, CSRF protection, approvals and PKCE.
Package session will hold browser sessions and native-client approval flows: sessions, CSRF protection, approvals and PKCE.
token
Package token issues, refreshes, verifies and revokes Access tokens (decision 0005): RS256 JWTs signed with a per-instance key, with the reference and refresh tokens that go with them, and the short-lived registry tokens of the Docker token flow.
Package token issues, refreshes, verifies and revokes Access tokens (decision 0005): RS256 JWTs signed with a per-instance key, with the reference and refresh tokens that go with them, and the short-lived registry tokens of the Docker token flow.

Jump to

Keyboard shortcuts

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