mtls

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package mtls serves the app over TLS and only accepts requests from proxies that present a client certificate issued by the internal CA.

Certificates are short-lived and re-rendered by Nomad, so they are re-read on SIGHUP rather than only at start-up.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// CertFile holds the server certificate (and any intermediates).
	CertFile string
	// KeyFile holds the server's private key; empty means it is in CertFile.
	KeyFile string
	// ClientCAFile holds the CA certificates client certificates must chain to.
	ClientCAFile string
	// AllowedClients are the DNS names a client certificate must carry one of.
	AllowedClients []string
}

Config says where the certificates live and which clients may connect.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether mTLS has been configured at all.

type Server

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

Server holds the current certificates and checks incoming requests.

func New

func New(conf Config) (*Server, error)

New loads the certificates in conf.

func (*Server) Middleware

func (s *Server) Middleware(skipPaths ...string) echo.MiddlewareFunc

Middleware rejects requests that did not present a verified client certificate for one of the allowed names. Requests for skipPaths (the health check) are let through so the orchestrator can probe without a certificate.

func (*Server) Reload

func (s *Server) Reload() error

Reload re-reads the certificates from disk. On error the previous ones stay in use.

func (*Server) ReloadOnSIGHUP

func (s *Server) ReloadOnSIGHUP() (stop func())

ReloadOnSIGHUP reloads the certificates whenever the process gets SIGHUP, which is what Nomad sends when it re-renders them. Call stop to stop listening.

func (*Server) TLSConfig

func (s *Server) TLSConfig() *tls.Config

TLSConfig returns a config that always uses the most recently loaded certificates.

Client certificates are verified when given but not required at the handshake, so the health check can connect without one; Middleware enforces them for everything else.

Directories

Path Synopsis
Package mtlstest makes throwaway CAs and certificates for mTLS tests.
Package mtlstest makes throwaway CAs and certificates for mTLS tests.

Jump to

Keyboard shortcuts

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