Documentation
¶
Overview ¶
Package tok provides AuthN token (structure and methods) for validation by AIS gateways
- Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
Package tok provides AuthN token (structure and methods) for validation by AIS gateways
- Copyright (c) 2018-2026, NVIDIA CORPORATION. All rights reserved.
Index ¶
- Variables
- func CreateHMACTokenStr(c jwt.Claims, secret cmn.Censored) (string, error)
- func CreateRSATokenStr(c jwt.Claims, rsaKey *rsa.PrivateKey) (string, error)
- type AISClaims
- func (c *AISClaims) CheckPermissions(clusterID string, bck *cmn.Bck, perms apc.AccessAttrs) error
- func (c *AISClaims) GetExpirationTime() (*jwt.NumericDate, error)
- func (c *AISClaims) GetSubject() (string, error)
- func (c *AISClaims) IsExpired() bool
- func (c *AISClaims) IsUser(user string) bool
- func (c *AISClaims) String() string
- func (c *AISClaims) Validate() error
- type CacheConfig
- type DiscoveryConf
- type JWKSRoundTripper
- type KeyCacheManager
- type Parser
- type SigConfig
- type TokenHdr
- type TokenParser
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoPermissions = errors.New("insufficient permissions") ErrInvalidToken = errors.New("invalid token") ErrNoSubject = errors.New("missing 'sub' or 'username' claims") ErrNoToken = errors.New("token required") ErrTokenExpired = errors.New("token expired") ErrTokenRevoked = errors.New("token revoked") )
var ErrNoJWKSForIssuer = errors.New("no JWKS entry exists for issuer")
Functions ¶
func CreateHMACTokenStr ¶ added in v1.4.1
func CreateRSATokenStr ¶ added in v1.4.1
Types ¶
type AISClaims ¶ added in v1.4.1
type AISClaims struct {
// Deprecated: Use RegisteredClaims.Subject instead, mapped to 'sub' claim.
UserID string `json:"username"`
// Deprecated: Use RegisteredClaims.ExpiresAt instead, mapped to 'exp' claim.
Expires time.Time `json:"expires"`
ClusterACLs []*authn.CluACL `json:"clusters"`
BucketACLs []*authn.BckACL `json:"buckets,omitempty"`
IsAdmin bool `json:"admin"`
jwt.RegisteredClaims
}
func AdminClaims ¶ added in v1.4.1
func StandardClaims ¶ added in v1.4.1
func (*AISClaims) CheckPermissions ¶ added in v1.4.1
func (*AISClaims) GetExpirationTime ¶ added in v1.4.1
func (c *AISClaims) GetExpirationTime() (*jwt.NumericDate, error)
GetExpirationTime implements Claims interface with backwards-compatible support for 'expires'
func (*AISClaims) GetSubject ¶ added in v1.4.1
GetSubject implements Claims interface with backwards-compatible support for 'username'
type CacheConfig ¶ added in v1.4.1
type CacheConfig struct {
DiscoveryConf *DiscoveryConf
MinCacheRefreshInterval *time.Duration
}
type DiscoveryConf ¶ added in v1.4.1
type JWKSRoundTripper ¶ added in v1.4.2
type JWKSRoundTripper struct {
// contains filtered or unexported fields
}
JWKSRoundTripper wraps http.RoundTripper to track latency of JWKS fetches
func NewJWKSRoundTripper ¶ added in v1.4.2
func NewJWKSRoundTripper(base http.RoundTripper, statsT stats.Tracker) *JWKSRoundTripper
type KeyCacheManager ¶ added in v1.4.1
type KeyCacheManager struct {
// contains filtered or unexported fields
}
func NewKeyCacheManager ¶ added in v1.4.1
func NewKeyCacheManager(oidc *cmn.OIDCConf, client *http.Client, cacheConf *CacheConfig, statsT stats.Tracker) *KeyCacheManager
NewKeyCacheManager creates an instance of KeyCacheManager with an unpopulated cache After creating, call Init with a long-lived context to create a key cache Optionally, also pre-populate the cache to register and preload the allowed issuers
func (*KeyCacheManager) IncCounter ¶ added in v1.4.2
func (km *KeyCacheManager) IncCounter(metric string)
func (*KeyCacheManager) Init ¶ added in v1.4.1
func (km *KeyCacheManager) Init(rootCtx context.Context)
Init prepares a key cache manager to provide to a token parser The provided context must be valid for the life of the cache for automatic refresh
func (*KeyCacheManager) PopulateJWKSCache ¶ added in v1.4.1
func (km *KeyCacheManager) PopulateJWKSCache(ctx context.Context) error
PopulateJWKSCache looks up JWKS URLs, adds them to the cache, and preloads JWKS Returns error only on context cancellation or invalid config
type Parser ¶ added in v1.4.1
type Parser interface {
// ValidateToken verifies JWT signature and extracts token claims.
ValidateToken(ctx context.Context, tokenStr string) (*AISClaims, error)
// IsSecretCksumValid checks if a provided secret checksum is valid.
IsSecretCksumValid(cksumVal string) bool
// IsPublicKeyValid checks if a provided public key matches the parser's key.
IsPublicKeyValid(pubKeyStr string) (bool, error)
}
type TokenHdr ¶ added in v1.4.1
type TokenHdr struct {
// Request header containing token string
Header string
// Raw token string from request
Token string
}
func ExtractToken ¶
ExtractToken extracts JWT token from either Authorization header (Bearer token) or X-Amz-Security-Token header with the following priority:
- Authorization: Bearer <token> (standard JWT auth)
- X-Amz-Security-Token: enables native AWS SDK clients to authenticate using AIS-compatible JWT tokens passed when using SigV4 authentication.
type TokenParser ¶ added in v1.4.1
type TokenParser struct {
// contains filtered or unexported fields
}
func NewTokenParser ¶ added in v1.4.1
func NewTokenParser(conf *cmn.AuthConf, cacheManager *KeyCacheManager) *TokenParser
NewTokenParser creates a new instance of TokenParser. If using allowed issuers and public key lookups, call InitKeyCache after creation
func (*TokenParser) IsPublicKeyValid ¶ added in v1.4.1
func (tm *TokenParser) IsPublicKeyValid(pubKeyStr string) (bool, error)
IsPublicKeyValid Checks if a provided public key matches what this cluster will use to validate tokens
func (*TokenParser) IsSecretCksumValid ¶ added in v1.4.1
func (tm *TokenParser) IsSecretCksumValid(cksumVal string) bool
IsSecretCksumValid Checks if a provided secret checksum is valid for signing requests to be parsed by this cluster
func (*TokenParser) ValidateToken ¶ added in v1.4.1
ValidateToken verifies JWT signature and extracts token claims (supporting both HMAC (HS256) and RSA (RS256) signing methods) - HS256: validates with secret (symmetric) - RS256: validates with pubKey (asymmetric)