oidc

package
v1.0.0-alpha.43 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package oidc verifies CI OIDC ID tokens and reads a run's identity from them.

Only RS256 is accepted, the one algorithm both issuers' discovery documents list. docs/serve.md cites the source and retrieval date of every claim name, issuer URL and key set path below.

Index

Constants

View Source
const (

	// ReadInterval is the least time between two reads of one issuer's key
	// set, whatever the first read gave. A token whose key the set read last
	// does not hold waits for the next read, so no stream of tokens, forged or
	// not, reads the set more often, and a sender told the set cannot be read
	// finds it read afresh once this much time has passed.
	ReadInterval = time.Minute
)

Variables

View Source
var (
	ErrMalformed    = errors.New("oidc: malformed token")
	ErrAlgorithm    = errors.New("oidc: algorithm not accepted")
	ErrIssuer       = errors.New("oidc: unknown issuer")
	ErrUnknownKeyID = errors.New("oidc: the issuer's key set holds no such key id")
	ErrSignature    = errors.New("oidc: bad signature")
	ErrAudience     = errors.New("oidc: wrong audience")
	ErrExpired      = errors.New("oidc: token expired")
	ErrNotYetValid  = errors.New("oidc: token not yet valid")
	ErrClaims       = errors.New("oidc: run identity claims missing or invalid")
)

The refusals. A caller reports one answer to the sender for each of them but ErrKeySetUnavailable, and logs which.

View Source
var ErrKeySetUnavailable = errors.New("oidc: the issuer's key set cannot be read")

ErrKeySetUnavailable means the issuer's key set could not be read: no answer, an answer past its time, a status other than 200, or an answer that is not a key set. It says nothing about the token, which may be good, and the same token can be checked again once ReadInterval has passed.

Functions

This section is empty.

Types

type Identity

type Identity struct {
	Host  string
	Owner string
	// OwnerID is the number the issuer gives the owner: GitHub's
	// repository_owner_id, GitLab's namespace_id. A login can be given up and
	// taken by someone else, and the number stays with the account.
	OwnerID string
	// Namespace is the path OwnerID numbers, lower case: the owner's login on
	// GitHub, the project's whole namespace path on GitLab.
	Namespace  string
	Repository string
	// RepositoryID is GitHub's repository_id or GitLab's project_id.
	RepositoryID string
	RunID        string
	RunAttempt   string
	CommitSHA    string
	CommitIsHead bool
	Actor        string
	Event        string
	PullRequest  string
	// Ref is the ref the run is for, as GitHub's token states it, and empty
	// on GitLab.
	Ref string
	// RefProtected is the JSON text of GitHub's ref_protected claim, as the
	// token holds it, and empty when the token holds none. It is kept as
	// text, so a reader compares the claim's exact form and never a value
	// read loosely from it.
	RefProtected string
	// Environment is the GitHub deployment environment the job referenced,
	// empty when it referenced none. Its protection rules are the
	// repository's, so only a job they admitted carries it.
	Environment string
}

Identity is a run as the token states it. Repository is lower case, host and path, the form of the costroid/repo tag. PullRequest is empty unless the token itself names one.

CommitSHA is the commit the token verifies. It is the head of the ref only when CommitIsHead says so: on GitHub's pull_request event it is a merge commit, and on a GitLab merged results pipeline a temporary one.

type Issuer

type Issuer struct {
	Kind    Kind
	URL     string
	JWKSURL string
	// Host is the SCM host its repositories live on.
	Host string
}

Issuer is one trusted token issuer.

func GitHub

func GitHub() Issuer

GitHub is github.com's Actions issuer.

func GitLab

func GitLab(host string) Issuer

GitLab is a GitLab instance's CI issuer, given its host name.

func (Issuer) KeySetHost

func (i Issuer) KeySetHost() string

KeySetHost is the host the issuer's signing keys are read from, the one an egress allowlist must hold. GitHub's is not Host.

type Kind

type Kind int

Kind selects how an issuer's claims read.

const (
	GitHubActions Kind = iota + 1
	GitLabCI
)

The CI systems with a claim mapping.

type Verifier

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

Verifier checks tokens against a set of issuers and one audience.

func NewVerifier

func NewVerifier(audience string, client *http.Client, now func() time.Time, issuers ...Issuer) *Verifier

NewVerifier returns a Verifier that reads key sets through client. A nil clock means time.Now.

func (*Verifier) Verify

func (v *Verifier) Verify(ctx context.Context, token string) (Identity, error)

Verify checks a token and returns the run it names.

Directories

Path Synopsis
Package oidctest is a stub OIDC issuer for tests: an RSA key, a JWKS endpoint and a signer.
Package oidctest is a stub OIDC issuer for tests: an RSA key, a JWKS endpoint and a signer.

Jump to

Keyboard shortcuts

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