actionsoidc

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package actionsoidc fetches a GitHub Actions OIDC assertion (a JWT) from the runner's token service. It is provider-neutral: the inference gateway route (ADR 0137) uses the assertion as its credential directly, and package openaiwif exchanges one for an OpenAI access token.

The OIDC endpoint is a trusted, fixed channel rather than user or remote configuration: GitHub injects it into the job as a runner-only, deny-listed variable. So this client is outside the SSRF-hardening scope described in docs/contributing/go-code.md ("Secure HTTP clients"). It still applies the baseline that section asks of every client: HTTPS only, an explicit timeout, and a bounded response body.

Index

Constants

View Source
const (
	// MaxResponseBytes bounds how many bytes a response may carry. The
	// responses are small JSON; a larger body is an error, not something
	// to parse.
	MaxResponseBytes = 1 << 20 // 1 MiB

	// HTTPTimeout is the per-request timeout of the default client.
	HTTPTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func Fetch

func Fetch(ctx context.Context, client *http.Client, oidcURL, oidcToken, audience string) (string, error)

Fetch requests a GitHub OIDC JWT from the runner's token endpoint with client and returns it unparsed. It does not check the URL: callers run RequireSecureURL and RequireGitHubOIDCHost first, as FetchAssertion does. Errors never include the assertion.

func ParseJWTLifetime

func ParseJWTLifetime(token string) (iat, exp time.Time, err error)

ParseJWTLifetime decodes the iat and exp claims from a JWT's payload without verifying its signature. Both claims are required, and exp must be after iat. Errors never include the token.

func ReadBounded

func ReadBounded(r io.Reader) ([]byte, error)

ReadBounded reads at most MaxResponseBytes from r and errors when the body is larger, so an oversized response is never parsed.

func RequireGitHubOIDCHost

func RequireGitHubOIDCHost(raw string) error

RequireGitHubOIDCHost rejects an assertion URL that does not point at GitHub's Actions token service (loopback is allowed for tests). The URL is runner-injected and deny-listed, so this is defence in depth against a rewritten runner environment, not SSRF hardening.

func RequireSecureURL

func RequireSecureURL(what, raw string) error

RequireSecureURL rejects anything but https, except plain http to a loopback address (test servers).

Types

type Assertion

type Assertion struct {
	// Value is the JWT. Never log, print, or include in error messages.
	Value string

	// IssuedAt is the token's iat claim.
	IssuedAt time.Time

	// ExpiresAt is the token's exp claim.
	ExpiresAt time.Time
}

Assertion is a fetched GitHub OIDC JWT with the lifetime claims read from its payload. The claims are decoded without verifying the signature: the gateway verifies the token, and the runner only uses them to schedule a re-fetch before the token expires.

func FetchAssertion

func FetchAssertion(ctx context.Context, cfg AssertionConfig) (*Assertion, error)

FetchAssertion requests a GitHub OIDC assertion for cfg.Audience and returns it with its iat and exp claims. Errors never include the assertion value.

func (*Assertion) Lifetime

func (a *Assertion) Lifetime() time.Duration

Lifetime returns exp - iat.

type AssertionConfig

type AssertionConfig struct {
	// Audience is the OIDC audience the assertion is minted for.
	Audience string

	// OIDCRequestURL is the ACTIONS_ID_TOKEN_REQUEST_URL from the runner.
	OIDCRequestURL string

	// OIDCRequestToken is the ACTIONS_ID_TOKEN_REQUEST_TOKEN from the runner.
	OIDCRequestToken string

	// HTTPClient overrides the HTTP client. Tests only: a caller-supplied
	// client bypasses the default redirect refusal.
	HTTPClient *http.Client
}

AssertionConfig holds the inputs for a bare GitHub OIDC assertion fetch: no exchange follows, so the assertion itself is the credential (the inference gateway route, ADR 0137).

Jump to

Keyboard shortcuts

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