workloadidentity

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package workloadidentity exchanges a workload's platform identity token (Kubernetes, AWS, GCP, Azure, GitHub Actions, SPIFFE) for a short-lived provider access token, so a provider can authenticate without a static API key.

A Source caches the access token and refreshes it ahead of expiry. The identity token file is re-read on every exchange because projected tokens rotate on disk. Neither the identity token nor the access token is ever logged or included in an error.

Index

Constants

View Source
const OpenAITokenEndpoint = "https://auth.openai.com/oauth/token" //nolint:gosec // G101: a public endpoint URL, not a credential.

OpenAITokenEndpoint is the default endpoint for the TokenExchange grant.

Variables

This section is empty.

Functions

func DefaultTokenEndpoint

func DefaultTokenEndpoint(grant Grant, baseURL string) string

DefaultTokenEndpoint returns the exchange endpoint used when none is configured. The jwt-bearer endpoint lives under the provider's API base URL (Anthropic: <base_url>/oauth/token), so a custom base URL moves it too.

Types

type Config

type Config struct {
	// Provider names the provider instance in logs.
	Provider string
	Grant    Grant
	// TokenEndpoint is the exchange URL; see DefaultTokenEndpoint.
	TokenEndpoint string
	config.WorkloadIdentityConfig
}

Config is a resolved workload identity configuration for one provider.

func (Config) Validate

func (c Config) Validate() error

Validate reports the first missing or unsupported setting. Errors name fields only, never values.

type Grant

type Grant string

Grant selects the OAuth grant a provider's token endpoint speaks.

const (
	// TokenExchange is the RFC 8693 token exchange OpenAI uses.
	TokenExchange Grant = "token_exchange"
	// JWTBearer is the RFC 7523 jwt-bearer grant Anthropic uses.
	JWTBearer Grant = "jwt_bearer"
)

type Source

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

Source hands out a cached provider access token, exchanging the identity token for a new one ahead of expiry. It is safe for concurrent use.

No exchange runs under the lock. While the cached token is still usable, callers get it immediately and one refresh runs in the background. Callers without a usable token wait for the shared exchange, and each stops waiting when its own context ends.

func New

func New(cfg Config, client *http.Client) (*Source, error)

New validates cfg and returns a Source that exchanges through client. No exchange happens until the first Token call.

func (*Source) Token

func (s *Source) Token(ctx context.Context) (string, error)

Token returns a valid access token. When the cached token is due for refresh but still usable, it is returned while a refresh runs in the background. Otherwise Token waits for an exchange, or returns the last exchange error while failures are backing off.

Jump to

Keyboard shortcuts

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