Documentation
¶
Index ¶
- func CallerCommonName(ctx context.Context) string
- func ClientTLSConfig(cfg TLSConfig) (*tls.Config, error)
- func ClientTLSOnlyConfig(cfg TLSConfig) (*tls.Config, error)
- func ContextWithClaims(ctx context.Context, claims *BridgeClaims) context.Context
- func ServerTLSConfig(cfg TLSConfig) (*tls.Config, error)
- func ServerTLSOnlyConfig(cfg TLSConfig) (*tls.Config, error)
- func StreamAuditInterceptor(logger *slog.Logger) grpc.StreamServerInterceptor
- func StreamJWTInterceptor(v *JWTVerifier, logger *slog.Logger) grpc.StreamServerInterceptor
- func StreamPassthroughInterceptor() grpc.StreamServerInterceptor
- func UnaryAuditInterceptor(logger *slog.Logger) grpc.UnaryServerInterceptor
- func UnaryJWTInterceptor(v *JWTVerifier, logger *slog.Logger) grpc.UnaryServerInterceptor
- func UnaryPassthroughInterceptor() grpc.UnaryServerInterceptor
- type BridgeClaims
- type CertReloader
- type JWTIssuer
- type JWTVerifier
- type TLSConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallerCommonName ¶
CallerCommonName extracts the Common Name from the mTLS peer certificate in the gRPC context. Returns empty string if not available.
func ClientTLSConfig ¶
ClientTLSConfig returns a TLS config that verifies server certs and presents a client cert (mTLS). Minimum TLS 1.3.
func ClientTLSOnlyConfig ¶
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 ¶
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 ¶
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 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.