authkit

package
v11.3.24 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package authkit provides scoped inbound bearer-token validation for services that need Windmill-callable HTTP or gRPC endpoints.

Index

Constants

View Source
const (
	DefaultEnvVar = "CHASSIS_AUTHKIT_KEYS"
)

Variables

This section is empty.

Functions

func ContextWithPrincipal

func ContextWithPrincipal(ctx context.Context, p *Principal) context.Context

ContextWithPrincipal returns a child context containing p.

func HTTPMiddleware

func HTTPMiddleware(verifier *StaticVerifier, requiredScopes ...string) func(http.Handler) http.Handler

HTTPMiddleware authenticates HTTP requests before invoking next.

func StreamServerInterceptor

func StreamServerInterceptor(verifier *StaticVerifier, requiredScopes ...string) grpc.StreamServerInterceptor

StreamServerInterceptor authenticates gRPC streaming calls.

func UnaryServerInterceptor

func UnaryServerInterceptor(verifier *StaticVerifier, requiredScopes ...string) grpc.UnaryServerInterceptor

UnaryServerInterceptor authenticates gRPC unary calls.

Types

type Key

type Key struct {
	ID         string
	StoredHash string
	Scopes     []string
}

Key describes one static bearer credential and the scopes it grants.

func LoadStaticKeysFromEnv

func LoadStaticKeysFromEnv(envVar ...string) ([]Key, error)

LoadStaticKeysFromEnv parses CHASSIS_AUTHKIT_KEYS by default. The format is:

key-id=scrypt$N$r$p$salt_b64$derived_key_b64:scope1,scope2;other=...

func ParseStaticKeys

func ParseStaticKeys(value string) ([]Key, error)

ParseStaticKeys parses the static key environment format.

type Principal

type Principal struct {
	KeyID  string
	Scopes []string
}

Principal is attached to request contexts after successful authentication.

func PrincipalFromContext

func PrincipalFromContext(ctx context.Context) (*Principal, bool)

PrincipalFromContext returns the authenticated principal, if any.

type StaticVerifier

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

StaticVerifier verifies token strings in the form <key-id>.<secret> against stored scrypt hashes.

func MustStaticVerifier

func MustStaticVerifier(keys []Key) *StaticVerifier

MustStaticVerifier is like NewStaticVerifier but panics on invalid keys.

func NewStaticVerifier

func NewStaticVerifier(keys []Key) (*StaticVerifier, error)

NewStaticVerifier builds a verifier from static key records.

func (*StaticVerifier) VerifyBearer

func (v *StaticVerifier) VerifyBearer(ctx context.Context, authorization string, requiredScopes ...string) (*Principal, error)

VerifyBearer validates an Authorization header value and returns a principal.

Jump to

Keyboard shortcuts

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