Documentation
¶
Overview ¶
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). Providers and mappings are configuration documents (configdoc.ConfigOIDC, configdoc.ConfigOIDCMapping) stored in their wire form, so they read back exactly as written.
Role ¶
access module, core layer: workload OIDC. The access module's HTTP adapter serves the provider, mapping and exchange operations through Service; no other module calls it. A subject token is verified through core/idtoken and the access token issued through core/token. The package imports the standard library, the kernel, platform/configdoc and the module's core/idtoken and core/token.
Inputs ¶
- Service: a Store whose Configs hold the providers and mappings, the token service, the ID token verifier and the clock.
- Providers, Provider, CreateProvider, UpdateProvider and DeleteProvider: provider names and Provider documents as the Access API sends them.
- Mappings, Mapping, CreateMapping, UpdateMapping and DeleteMapping: a provider's name, a project to list, and Mapping documents.
- Exchange: an ExchangeRequest, the exchange's form fields.
- CanonicalType: a provider type as a client spells it.
Outputs ¶
- Provider and Mapping documents as they were written; a mapping's project is derived from the project roles its scope names.
- Exchanged: the access token that the first matching mapping describes, issued by the token service, and its user name.
- ErrNotFound, ErrInvalid, ErrNoMatch and ErrUnverified, the last wrapping idtoken's errors; the HTTP adapter answers them 404, 400, 400 and 401.
Invariants ¶
- A mapping's project cannot change once it is stored, and a mapping names at most one project.
- An exchange tries the request's project's mappings first, then the global ones, never another project's; within each, lower priorities first and the first created among equals. The first mapping whose claims the token satisfies decides the token issued.
References ¶
- Decision 0019: docs/research/decisions/0019-human-authentication-tiers.md, lines 22 to 25 (workload OIDC exchange is implemented, apart from human login).
- Research 21: docs/research/21-oidc-token-exchange.md.
- Decision 0005: docs/research/decisions/0005-authentication-and-tokens.md (the tokens an exchange issues).
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md ("Package placement and names": idtoken stays a separate package).
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 283 (core/oidc) and line 1031 (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/83
- https://github.com/weaveplatform/artifactweave/issues/1073
Status ¶
Implemented P4: providers, identity mappings and the token exchange (pull request 145), with mappings aligned with 7.x after (pull requests 468, 486 and 499). Moved here in P9d, where Service.Store needs only the configuration documents.
Testing ¶
- oidc_test.go: TestUnitCanonicalType, TestUnitProviders, TestUnitMappings, TestUnitCombinations, TestUnitPatternSyntax, TestUnitProjectRolesWithoutUser, TestUnitMappingNamesOneProject, TestUnitExchangeOrder, TestUnitClaimMatching, TestUnitExchangeTokens, TestUnitExchangeRefuses and TestUnitProviderTypes; TestUnitStoreFailures and TestUnitCorruptDocuments fail the configuration store and corrupt its documents.
- pattern_test.go: TestUnitPatterns, TestUnitGroupPatterns, TestUnitUserScope and TestUnitResourcePatterns.
The tests run on the metadata store's in-memory store, with idtokentest as the provider.
Index ¶
- Constants
- Variables
- func CanonicalType(s string) (string, bool)
- type ExchangeRequest
- type Exchanged
- type Mapping
- type Provider
- type Service
- func (s Service) CreateMapping(ctx context.Context, provider string, m Mapping) (Mapping, error)
- func (s Service) CreateProvider(ctx context.Context, p Provider) (Provider, error)
- func (s Service) DeleteMapping(ctx context.Context, provider, name string) error
- func (s Service) DeleteProvider(ctx context.Context, name string) error
- func (s Service) Exchange(ctx context.Context, r ExchangeRequest) (Exchanged, error)
- func (s Service) Mapping(ctx context.Context, provider, name string) (Mapping, error)
- func (s Service) Mappings(ctx context.Context, provider, project string) ([]Mapping, error)
- func (s Service) Provider(ctx context.Context, name string) (Provider, error)
- func (s Service) Providers(ctx context.Context) ([]Provider, error)
- func (s Service) UpdateMapping(ctx context.Context, provider, name string, m Mapping) (Mapping, error)
- func (s Service) UpdateProvider(ctx context.Context, name string, p Provider) (Provider, error)
- type TokenSpec
Constants ¶
const ( GrantTokenExchange = "urn:ietf:params:oauth:grant-type:token-exchange" SubjectIDToken = "urn:ietf:params:oauth:token-type:id_token" IssuedAccessToken = "urn:ietf:params:oauth:token-type:access_token" )
The RFC 8693 identifiers of the exchange.
const ( TypeGeneric = "Generic OpenID Connect" TypeGitHub = "GitHub" TypeGitHubEnterprise = "GitHub Enterprise" TypeAzure = "Azure" )
Provider types in the Access vocabulary, which the jfrog/platform Terraform provider sends and reads back.
const DefaultExpiry = time.Hour
DefaultExpiry is the lifetime of a mapping's token when its spec sets none.
const MaxExpiry = 24 * time.Hour
MaxExpiry is the longest token a mapping issues: Access limits a mapping's expiration time to 24 hours.
Variables ¶
var ( // ErrNotFound reports a provider or mapping that does not exist. ErrNotFound = errors.New("oidc: not found") // ErrInvalid reports a configuration or exchange request the server // refuses as malformed. ErrInvalid = errors.New("oidc: invalid") // ErrNoMatch reports a verified token that no identity mapping accepts. ErrNoMatch = errors.New("oidc: no identity mapping matches the subject token") // ErrUnverified reports a subject token that does not verify. ErrUnverified = errors.New("oidc: the subject token does not verify") )
Functions ¶
func CanonicalType ¶
CanonicalType returns the Access form of a provider type; "" is generic.
Types ¶
type ExchangeRequest ¶
type ExchangeRequest struct {
GrantType, SubjectTokenType, SubjectToken string
ProviderName, ProjectKey, MappingName string
IncludeReference bool
JobID, RunID, Repo, Revision, Branch string
}
ExchangeRequest is a token exchange. The CI fields are recorded in the issued token's description for auditing.
type Mapping ¶
type Mapping struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Priority *int `json:"priority,omitempty"`
Claims map[string]any `json:"claims,omitempty"`
TokenSpec *TokenSpec `json:"token_spec,omitempty"`
ProjectKey *string `json:"project_key,omitempty"`
}
Mapping is an identity mapping in its wire form. ProjectKey is set by the server, from a project role in the scope.
type Provider ¶
type Provider struct {
Name *string `json:"name,omitempty"`
IssuerURL *string `json:"issuer_url,omitempty"`
Audience *string `json:"audience,omitempty"`
Description *string `json:"description,omitempty"`
ProviderType *string `json:"provider_type,omitempty"`
TokenIssuer *string `json:"token_issuer,omitempty"`
EnablePermissiveConfiguration *bool `json:"enable_permissive_configuration,omitempty"`
UseDefaultProxy *bool `json:"use_default_proxy,omitempty"`
AzureAppID *string `json:"azure_app_id,omitempty"`
Organization *string `json:"organization,omitempty"`
ProjectKey *string `json:"project_key,omitempty"`
}
Provider is an OIDC provider in its wire form.
type Service ¶
type Service struct {
// Store holds the providers and mappings as configuration documents.
// Each call joins the transaction ctx carries.
Store interface{ Configs() configdoc.ConfigStore }
Tokens *token.Service
Keys *idtoken.Verifier
// Now supplies the time; nil means time.Now.
Now func() time.Time
}
Service manages providers and mappings and exchanges tokens.
func (Service) CreateMapping ¶
CreateMapping adds m to a provider; a name in use is invalid.
func (Service) CreateProvider ¶
CreateProvider adds p; a name in use is invalid, as Access answers 400.
func (Service) DeleteMapping ¶
DeleteMapping removes one mapping.
func (Service) DeleteProvider ¶
DeleteProvider removes a provider and its mappings.
func (Service) Exchange ¶
Exchange verifies the request's ID token against its provider, finds the first identity mapping whose claims it satisfies, and issues the access token that mapping describes.
func (Service) UpdateMapping ¶
func (s Service) UpdateMapping( ctx context.Context, provider, name string, m Mapping, ) (Mapping, error)
UpdateMapping replaces the mapping name with m, keeping its place among equal priorities. Its project, which its scope's project roles imply, cannot change: "Attempting to change the project key returns 400 Bad Request" (Manage Project-Scoped Identity Mappings), from a project to none or another, or from none to one.
type TokenSpec ¶
type TokenSpec struct {
Username *string `json:"username,omitempty"`
UsernamePattern *string `json:"username_pattern,omitempty"`
GroupsPattern *string `json:"groups_pattern,omitempty"`
ResourcePattern *string `json:"resource_pattern,omitempty"`
Scope *string `json:"scope,omitempty"`
Audience *string `json:"audience,omitempty"`
ExpiresIn *int64 `json:"expires_in,omitempty"`
SelfRevocable *bool `json:"self_revocable,omitempty"`
}
TokenSpec shapes the access token a mapping issues.