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 ¶
- Variables
- func BuildAuthorizationURL(request AuthorizationURLRequest) (*url.URL, error)
- func BuildTokenRequest(request AuthorizationCodeRequest) (url.Values, error)
- func ExpireSessionCookie(policy CookiePolicy, now time.Time) (*http.Cookie, error)
- func ManagementPanelAllowed(decision ManagementDecision) bool
- func NewSessionCookie(policy CookiePolicy, now time.Time) (*http.Cookie, error)
- func PKCEChallenge(verifier string) (string, error)
- func ValidateAuthorizationCallback(values url.Values, expectedState string) (string, error)
- func ValidateBootstrapAdmins(admins []BootstrapAdmin) error
- type AuthorizationCodeRequest
- type AuthorizationSecrets
- type AuthorizationStateRecord
- type AuthorizationStateStore
- type AuthorizationURLRequest
- type BootstrapAdmin
- type CSRFManager
- type CookiePolicy
- type CredentialRef
- type DiscoveryMetadata
- type JWK
- type JWKS
- type ManagementDecision
- type PKCE
- type Runtime
- func (runtime *Runtime) Discovery() DiscoveryMetadata
- func (runtime *Runtime) JWKS(now time.Time) JWKS
- func (runtime *Runtime) ValidateCloudRINGDiscoveryPolicy(discovery DiscoveryMetadata) error
- func (runtime *Runtime) ValidateDiscovery(discovery DiscoveryMetadata) error
- func (runtime *Runtime) ValidateOIDCDiscovery(discovery DiscoveryMetadata) error
- func (runtime *Runtime) VerifyIDToken(token string, now time.Time, expectedNonce string) (VerifiedClaims, error)
- func (runtime *Runtime) VerifyJWT(token string, now time.Time) (VerifiedClaims, error)
- type RuntimeConfig
- type SameSiteMode
- type SecretKeyRef
- type SecretManagerRef
- type SessionStateRecord
- type SessionStateStore
- type SigningKey
- type StateReadiness
- type VerifiedClaims
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuthorizationStateInvalid = errors.New("identity: authorization state is invalid") ErrAuthorizationStateConsumed = errors.New("identity: authorization state was already consumed") )
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 ManagementPanelAllowed ¶
func ManagementPanelAllowed(decision ManagementDecision) bool
func NewSessionCookie ¶
func PKCEChallenge ¶
func ValidateBootstrapAdmins ¶
func ValidateBootstrapAdmins(admins []BootstrapAdmin) error
Types ¶
type AuthorizationSecrets ¶
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 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
type CookiePolicy ¶
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 ManagementDecision ¶
type PKCE ¶
func GeneratePKCE ¶
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) 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.
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 SecretManagerRef ¶
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 SessionStateStore ¶
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 ¶
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.