webtls

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package webtls resolves and runs Ken's TLS posture. Three modes, chosen by KEN_TLS:

  • off — plain HTTP. Valid ONLY behind a reverse proxy that terminates TLS.
  • acme — in-process Let's Encrypt via autocert: automatic issuance AND renewal, certs cached on disk. Needs KEN_TLS_DOMAINS (+ KEN_TLS_EMAIL).
  • file — an operator-supplied PEM cert/key (KEN_TLS_CERT/KEN_TLS_KEY), hot-reloaded when the files change on disk (so a renewal needs no restart).

In the two TLS modes it also runs a plain-HTTP listener (default :80) that serves ACME HTTP-01 challenges and 301-redirects everything else to HTTPS, so a user who types http:// still lands on the encrypted site.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Mode     Mode
	Addr     string   // main app listener: plain HTTP in off mode, HTTPS otherwise
	HTTPAddr string   // plain-HTTP redirect + ACME HTTP-01 listener (TLS modes; "" disables)
	Domains  []string // cert host allowlist (acme mode; also gates the HTTPS redirect)
	Email    string   // ACME account email (acme mode; recommended, optional)
	CacheDir string   // ACME certificate cache directory (acme mode)
	CertFile string   // PEM certificate (file mode)
	KeyFile  string   // PEM private key (file mode)

	QuietHandshake bool // suppress benign "TLS handshake error" scanner noise in the log
}

Config is the resolved TLS configuration.

func FromEnv

func FromEnv(addr, dataDir string) (Config, error)

FromEnv resolves the TLS configuration from KEN_TLS* environment variables. addr is the main listen address already resolved from --addr / KEN_ADDR (empty accepts the mode default: :8080 plain, :443 with TLS). dataDir seeds the default ACME cache directory (<dataDir>/acme). It fails fast on an invalid combination.

func (Config) Build

func (c Config) Build(appHandler http.Handler, tune func(*http.Server), acmeDomains func() []string) (*Servers, error)

Build constructs the server(s) for c. appHandler is the application mux; tune (if non-nil) is applied to the main server (timeouts, etc.). Build performs the fail-fast checks: it loads the cert/key in file mode and creates the ACME cache directory in acme mode, so a misconfiguration is caught at startup. acmeDomains, when non-nil, supplies the live ACME host allowlist (from settings) so domains can change without a restart; nil uses the static c.Domains.

func (Config) Describe

func (c Config) Describe() string

Describe returns a one-line human summary of the TLS posture for the startup log.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether Ken terminates TLS itself (acme or file mode).

type Mode

type Mode string

Mode is the TLS termination strategy.

const (
	ModeOff  Mode = "off"
	ModeACME Mode = "acme"
	ModeFile Mode = "file"
)

type Servers

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

Servers holds the running listeners so the caller keeps control of shutdown.

func (*Servers) Shutdown

func (s *Servers) Shutdown(ctx context.Context)

Shutdown gracefully stops every listener.

func (*Servers) Start

func (s *Servers) Start(errc chan<- error)

Start begins serving on every listener. A failure of the MAIN listener (other than a clean shutdown) is sent to errc. A failure of the optional :80 redirect/challenge listener is only logged — it must never tear down an otherwise-healthy HTTPS service.

Jump to

Keyboard shortcuts

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