auth

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallerCommonName

func CallerCommonName(ctx context.Context) string

CallerCommonName extracts the Common Name from the mTLS peer certificate in the gRPC context. Returns empty string if not available.

func ClientTLSConfig

func ClientTLSConfig(cfg TLSConfig) (*tls.Config, error)

ClientTLSConfig returns a TLS config that verifies server certs and presents a client cert (mTLS). Minimum TLS 1.3.

func ClientTLSOnlyConfig

func ClientTLSOnlyConfig(cfg TLSConfig) (*tls.Config, error)

ClientTLSOnlyConfig returns a TLS config that verifies the server's certificate but does NOT present a client certificate. This is used for clients connecting in "tls" mode where only JWT is used for auth. Minimum TLS 1.3.

func ContextWithClaims

func ContextWithClaims(ctx context.Context, claims *BridgeClaims) context.Context

ContextWithClaims stores claims in context.

func ServerTLSConfig

func ServerTLSConfig(cfg TLSConfig) (*tls.Config, error)

ServerTLSConfig returns a TLS config that REQUIRES and verifies client certs (mTLS). Minimum TLS 1.3. The server certificate is loaded via a CertReloader so that renewed certificates on disk are picked up on new TLS handshakes without restarting the server.

func ServerTLSOnlyConfig

func ServerTLSOnlyConfig(cfg TLSConfig) (*tls.Config, error)

ServerTLSOnlyConfig returns a TLS config that presents a server certificate but does NOT require or verify client certificates. This is used for the "tls" security mode where JWT provides authorization without mutual TLS. Minimum TLS 1.3. The server certificate is loaded via a CertReloader.

func StreamAuditInterceptor

func StreamAuditInterceptor(logger *slog.Logger) grpc.StreamServerInterceptor

StreamAuditInterceptor logs stream RPC outcomes with caller metadata.

func StreamJWTInterceptor

func StreamJWTInterceptor(v *JWTVerifier, logger *slog.Logger) grpc.StreamServerInterceptor

StreamJWTInterceptor returns a gRPC stream interceptor that verifies JWTs.

func StreamPassthroughInterceptor

func StreamPassthroughInterceptor() grpc.StreamServerInterceptor

StreamPassthroughInterceptor injects empty claims for dev mode when JWT auth is disabled.

func UnaryAuditInterceptor

func UnaryAuditInterceptor(logger *slog.Logger) grpc.UnaryServerInterceptor

UnaryAuditInterceptor logs RPC outcomes with caller and request scope metadata.

func UnaryJWTInterceptor

func UnaryJWTInterceptor(v *JWTVerifier, logger *slog.Logger) grpc.UnaryServerInterceptor

UnaryJWTInterceptor returns a gRPC unary interceptor that verifies JWTs.

func UnaryPassthroughInterceptor

func UnaryPassthroughInterceptor() grpc.UnaryServerInterceptor

UnaryPassthroughInterceptor injects empty claims for dev mode when JWT auth is disabled.

Types

type BridgeClaims

type BridgeClaims struct {
	ProjectID string `json:"project_id"`
	jwt.RegisteredClaims
}

BridgeClaims are the JWT claims required for bridge API access.

func ClaimsFromContext

func ClaimsFromContext(ctx context.Context) (*BridgeClaims, bool)

ClaimsFromContext extracts BridgeClaims from a gRPC context.

type CertReloader

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

CertReloader watches TLS certificate and key files on disk and reloads them when the files change. It is safe for concurrent use. The reload check is triggered on each TLS handshake via the GetCertificate callback, so renewed certificates are picked up without restarting the server.

func NewCertReloader

func NewCertReloader(certPath, keyPath string) (*CertReloader, error)

NewCertReloader creates a CertReloader that loads the certificate from the given paths. The initial certificate is loaded immediately.

func (*CertReloader) GetCertificate

func (r *CertReloader) GetCertificate(*tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificate implements the tls.Config.GetCertificate callback. On each call it checks whether the cert file has been modified on disk and reloads if necessary. If the reload fails, the previously cached certificate is returned.

func (*CertReloader) Reload

func (r *CertReloader) Reload() error

Reload forces an immediate reload of the certificate from disk. Returns an error if the cert files cannot be read or parsed; the previously cached certificate is preserved in that case.

type JWTIssuer

type JWTIssuer struct {
	Issuer   string
	Audience string
	Key      ed25519.PrivateKey
	TTL      time.Duration
}

JWTIssuer mints Ed25519-signed JWTs for bridge authentication.

func (*JWTIssuer) Mint

func (j *JWTIssuer) Mint(sub, projectID string) (string, error)

Mint creates a new JWT with the given subject and project ID.

type JWTVerifier

type JWTVerifier struct {
	Audience string
	MaxTTL   time.Duration
	// Keys maps issuer name to their Ed25519 public key.
	Keys map[string]ed25519.PublicKey
	// contains filtered or unexported fields
}

JWTVerifier verifies Ed25519-signed JWTs from multiple issuers. After initialization, use AddKey to register new issuers at runtime.

func (*JWTVerifier) AddKey

func (v *JWTVerifier) AddKey(issuer string, pubKey ed25519.PublicKey)

AddKey registers a new issuer's Ed25519 public key at runtime. If the issuer already exists, the key is replaced.

func (*JWTVerifier) HasKey

func (v *JWTVerifier) HasKey(issuer string) bool

HasKey returns true if the given issuer has a registered public key.

func (*JWTVerifier) Verify

func (v *JWTVerifier) Verify(tokenString string) (*BridgeClaims, error)

Verify parses and validates a JWT token string.

type TLSConfig

type TLSConfig struct {
	CABundlePath string // Trust bundle (own CA + cross-signed CAs)
	CertPath     string // Server or client certificate
	KeyPath      string // Server or client private key
	ServerName   string // For client-side server name verification
}

TLSConfig holds paths for mTLS configuration.

Jump to

Keyboard shortcuts

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