oidc

package
v0.1.4875 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 27 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 lets a CI job trade an OIDC token for a short-lived gateway key (#4531, xazaj on X: GitHub Actions' token in place of a key kept in the repository's secrets). The user writes a rule: which issuer, which audience, which claims (repository, ref, environment…), and which of their gateway keys the key is issued under; a token that is signed by that issuer and matches every claim gets a key, held to everything that gateway key is held to and living no longer than the rule says.

No rule, no exchange: none is made by default.

Index

Constants

View Source
const DefaultTTL = time.Hour

DefaultTTL is how long a key lives when the rule says nothing.

View Source
const GitHub = "https://token.actions.githubusercontent.com"

GitHub is GitHub Actions' issuer, a rule's when it names none.

Variables

View Source
var Client = &http.Client{Timeout: 10 * time.Second}

Client fetches the issuers' keys; a variable for the tests, which serve them from an httptest TLS server and never reach the network.

View Source
var Now = time.Now

Now is the clock tokens are judged by.

Functions

func Match

func Match(ctx context.Context, token string) (Rule, Claims, error)

Match verifies token and finds the first rule it satisfies. A token is judged only against rules that name its issuer, so an issuer no rule names is never asked for keys: a token can't make magpie fetch from a URL of its choosing.

func Path

func Path() string

Path is the rules' file.

func Remove

func Remove(id string) error

Remove takes the rule id away.

Types

type Claims

type Claims map[string]any

Claims are a verified token's claims.

func (Claims) Str

func (c Claims) Str(name string) string

Str is claim c as text: a string as it is, a number or bool written out.

type Rule

type Rule struct {
	ID string `json:"id"`
	// Key is the id of the gateway key the keys are issued under; it must
	// be let issue keys (magpie gateway-key issuer <id> on).
	Key    string `json:"key"`
	Issuer string `json:"issuer"`
	// Audience is the token's aud the rule takes: by default
	// "magpie-<id>", so a token asked for one rule opens no other.
	Audience string `json:"audience"`
	// Claims each name a claim and the value it must have: exact, or a
	// glob as path.Match reads it ("refs/heads/release/*").
	Claims map[string]string `json:"claims"`
	// TTL is the longest a key it issues lives, in seconds.
	TTL int64 `json:"ttl"`
}

Rule is one way in.

func Add

func Add(r Rule) (Rule, error)

Add checks r and keeps it, and gives it back with its id and defaults.

func List

func List() ([]Rule, error)

List is every rule.

func (Rule) Lifetime

func (r Rule) Lifetime() time.Duration

Lifetime is the rule's TTL as a duration.

Directories

Path Synopsis
Package oidctest serves an OIDC issuer on an httptest TLS server for the tests of package oidc and the gateway: its discovery document, its keys and the tokens it signs, never reaching the network.
Package oidctest serves an OIDC issuer on an httptest TLS server for the tests of package oidc and the gateway: its discovery document, its keys and the tokens it signs, never reaching the network.

Jump to

Keyboard shortcuts

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