certs

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package certs picks the TLS certificate of a host.

The selection is deliberately deterministic and explainable: every result carries the class it was matched by and the pattern that matched, so the log line says *why* a host ended up with a certificate.

Index

Constants

This section is empty.

Variables

View Source
var AutoSpec = Spec{Mode: ModeAuto, Raw: "auto"}

AutoSpec is the default: pick the best matching certificate.

Functions

func Hash

func Hash(list []npm.Certificate) string

Hash summarises a certificate list so a change (a new certificate, a renewal, a deletion) can trigger a reconcile run.

Types

type Class

type Class int

Class ranks how well a certificate fits a set of domains. Lower is better.

const (
	// ClassExactOnly means the certificate covers exactly these domains.
	ClassExactOnly Class = iota + 1
	// ClassExactExtra means every domain matches exactly, plus further SANs.
	ClassExactExtra
	// ClassMixed means every domain is covered, some exactly, some by a
	// wildcard.
	ClassMixed
	// ClassWildcard means every domain is covered by a wildcard.
	ClassWildcard
	// ClassNone means the certificate does not cover the domains.
	ClassNone
)

The match classes, best first.

func (Class) String

func (c Class) String() string

String implements fmt.Stringer and is what the log line shows.

type Mode

type Mode int

Mode is what a `certificate` label asks for.

const (
	// ModeAuto picks the best matching certificate (the default).
	ModeAuto Mode = iota
	// ModeID pins a certificate id.
	ModeID
	// ModeDomain names a domain the certificate must cover.
	ModeDomain
	// ModeName names a certificate by its nice_name ("name:My wildcard").
	ModeName
	// ModeNew requests a fresh Let's Encrypt certificate.
	ModeNew
	// ModeNone deliberately attaches no certificate.
	ModeNone
)

The accepted certificate modes.

func (Mode) String

func (m Mode) String() string

String implements fmt.Stringer.

type Options

type Options struct {
	// Current is the certificate id the live resource already carries.
	Current int
	// Partial is the policy when no certificate covers every domain.
	Partial Partial
	// Now is the reference time for expiry checks (zero means time.Now).
	Now time.Time
}

Options tune the automatic selection.

type Partial

type Partial string

Partial is the policy for domains no single certificate covers.

const (
	// PartialPrimary uses a certificate for the first domain and warns about
	// the rest (the default).
	PartialPrimary Partial = "primary"
	// PartialNone attaches no certificate at all.
	PartialNone Partial = "none"
)

The partial-coverage policies.

func ParsePartial

func ParsePartial(raw string) (Partial, error)

ParsePartial resolves NPM_CERTIFICATE_PARTIAL.

type Selection

type Selection struct {
	// ID is the certificate to attach, 0 for none.
	ID int
	// New requests a fresh Let's Encrypt certificate.
	New bool
	// Class is how the certificate matched.
	Class Class
	// Pattern is the certificate domain that matched the first host domain.
	Pattern string
	// Uncovered lists host domains the certificate does not cover.
	Uncovered []string
	// Kept reports that an already attached certificate was retained.
	Kept bool
}

Selection is the outcome of a certificate lookup.

func Resolve

func Resolve(spec Spec, domains []string, list []npm.Certificate, opts Options) (Selection, error)

Resolve turns a spec into a concrete certificate id.

For ModeAuto the candidates are ranked by class, then by remaining validity, then by id; an already attached certificate that is still valid and still covers the domains is kept unless a candidate matches in a strictly better class, so a newly imported wildcard cannot shuffle existing hosts around.

type Spec

type Spec struct {
	Mode   Mode
	ID     int
	Domain string
	Name   string
	Raw    string
}

Spec is a parsed `certificate` label value.

func ParseSpec

func ParseSpec(raw string) (Spec, error)

ParseSpec reads a `certificate` label or NPM_DEFAULT_CERTIFICATE value.

func (Spec) String

func (s Spec) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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