tts

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvaluateIssuanceRules

func EvaluateIssuanceRules(rules []IssuanceRule, ictx *IssuanceContext) error

EvaluateIssuanceRules evaluates all compiled issuance rules against the given context. Returns nil if all rules pass. Returns an error with the failing rule's message otherwise.

func ScopeContains

func ScopeContains(scopeString, target string) bool

ScopeContains checks if a space-delimited scope string contains a specific scope. This is a helper function available for use in application code; CEL rules use string operations directly.

Types

type Config

type Config struct {
	// TrustDomain is the trust domain identifier, used as the `aud` claim in TxTokens.
	TrustDomain string `yaml:"trustDomain"`
	// Issuer is the TTS issuer URI, used as the `iss` claim in TxTokens.
	Issuer string `yaml:"issuer"`
	// SubjectTokens is an ordered list of JWT authenticators for subject token validation.
	SubjectTokens []authn.AuthenticatorConfig `yaml:"subjectTokens"`
	// Defaults contains default token settings.
	Defaults TokenDefaults `yaml:"defaults"`
}

Config is the TTS server configuration, matching the TxTokenConfig CRD spec.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads and parses a TTS configuration file.

func (*Config) DefaultKeySize

func (c *Config) DefaultKeySize() int

DefaultKeySize returns the RSA key size, defaulting to 2048.

func (*Config) DefaultTokenLifetime

func (c *Config) DefaultTokenLifetime() time.Duration

DefaultTokenLifetime returns the parsed token lifetime, defaulting to 15s.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that the configuration is valid.

type ErrorResponse

type ErrorResponse struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description,omitempty"`
}

ErrorResponse is the OAuth 2.0 error response.

type Handler

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

Handler processes RFC 8693 token exchange requests and issues TxTokens.

func NewHandler

func NewHandler(router *authn.Router, keyManager *keys.Manager, issuer, trustDomain string, lifetime time.Duration) *Handler

NewHandler creates a new token exchange handler.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles the token exchange endpoint.

func (*Handler) SetIssuanceRules

func (h *Handler) SetIssuanceRules(rules []IssuanceRule)

SetIssuanceRules updates the compiled issuance rules evaluated before token issuance.

func (*Handler) SetVerifier

func (h *Handler) SetVerifier(v *verify.Verifier)

SetVerifier sets the TxToken verifier for token replacement support.

type IssuanceContext

type IssuanceContext struct {
	Subject    string
	Scope      string
	Tctx       map[string]any
	Rctx       map[string]any
	Workload   string
	WorkloadNS string
}

IssuanceContext contains the variables available to CEL issuance rules.

type IssuanceDeniedError

type IssuanceDeniedError struct {
	RuleName string
	Message  string
}

IssuanceDeniedError is returned when an issuance rule evaluates to false.

func (*IssuanceDeniedError) Error

func (e *IssuanceDeniedError) Error() string

type IssuanceRule

type IssuanceRule struct {
	Name string
	// contains filtered or unexported fields
}

IssuanceRule is a compiled CEL issuance rule evaluated before token issuance.

func CompileIssuanceRules

func CompileIssuanceRules(configs []IssuanceRuleConfig) ([]IssuanceRule, error)

CompileIssuanceRules compiles a list of issuance rule configs into executable programs.

type IssuanceRuleConfig

type IssuanceRuleConfig struct {
	Name    string `json:"name" yaml:"name"`
	CEL     string `json:"cel" yaml:"cel"`
	Message string `json:"message" yaml:"message"`
}

IssuanceRuleConfig is the configuration for an issuance rule (from TokenPolicy).

type Server

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

Server is the Transaction Token Service HTTP server.

func NewServer

func NewServer(cfg *Config) (*Server, error)

NewServer creates a new TTS server from configuration.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP handler for the TTS server.

func (*Server) KeyManager

func (s *Server) KeyManager() *keys.Manager

KeyManager returns the key manager (for testing).

type TokenDefaults

type TokenDefaults struct {
	// TokenLifetime is the default TxToken lifetime (e.g., "15s").
	TokenLifetime string `yaml:"tokenLifetime"`
	// KeySize is the RSA key size in bits (e.g., 2048).
	KeySize int `yaml:"keySize"`
}

TokenDefaults contains default token configuration.

type TokenExchangeRequest

type TokenExchangeRequest struct {
	GrantType          string
	SubjectToken       string
	SubjectTokenType   string
	RequestedTokenType string
	Audience           string
	Scope              string
	RequestDetails     map[string]any // becomes tctx
	RequestContext     map[string]any // becomes rctx
}

TokenExchangeRequest represents the parsed RFC 8693 token exchange parameters.

type TokenExchangeResponse

type TokenExchangeResponse struct {
	AccessToken     string `json:"access_token"`
	IssuedTokenType string `json:"issued_token_type"`
	TokenType       string `json:"token_type"`
}

TokenExchangeResponse is the RFC 8693 token exchange response.

Jump to

Keyboard shortcuts

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