oidc

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package oidc is Access's 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 (types.ConfigOIDC, types.ConfigOIDCMapping) stored in their wire form, so they read back exactly as written.

Index

Constants

View Source
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.

View Source
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.

View Source
const DefaultExpiry = time.Hour

DefaultExpiry is the lifetime of a mapping's token when its spec sets none.

View Source
const MaxExpiry = 24 * time.Hour

MaxExpiry is the longest token a mapping issues: Access limits a mapping's expiration time to 24 hours.

Variables

View Source
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

func CanonicalType(s string) (string, bool)

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 Exchanged

type Exchanged struct {
	token.Issued
	Username string
}

Exchanged is the token an exchange issued.

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.

func (Provider) Type

func (p Provider) Type() string

Type is the provider's type in the Access vocabulary.

type Service

type Service struct {
	Store  store.Store
	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

func (s Service) CreateMapping(ctx context.Context, provider string, m Mapping) (Mapping, error)

CreateMapping adds m to a provider; a name in use is invalid.

func (Service) CreateProvider

func (s Service) CreateProvider(ctx context.Context, p Provider) (Provider, error)

CreateProvider adds p; a name in use is invalid, as Access answers 400.

func (Service) DeleteMapping

func (s Service) DeleteMapping(ctx context.Context, provider, name string) error

DeleteMapping removes one mapping.

func (Service) DeleteProvider

func (s Service) DeleteProvider(ctx context.Context, name string) error

DeleteProvider removes a provider and its mappings.

func (Service) Exchange

func (s Service) Exchange(ctx context.Context, r ExchangeRequest) (Exchanged, error)

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) Mapping

func (s Service) Mapping(ctx context.Context, provider, name string) (Mapping, error)

Mapping returns one mapping.

func (Service) Mappings

func (s Service) Mappings(ctx context.Context, provider, project string) ([]Mapping, error)

Mappings returns a provider's mappings, only project's when it is set.

func (Service) Provider

func (s Service) Provider(ctx context.Context, name string) (Provider, error)

Provider returns one provider.

func (Service) Providers

func (s Service) Providers(ctx context.Context) ([]Provider, error)

Providers returns every provider, by name.

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.

func (Service) UpdateProvider

func (s Service) UpdateProvider(ctx context.Context, name string, p Provider) (Provider, error)

UpdateProvider replaces the provider name with p, whose name, when set, must be name.

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.

Jump to

Keyboard shortcuts

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