identity

package
v0.1.0-c01.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 23 Imported by: ? 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 identity implements provider-neutral OIDC discovery, profile-bound asymmetric JWT verification, JWKS rotation, bootstrap-credential references, secure session cookies, CSRF protection, and management-surface fail-closed gates.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthorizationStateInvalid  = errors.New("identity: authorization state is invalid")
	ErrAuthorizationStateConsumed = errors.New("identity: authorization state was already consumed")
	ErrSessionStateUnavailable    = errors.New("identity: session state is unavailable")
)

Functions

func BuildAuthorizationURL

func BuildAuthorizationURL(request AuthorizationURLRequest) (*url.URL, error)

func BuildTokenRequest

func BuildTokenRequest(request AuthorizationCodeRequest) (url.Values, error)

BuildTokenRequest returns only the public authorization-code exchange parameters. A confidential client credential, when required by a provider, belongs in the transport authentication layer and must not be added here.

func ExpireSessionCookie

func ExpireSessionCookie(policy CookiePolicy, now time.Time) (*http.Cookie, error)

func ManagementPanelAllowed

func ManagementPanelAllowed(decision ManagementDecision) bool

func NewSessionCookie

func NewSessionCookie(policy CookiePolicy, now time.Time) (*http.Cookie, error)

func PKCEChallenge

func PKCEChallenge(verifier string) (string, error)

func ValidateAuthorizationCallback

func ValidateAuthorizationCallback(values url.Values, expectedState string) (string, error)

func ValidateBootstrapAdmins

func ValidateBootstrapAdmins(admins []BootstrapAdmin) error

Types

type AuthorizationCodeRequest

type AuthorizationCodeRequest struct {
	TokenEndpoint string
	ClientID      string
	RedirectURI   string
	Code          string
	PKCEVerifier  string
}

type AuthorizationSecrets

type AuthorizationSecrets struct {
	State string
	Nonce string
	PKCE  PKCE
}

func GenerateAuthorizationSecrets

func GenerateAuthorizationSecrets() (AuthorizationSecrets, error)

type AuthorizationStateRecord

type AuthorizationStateRecord struct {
	StateHash          string
	NonceHash          string
	SealedNonce        []byte
	SealedPKCEVerifier []byte
	RedirectURI        string
	CreatedAt          time.Time
	ExpiresAt          time.Time
}

AuthorizationStateRecord contains only hashes and sealed transaction material. Raw browser state, nonce, authorization code, and PKCE verifier values must not be persisted.

type AuthorizationStateStore

type AuthorizationStateStore interface {
	StateReadiness
	Put(context.Context, AuthorizationStateRecord) error
	Consume(context.Context, string, time.Time) (AuthorizationStateRecord, error)
	DeleteExpired(context.Context, time.Time, int) (int, error)
}

AuthorizationStateStore must make Consume atomic. A state record can be returned at most once, including when multiple replicas race the callback.

type AuthorizationURLRequest

type AuthorizationURLRequest struct {
	AuthorizationEndpoint string
	ClientID              string
	RedirectURI           string
	Scopes                []string
	State                 string
	Nonce                 string
	PKCE                  PKCE
}

type BootstrapAdmin

type BootstrapAdmin struct {
	Username              CredentialRef      `json:"username"`
	PasswordHashRef       CredentialRef      `json:"passwordHashRef"`
	RecoveryCodes         SecretManagerRef   `json:"recoveryCodes"`
	MFARequired           bool               `json:"mfaRequired"`
	RotateAfterFirstLogin bool               `json:"rotateAfterFirstLogin"`
	AdditionalSecretRefs  []SecretManagerRef `json:"additionalSecretRefs,omitempty"`
}

type CSRFManager

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

func NewCSRFManager

func NewCSRFManager(keyMaterial []byte, maxAge time.Duration) CSRFManager

func (CSRFManager) Check

func (manager CSRFManager) Check(csrfValue, sessionID string, now time.Time) error

func (CSRFManager) Issue

func (manager CSRFManager) Issue(sessionID string, now time.Time) (string, error)

type CookiePolicy

type CookiePolicy struct {
	Name     string
	Value    string
	Path     string
	Lifetime time.Duration
	SameSite SameSiteMode
}

type CredentialRef

type CredentialRef struct {
	Env               string        `json:"env,omitempty"`
	ExternalSecretRef *SecretKeyRef `json:"externalSecretRef,omitempty"`
	Plaintext         string        `json:"plaintext,omitempty"`
}

type DiscoveryMetadata

type DiscoveryMetadata struct {
	Issuer                               string   `json:"issuer"`
	AuthorizationEndpoint                string   `json:"authorization_endpoint"`
	TokenEndpoint                        string   `json:"token_endpoint"`
	JWKSURI                              string   `json:"jwks_uri"`
	ResponseTypesSupported               []string `json:"response_types_supported"`
	SubjectTypesSupported                []string `json:"subject_types_supported"`
	IDTokenSigningAlgValuesSupported     []string `json:"id_token_signing_alg_values_supported"`
	TokenEndpointAuthMethodsSupported    []string `json:"token_endpoint_auth_methods_supported"`
	ClaimsSupported                      []string `json:"claims_supported"`
	CodeChallengeMethodsSupported        []string `json:"code_challenge_methods_supported"`
	CloudRINGJWKSCacheTTLSeconds         int64    `json:"cloudring_jwks_cache_ttl_seconds"`
	CloudRINGJWKSRotationOverlapSeconds  int64    `json:"cloudring_jwks_rotation_overlap_seconds"`
	CloudRINGManagementPanelIAMGate      string   `json:"cloudring_management_panel_iam_gate"`
	CloudRINGBootstrapAdminSecretPolicy  string   `json:"cloudring_bootstrap_admin_secret_policy"`
	CloudRINGBrowserWriteCSRFRequirement string   `json:"cloudring_browser_write_csrf_requirement"`
}

type JWK

type JWK struct {
	KTY string `json:"kty"`
	Use string `json:"use"`
	KID string `json:"kid"`
	Alg string `json:"alg"`
	N   string `json:"n,omitempty"`
	E   string `json:"e,omitempty"`
	Crv string `json:"crv,omitempty"`
	X   string `json:"x,omitempty"`
	Y   string `json:"y,omitempty"`
}

type JWKS

type JWKS struct {
	Keys []JWK `json:"keys"`
}

type ManagementDecision

type ManagementDecision struct {
	Authenticated bool
	TokenValid    bool
	IAMAllow      bool
	IAMErr        string
}

type PKCE

type PKCE struct {
	Verifier  string
	Challenge string
	Method    string
}

func GeneratePKCE

func GeneratePKCE() (PKCE, error)

type Runtime

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

func NewRuntime

func NewRuntime(config RuntimeConfig) (*Runtime, error)

func (*Runtime) Discovery

func (runtime *Runtime) Discovery() DiscoveryMetadata

func (*Runtime) JWKS

func (runtime *Runtime) JWKS(now time.Time) JWKS

func (*Runtime) ValidateCloudRINGDiscoveryPolicy

func (runtime *Runtime) ValidateCloudRINGDiscoveryPolicy(discovery DiscoveryMetadata) error

ValidateCloudRINGDiscoveryPolicy validates only the CloudRING extension fields emitted by a CloudRING-controlled issuer. External OIDC providers are not expected to publish these non-standard fields.

func (*Runtime) ValidateDiscovery

func (runtime *Runtime) ValidateDiscovery(discovery DiscoveryMetadata) error

func (*Runtime) ValidateOIDCDiscovery

func (runtime *Runtime) ValidateOIDCDiscovery(discovery DiscoveryMetadata) error

ValidateOIDCDiscovery validates the standard provider capabilities that the runtime actually consumes. Providers may advertise additional conforming capabilities; CloudRING-specific policy extensions are deliberately not evaluated here.

func (*Runtime) VerifyIDToken

func (runtime *Runtime) VerifyIDToken(token string, now time.Time, expectedNonce string) (VerifiedClaims, error)

VerifyIDToken verifies the configured JWT profile and binds the ID token to the nonce issued for the browser authorization transaction.

func (*Runtime) VerifyJWT

func (runtime *Runtime) VerifyJWT(token string, now time.Time) (VerifiedClaims, error)

type RuntimeConfig

type RuntimeConfig struct {
	Issuer                string
	AuthorizationEndpoint string
	TokenEndpoint         string
	JWKSURI               string
	Audience              string
	AuthorizedParty       string
	ExpectedJOSEType      string
	JWTClassClaim         string
	ExpectedJWTClass      string
	AllowedAlgorithms     []string
	RequiredClaims        []string
	GroupsClaim           string
	NamespacesClaim       string
	TokenMaxLifetime      time.Duration
	ClockSkew             time.Duration
	JWKSCacheTTL          time.Duration
	RotationOverlap       time.Duration
	Keys                  []SigningKey
}

type SameSiteMode

type SameSiteMode string
const (
	SameSiteLax    SameSiteMode = "Lax"
	SameSiteStrict SameSiteMode = "Strict"
)

type SecretKeyRef

type SecretKeyRef struct {
	Name string `json:"name"`
	Key  string `json:"key"`
}

type SecretManagerRef

type SecretManagerRef struct {
	Provider  string `json:"provider"`
	Reference string `json:"reference"`
}

type SessionStateRecord

type SessionStateRecord struct {
	TokenHash  string
	SubjectID  string
	CreatedAt  time.Time
	LastSeenAt time.Time
	ExpiresAt  time.Time
	RevokedAt  time.Time
}

SessionStateRecord uses the hash of an opaque session token as its key. Implementations must never persist the raw session token.

type SigningKey

type SigningKey struct {
	KeyID       string
	Algorithm   string
	PublicKey   any
	ActiveFrom  time.Time
	ActiveUntil time.Time
}

func SigningKeysFromJWKS

func SigningKeysFromJWKS(jwks JWKS) ([]SigningKey, error)

type StateReadiness

type StateReadiness interface {
	Ready(context.Context) error
}

StateReadiness reports whether the durable state dependency is usable. A successful result must reflect a real read/write-capable backend, not merely local configuration presence.

type VerifiedClaims

type VerifiedClaims struct {
	Issuer     string
	Audience   []string
	ExpiresAt  time.Time
	IssuedAt   time.Time
	Subject    string
	Nonce      string
	Groups     []string
	Namespaces []string
}

Jump to

Keyboard shortcuts

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