Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateJTI(aud, sub, act string) string
- func GenerateKID(pubBytes []byte) string
- type KeyPair
- type KeyPairs
- type TokenData
- type TokenManager
- func (tm *TokenManager) CapTTL(ttl time.Duration) time.Duration
- func (tm *TokenManager) KeyPairs() KeyPairs
- func (tm *TokenManager) MaxTTL() time.Duration
- func (tm *TokenManager) MintStatelessKey(aud string, sub string, action string, scope string, ttl time.Duration) (string, error)
- func (tm *TokenManager) RevocationTTL() time.Duration
- func (tm *TokenManager) RevokeByMetadata(ctx context.Context, aud, sub, act string, ttl time.Duration) error
- func (tm *TokenManager) RevokeToken(ctx context.Context, signed string) error
- func (tm *TokenManager) TokenPrefix() string
- func (tm *TokenManager) ValidateToken(ctx context.Context, signed, expectedAudience string) (*TokenData, error)
- func (tm *TokenManager) WithMaxTTL(maxTTL time.Duration) *TokenManager
- func (tm *TokenManager) WithTokenPrefix(prefix string) *TokenManager
Constants ¶
const RevocationHorizon = 10 * 365 * 24 * time.Hour
RevocationHorizon is how long a revocation lasts on a host with no maximum API token lifetime. A revocation must outlive every token it revokes, and it only revokes tokens issued up to its own timestamp, so a long one blocks no key minted afterwards under the same name.
Variables ¶
var ErrTTLExceedsMax = errors.New("ttl exceeds the host's maximum API token lifetime")
ErrTTLExceedsMax is returned when a mint asks for a lifetime longer than the host's KDexHost.spec.auth.apiToken.maxTTL. See kdex-tech/host-manager#238.
Functions ¶
func GenerateJTI ¶ added in v0.2.30
func GenerateKID ¶
Types ¶
type KeyPair ¶
type KeyPair struct {
ActiveKey bool
KeyId string
PublicKey *paseto.V4AsymmetricPublicKey
SecretKey *paseto.V4AsymmetricSecretKey
}
type KeyPairs ¶
type KeyPairs []*KeyPair
func GenerateDevmodeKeyPair ¶
func GenerateDevmodeKeyPair() *KeyPairs
type TokenManager ¶
type TokenManager struct {
// contains filtered or unexported fields
}
func APITokenManagerLoader ¶
func APITokenManagerLoader( issuer string, secrets kdexv1alpha1.Secrets, revocationCache cache.Cache, devMode bool, ) (*TokenManager, error)
func NewTokenManager ¶
func (*TokenManager) CapTTL ¶ added in v0.25.0
func (tm *TokenManager) CapTTL(ttl time.Duration) time.Duration
CapTTL shortens ttl to the host's maximum. It is for lifetimes the server chooses itself; a lifetime a caller asked for is refused, not shortened, so the caller is never handed a token that expires sooner than it requested.
func (*TokenManager) KeyPairs ¶
func (tm *TokenManager) KeyPairs() KeyPairs
func (*TokenManager) MaxTTL ¶ added in v0.25.0
func (tm *TokenManager) MaxTTL() time.Duration
MaxTTL returns the host's maximum API token lifetime, zero when unbounded.
func (*TokenManager) MintStatelessKey ¶
func (*TokenManager) RevocationTTL ¶ added in v0.26.0
func (tm *TokenManager) RevocationTTL() time.Duration
RevocationTTL is the shortest lifetime of a revocation: never shorter than the longest token this host can mint, so a revoked token cannot come back.
func (*TokenManager) RevokeByMetadata ¶ added in v0.2.30
func (*TokenManager) RevokeToken ¶ added in v0.2.30
func (tm *TokenManager) RevokeToken(ctx context.Context, signed string) error
func (*TokenManager) TokenPrefix ¶ added in v0.3.0
func (tm *TokenManager) TokenPrefix() string
TokenPrefix returns this host's white-label API token prefix (empty when prefixing is off). Callers that need to discriminate a brand-prefixed PAT on the wire (e.g. the Bearer auth path) use this to recognize the prefix without reaching into the manager's internals.
func (*TokenManager) ValidateToken ¶
func (tm *TokenManager) ValidateToken(ctx context.Context, signed, expectedAudience string) (*TokenData, error)
ValidateToken parses and verifies a PASETO API token.
expectedAudience is REQUIRED in spirit but technically optional in signature:
- non-empty: a paseto.ForAudience rule is added so a token minted for a different audience is rejected. This is the correct mode for any handler that uses ValidateToken's success as proof the bearer should be granted access on the receiving party.
- empty: the audience check is skipped. This is ONLY appropriate when the token is being INSPECTED (e.g. to extract its subject for a revocation flow) — not when validating for use. Passing "" in any other context is the kdex-tech/host-manager#69 confused-deputy regression.
func (*TokenManager) WithMaxTTL ¶ added in v0.25.0
func (tm *TokenManager) WithMaxTTL(maxTTL time.Duration) *TokenManager
WithMaxTTL sets the longest lifetime this host mints an API token for; zero (the default) leaves mint lifetimes unbounded. The controller sources it from KDexHost.spec.auth.apiToken.maxTTL. Returns the receiver for chaining.
func (*TokenManager) WithTokenPrefix ¶ added in v0.2.94
func (tm *TokenManager) WithTokenPrefix(prefix string) *TokenManager
WithTokenPrefix sets this host's white-label API token prefix. Prefixing is off by default (empty), in which case tokens are emitted as bare "v4.public." PASETO strings. When set, the prefix REPLACES the PASETO header on the wire (see wrap/unwrap). Returns the receiver for chaining. This is the single configuration point for the prefix; the controller sources it from KDexHost.spec.auth.apiToken.tokenPrefix (falling back to the NexusConfiguration default) and calls this once per host.