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
- func Fetch(ctx context.Context, client *http.Client, oidcURL, oidcToken, audience string) (string, error)
- func ParseJWTLifetime(token string) (iat, exp time.Time, err error)
- func ReadBounded(r io.Reader) ([]byte, error)
- func RequireGitHubOIDCHost(raw string) error
- func RequireSecureURL(what, raw string) error
- type Assertion
- type AssertionConfig
Constants ¶
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 ¶
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 ¶
ReadBounded reads at most MaxResponseBytes from r and errors when the body is larger, so an oversized response is never parsed.
func RequireGitHubOIDCHost ¶
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.
On a GitHub server other than github.com (GitHub Enterprise Server, or a GitHub-compatible API) the Actions token service is that server itself, so the host GITHUB_SERVER_URL names is accepted too. The runner sets GITHUB_SERVER_URL beside the request URL. github.com itself is never accepted as a token service.
func RequireSecureURL ¶
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.
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).