Documentation
¶
Index ¶
- Constants
- func AuthClientLoader(secrets kdexv1alpha1.ServiceAccountSecrets) (map[string]AuthClient, error)
- func DiscoveryHandler(issuer string) http.HandlerFunc
- func FormatADGUID(b []byte) (string, error)
- func JWKSHandler(keyPairs *keys.KeyPairs) http.HandlerFunc
- func NewLDAPLookup(secret corev1.Secret) *ldapLookup
- func NewRoleProvider(ctx context.Context, c client.Client, focalHost string, ...) (*scopeProvider, error)
- func NewSecretLookup(secrets kdexv1alpha1.ServiceAccountSecrets) *secretLookup
- func OIDCConfigLoader(secrets kdexv1alpha1.ServiceAccountSecrets, devMode bool) (string, string, string, error)
- func SetAuthContext(ctx context.Context, ac AuthContext) context.Context
- func WithAuthentication(publicKey crypto.PublicKey, cookieName string) func(http.Handler) http.Handler
- type AuthClient
- type AuthContext
- func (ac AuthContext) GetAudience() (jwt.ClaimStrings, error)
- func (ac AuthContext) GetAuthMethod() (AuthMethod, error)
- func (ac AuthContext) GetEntitlements() ([]string, error)
- func (ac AuthContext) GetExpirationTime() (*jwt.NumericDate, error)
- func (ac AuthContext) GetIssuedAt() (*jwt.NumericDate, error)
- func (ac AuthContext) GetIssuer() (string, error)
- func (ac AuthContext) GetNotBefore() (*jwt.NumericDate, error)
- func (ac AuthContext) GetRoles() ([]string, error)
- func (ac AuthContext) GetScopes() ([]string, error)
- func (ac AuthContext) GetSubject() (string, error)
- type AuthMethod
- type AuthorizationChecker
- type AuthorizationCodeClaims
- type CompiledMappingRule
- type Config
- type ContextKey
- type Exchanger
- func (e *Exchanger) AuthCodeURL(state string) string
- func (e *Exchanger) CreateAuthorizationCode(ctx context.Context, claims AuthorizationCodeClaims) (string, error)
- func (e *Exchanger) EndSessionURL() (string, error)
- func (e *Exchanger) ExchangeCode(ctx context.Context, code string) (string, error)
- func (e *Exchanger) ExchangeToken(ctx context.Context, rawIDToken string) (string, error)
- func (e *Exchanger) GetClient(clientID string) (AuthClient, bool)
- func (e *Exchanger) GetOIDCClientID() string
- func (e *Exchanger) GetScopesSupported() ([]string, error)
- func (e *Exchanger) GetTokenTTL() time.Duration
- func (e *Exchanger) IsRefreshTokenEnabled() bool
- func (e *Exchanger) LoginClient(ctx context.Context, clientID, clientSecret, scope string) (TokenSet, error)
- func (e *Exchanger) LoginLocal(ctx context.Context, username, password, scope, clientID string, ...) (TokenSet, error)
- func (e *Exchanger) RedeemAuthorizationCode(ctx context.Context, code, clientID, redirectURI, codeVerifier string) (TokenSet, error)
- func (e *Exchanger) RedeemRefreshToken(ctx context.Context, tokenID, clientID string) (TokenSet, error)
- type InternalIdentityProvider
- type JWK
- type JWKSet
- type Lookup
- type OAuth2
- type OIDCProviderClaims
- type OpenIDConfiguration
- type RefreshTokenClaims
- type TokenResponse
- type TokenSet
Constants ¶
const (
TRUE = "true"
)
Variables ¶
This section is empty.
Functions ¶
func AuthClientLoader ¶
func AuthClientLoader(secrets kdexv1alpha1.ServiceAccountSecrets) (map[string]AuthClient, error)
func DiscoveryHandler ¶
func DiscoveryHandler(issuer string) http.HandlerFunc
DiscoveryHandler creates an HTTP handler that serves the OpenID discovery document.
func FormatADGUID ¶
FormatADGUID converts the raw binary objectGUID from AD into a standard UUID string. AD uses a little-endian format for the first three components.
func JWKSHandler ¶
func JWKSHandler(keyPairs *keys.KeyPairs) http.HandlerFunc
JWKSHandler creates an HTTP handler that serves the JWKS endpoint. This endpoint exposes the public key(s) used to verify JWT signatures.
func NewLDAPLookup ¶
func NewRoleProvider ¶
func NewSecretLookup ¶
func NewSecretLookup(secrets kdexv1alpha1.ServiceAccountSecrets) *secretLookup
func OIDCConfigLoader ¶
func OIDCConfigLoader(secrets kdexv1alpha1.ServiceAccountSecrets, devMode bool) (string, string, string, error)
func SetAuthContext ¶
func SetAuthContext(ctx context.Context, ac AuthContext) context.Context
SetAuthContext sets the auth context in the context.
func WithAuthentication ¶
func WithAuthentication(publicKey crypto.PublicKey, cookieName string) func(http.Handler) http.Handler
WithAuthentication creates a middleware that validates JWT tokens from the Authorization header. It injects the claims into the request context if the token is valid. If the Header is present but invalid, it returns 401 Unauthorized. If the Header is missing, it proceeds without claims (anonymous access).
Types ¶
type AuthClient ¶
type AuthContext ¶
func GetAuthContext ¶
func GetAuthContext(ctx context.Context) (AuthContext, bool)
GetAuthContext retrieves the claims from the context.
func (AuthContext) GetAudience ¶
func (ac AuthContext) GetAudience() (jwt.ClaimStrings, error)
GetAudience implements the Claims interface.
func (AuthContext) GetAuthMethod ¶
func (ac AuthContext) GetAuthMethod() (AuthMethod, error)
func (AuthContext) GetEntitlements ¶
func (ac AuthContext) GetEntitlements() ([]string, error)
func (AuthContext) GetExpirationTime ¶
func (ac AuthContext) GetExpirationTime() (*jwt.NumericDate, error)
GetExpirationTime implements the Claims interface.
func (AuthContext) GetIssuedAt ¶
func (ac AuthContext) GetIssuedAt() (*jwt.NumericDate, error)
GetIssuedAt implements the Claims interface.
func (AuthContext) GetIssuer ¶
func (ac AuthContext) GetIssuer() (string, error)
GetIssuer implements the Claims interface.
func (AuthContext) GetNotBefore ¶
func (ac AuthContext) GetNotBefore() (*jwt.NumericDate, error)
GetNotBefore implements the Claims interface.
func (AuthContext) GetRoles ¶
func (ac AuthContext) GetRoles() ([]string, error)
func (AuthContext) GetScopes ¶
func (ac AuthContext) GetScopes() ([]string, error)
func (AuthContext) GetSubject ¶
func (ac AuthContext) GetSubject() (string, error)
GetSubject implements the Claims interface.
type AuthMethod ¶
type AuthMethod string
const ( AuthMethodLocal AuthMethod = "local" AuthMethodOIDC AuthMethod = "oidc" AuthMethodOAuth2 AuthMethod = "oauth2" )
type AuthorizationChecker ¶
type AuthorizationChecker struct {
// contains filtered or unexported fields
}
AuthorizationChecker validates whether a user has the required permissions.
func NewAuthorizationChecker ¶
func NewAuthorizationChecker(anonymousEntitlements []string, log logr.Logger) *AuthorizationChecker
NewAuthorizationChecker creates a new authorization checker.
func (*AuthorizationChecker) CalculateRequirements ¶
func (ac *AuthorizationChecker) CalculateRequirements( resource string, resourceName string, kdexreqs []kdexv1alpha1.SecurityRequirement, ) ([]kdexv1alpha1.SecurityRequirement, error)
func (*AuthorizationChecker) CheckAccess ¶
func (ac *AuthorizationChecker) CheckAccess( ctx context.Context, resource string, resourceName string, kdexreqs []kdexv1alpha1.SecurityRequirement, ) (bool, error)
type AuthorizationCodeClaims ¶
type AuthorizationCodeClaims struct {
AuthMethod AuthMethod `json:"auth_method"`
ClientID string `json:"cid"`
CodeChallenge string `json:"challenge,omitempty"`
CodeChallengeMethod string `json:"challenge_method,omitempty"`
Exp int64 `json:"exp"`
RedirectURI string `json:"uri"`
Scope string `json:"scp"`
Subject string `json:"sub"`
}
type CompiledMappingRule ¶
type CompiledMappingRule struct {
dmapper.MappingRule
Program cel.Program
}
type Config ¶
type Config struct {
ActivePair *keys.KeyPair
AnonymousEntitlements []string
Clients map[string]AuthClient
CookieName string
KeyPairs *keys.KeyPairs
OIDC struct {
BlockKey string
ClientID string
ClientSecret string
IDTokenStore idtoken.IDTokenStore
ProviderURL string
RedirectURL string
Scopes []string
}
Signer sign.Signer
TokenTTL time.Duration
}
func (*Config) AddAuthentication ¶
func (*Config) IsAuthEnabled ¶
func (*Config) IsM2MEnabled ¶
func (*Config) IsOIDCEnabled ¶
type ContextKey ¶
type ContextKey string
ContextKey is a custom type for context keys to avoid collisions.
type Exchanger ¶
type Exchanger struct {
// contains filtered or unexported fields
}
func NewExchanger ¶
func NewExchanger( ctx context.Context, cfg Config, cacheManager cache.CacheManager, sp InternalIdentityProvider, ) (*Exchanger, error)
func (*Exchanger) AuthCodeURL ¶
func (*Exchanger) CreateAuthorizationCode ¶
func (*Exchanger) EndSessionURL ¶
func (*Exchanger) ExchangeCode ¶
func (*Exchanger) ExchangeToken ¶
func (*Exchanger) GetOIDCClientID ¶
func (*Exchanger) GetScopesSupported ¶
func (*Exchanger) GetTokenTTL ¶
func (*Exchanger) IsRefreshTokenEnabled ¶
func (*Exchanger) LoginClient ¶
func (*Exchanger) LoginLocal ¶
type JWK ¶
type JWK struct {
Alg string `json:"alg"`
Kid string `json:"kid"`
Kty string `json:"kty"`
Use string `json:"use"`
// RSA fields
E string `json:"e,omitempty"`
N string `json:"n,omitempty"`
// ECDSA fields
Crv string `json:"crv,omitempty"`
X string `json:"x,omitempty"`
Y string `json:"y,omitempty"`
}
JWK represents a JSON Web Key.
type OAuth2 ¶
func (*OAuth2) AuthorizeHandler ¶
func (o *OAuth2) AuthorizeHandler(w http.ResponseWriter, r *http.Request)
func (*OAuth2) OAuth2TokenHandler ¶
func (o *OAuth2) OAuth2TokenHandler(w http.ResponseWriter, r *http.Request)
type OIDCProviderClaims ¶
type OpenIDConfiguration ¶
type OpenIDConfiguration struct {
AuthorizationEndpoint string `json:"authorization_endpoint,omitempty"`
ClaimsSupported []string `json:"claims_supported,omitempty"`
GrantTypesSupported []string `json:"grant_types_supported,omitempty"`
IDTokenSigningAlgValuesSupported []string `json:"id_token_signing_alg_values_supported"`
Issuer string `json:"issuer"`
JwksURI string `json:"jwks_uri"`
ResponseTypesSupported []string `json:"response_types_supported"`
ScopesSupported []string `json:"scopes_supported,omitempty"`
SubjectTypesSupported []string `json:"subject_types_supported"`
TokenEndpoint string `json:"token_endpoint,omitempty"`
}
OpenIDConfiguration represents the OIDC discovery document.
type RefreshTokenClaims ¶
type RefreshTokenClaims struct {
AuthMethod AuthMethod `json:"auth_method"`
ClientID string `json:"cid"`
ExpiresAt int64 `json:"exp"`
IssuedAt int64 `json:"iat"`
Scope string `json:"scp"`
Subject string `json:"sub"`
}
RefreshTokenClaims holds the data stored inside a refresh token entry in the cache.
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
IDToken string `json:"id_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
Scope string `json:"scope,omitempty"`
TokenType string `json:"token_type"`
}
TokenResponse represents the OAuth2 token response.