mtls

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mtls provides mutual TLS helpers for backend HTTPS servers and gateway outbound clients.

Role in architecture:

  • Infrastructure: builds tls.Config, configures http.Server / Gin listeners, and outbound transports.
  • Configuration is loaded via config.GetConfig().MTLS (or config.Setup).

Responsibilities:

  • ServerTLSConfig / ClientTLSConfig / CloneTLSConfig for certificate material.
  • ConfigureServer, ListenAndServe, RunGin (and *Config / *WithConfig variants) when MTLS_ENABLED.
  • NewTransport for outbound HTTP with client certificate authentication.

Constraints:

  • When MTLS_ENABLED is false, listen helpers use plain HTTP / no client cert attachment.
  • Pair server TLS with middlewares.MTLSMiddleware so application checks match client auth.
  • Skip paths for the middleware come from MTLS_SKIP_PATHS (e.g. /live, /ready, /metrics).

This package must NOT:

  • Contain use-case or domain logic.
  • Implement HTTP auth beyond TLS client certificate verification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientTLSConfig

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

ClientTLSConfig returns TLS settings for the api-gateway outbound proxy.

func CloneTLSConfig

func CloneTLSConfig(cfg *tls.Config) *tls.Config

CloneTLSConfig returns a shallow copy safe for per-connection use.

func ConfigureServer

func ConfigureServer(srv *http.Server) error

ConfigureServer applies mTLS to an existing http.Server when enabled in config.

func ConfigureServerWithConfig

func ConfigureServerWithConfig(srv *http.Server, cfg Config) error

ConfigureServerWithConfig applies mTLS to srv when cfg.Enabled is true.

func ListenAndServe

func ListenAndServe(handler http.Handler, addr string) error

ListenAndServe starts plain HTTP or mTLS HTTPS depending on cfg.Enabled.

func ListenAndServeConfig

func ListenAndServeConfig(handler http.Handler, addr string, cfg Config) error

ListenAndServeConfig starts plain HTTP or mTLS HTTPS using the given configuration.

func ListenConfigured

func ListenConfigured(srv *http.Server) error

ListenConfigured serves using srv.TLSConfig when mTLS is enabled.

func ListenConfiguredWithConfig

func ListenConfiguredWithConfig(srv *http.Server, cfg Config) error

ListenConfiguredWithConfig serves with TLS when cfg.Enabled is true.

func NewTransport

func NewTransport(cfg Config) (*http.Transport, error)

NewTransport builds an http.Transport for gateway upstream connections.

func RunGin

func RunGin(engine *gin.Engine, addr string) error

RunGin is a drop-in for gin.Engine.Run with optional mTLS.

func RunGinConfig

func RunGinConfig(engine *gin.Engine, addr string, cfg Config) error

RunGinConfig is RunGin with an explicit configuration.

func ServerTLSConfig

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

ServerTLSConfig returns TLS settings for backend services (require gateway client cert).

Types

type Config

type Config = config.MTLSConfiguration

Config is the mTLS configuration loaded from the central config package.

func LoadConfig

func LoadConfig() Config

LoadConfig returns mTLS settings from the global config package.

Jump to

Keyboard shortcuts

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