certs

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package certs keeps a TLS certificate for every public hostname (§5.0.2). The controller is the ACME client (HTTP-01 through Traefik) and hands the certificates to Traefik in its dynamic config. Until a real certificate is issued, or when ACME fails, a self-signed placeholder keeps HTTPS working.

Index

Constants

View Source
const (
	AuthorityLetsEncrypt = "letsencrypt"
	AuthorityStaging     = "letsencrypt-staging"

	KindACME   = "acme"
	KindOrigin = "cloudflare-origin"

	// StagingDirectory is Let's Encrypt's test CA: its certificates are not trusted.
	StagingDirectory = "https://acme-staging-v02.api.letsencrypt.org/directory"
)
View Source
const (
	StatusValid       = "valid"        // issued by ACME
	StatusPending     = "pending"      // self-signed placeholder, ACME attempt due
	StatusFailed      = "failed"       // ACME failed, retrying with backoff
	StatusRateLimited = "rate_limited" // the CA rate-limited us (§5.0.2)
	StatusSelfSigned  = "self_signed"  // ACME disabled
	StatusAwaitingDNS = "awaiting_dns" // an order waits for TXT records
	StatusVerifying   = "verifying"    // the CA is checking the challenge
	StatusRevoked     = "revoked"

	IssuerACME       = "acme"
	IssuerSelfSigned = "self-signed"

	// TopicUpdated carries a View whenever a certificate changes.
	TopicUpdated = "certificate.updated"
	// ChallengePrefix is routed from Traefik's HTTP entrypoint to the controller.
	ChallengePrefix = "/.well-known/acme-challenge/"
)

Status values.

View Source
const (
	KeyECDSA   = "ecdsa-p256"
	KeyRSA2048 = "rsa-2048"
	KeyRSA3072 = "rsa-3072"
	KeyRSA4096 = "rsa-4096"
)

Key types.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
	ErrInvalid  = errors.New("invalid")
	ErrConflict = errors.New("conflict")
)

Errors the API maps.

View Source
var ErrUnknownHost = errors.New("no certificate is managed for this host")

ErrUnknownHost is returned by Renew for hosts that need no certificate.

KeyTypes lists what a certificate's key can be.

View Source
var Presets = []Preset{
	{"zerossl", "ZeroSSL", "https://acme.zerossl.com/v2/DV90", true, "In the ZeroSSL dashboard, open Developer and create EAB credentials: a key id and an HMAC key."},
	{"google", "Google Trust Services", "https://dv.acme-v02.api.pki.goog/directory", true, "Create an external account key with: gcloud publicca external-account-keys create"},
	{"sslcom", "SSL.com", "https://acme.ssl.com/sslcom-dv-ecc", true, "In your SSL.com account, create an ACME key: it gives a key id (HMAC key id) and an HMAC key."},
	{"buypass", "Buypass Go SSL", "https://api.buypass.com/acme/directory", false, "Needs no keys; certificates last 180 days."},
	{"custom", "Other ACME authority", "", false, "Any CA that speaks ACME: give its directory URL, and the key id and HMAC key if it asks for them."},
}

Presets are the providers the panel offers. Their directory addresses and how to get the keys are as the providers publish them; check the provider's own page if one stops working.

Functions

func NamesOfPEM added in v0.5.0

func NamesOfPEM(pemText string) []string

NamesOfPEM reads the names of the first certificate in a PEM, for a permission check before an import is accepted ("" input gives none).

func ValidKeyType added in v0.5.0

func ValidKeyType(t string) bool

ValidKeyType reports whether t is a known key type ("" means the default).

func ValidName added in v0.5.0

func ValidName(n string) error

ValidName checks a certificate name: a host, or *.host.

Types

type Attention added in v0.5.0

type Attention struct {
	Key      string
	Name     string
	DaysLeft float64
	Reason   string
	Alert    bool // a threshold the certificate's own alert days says to alert at
}

Attention describes a certificate that is about to expire or cannot renew.

type Authority added in v0.5.0

type Authority struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	Kind         string    `json:"kind"`
	Preset       string    `json:"preset,omitempty"`
	DirectoryURL string    `json:"directoryUrl,omitempty"`
	Email        string    `json:"email,omitempty"`
	EABKid       string    `json:"eabKid,omitempty"`
	HasEAB       bool      `json:"hasEab"`
	KeyType      string    `json:"keyType,omitempty"`
	ProviderID   string    `json:"providerId,omitempty"`
	Status       string    `json:"status"` // ok | new | error
	LastError    string    `json:"lastError,omitempty"`
	Builtin      bool      `json:"builtin"`
	Trusted      bool      `json:"trusted"` // browsers trust what it issues
	Default      bool      `json:"default"`
	Fallback     bool      `json:"fallback"`
	Certificates int       `json:"certificates"`
	CreatedAt    time.Time `json:"createdAt,omitempty"`
}

Authority is a certificate authority as shown (never its binding key).

type AuthorityInput added in v0.5.0

type AuthorityInput struct {
	Name         string
	Preset       string
	DirectoryURL string
	Email        string
	EABKid       string
	EABHMAC      string // base64 or base64url, as providers show it
	KeyType      string
	Kind         string
	ProviderID   string
}

AuthorityInput creates or changes an authority. Empty secrets keep the stored ones.

type Challenge added in v0.5.0

type Challenge struct {
	Name     string   `json:"name"`
	Value    string   `json:"value"`
	Names    []string `json:"names"`    // the certificate names it proves
	Wildcard bool     `json:"wildcard"` // proves a *. name
	Auto     bool     `json:"auto"`     // SynCloud writes and removes it (the domain has a provider)
	Present  bool     `json:"present"`  // public resolvers show it
	// Delegation: the challenge name is a CNAME to Target, where the TXT is written.
	Mode         string `json:"mode"`                   // direct | delegated | builtin | manual
	Target       string `json:"target,omitempty"`       // delegated: the CNAME's target
	CNAMEOK      bool   `json:"cnameOk,omitempty"`      // delegated: the CNAME is in place
	CNAMEManaged bool   `json:"cnameManaged,omitempty"` // delegated: SynCloud creates the CNAME
}

Challenge is a TXT record an order needs.

type ChallengeInfo added in v0.5.0

type ChallengeInfo struct {
	Mode         string // direct | delegated | manual
	Auto         bool   // SynCloud writes the TXT record
	Target       string // delegated: the name the CNAME points to
	CNAMEOK      bool   // delegated: public resolvers show the CNAME
	CNAMEManaged bool   // delegated: SynCloud can create the CNAME itself
}

ChallengeInfo is how a challenge name is answered (see dns.ChallengeRoute).

type Config

type Config struct {
	// ACME enables issuing from DirectoryURL; otherwise certificates stay self-signed.
	ACME         bool
	DirectoryURL string
	Email        string
	// HTTPClient talks to the ACME server (tests trust Pebble's CA here).
	HTTPClient  *http.Client
	RenewBefore time.Duration // default 30 days
}

type DNSHost added in v0.5.0

type DNSHost interface {
	// Challenge says where the TXT record of a challenge name goes: written
	// at the name (direct), written where a CNAME delegates it, or by hand.
	Challenge(ctx context.Context, name string) ChallengeInfo
	// EnsureDelegation creates the delegating CNAME when the domain has a provider.
	EnsureDelegation(ctx context.Context, name string) error
	PutTXT(ctx context.Context, name, value string) (id string, err error)
	DeleteTXT(ctx context.Context, name, id string) error
	// HasTXT returns the values that public resolvers do not all show yet.
	HasTXT(ctx context.Context, name string, values []string) (missing []string, err error)
	// ZoneOf names the registered domain a host belongs to, and its default authority.
	ZoneOf(ctx context.Context, host string) (zone, authorityID string, ok bool)
	// OriginCertificate asks a provider to sign an origin certificate.
	OriginCertificate(ctx context.Context, providerID, csrPEM string, names []string, days int) (string, error)
	// WildcardZones lists the domains that keep one wildcard certificate.
	WildcardZones(ctx context.Context) []ZonePolicy
}

DNSHost is what the certificates need from the domains: whether the platform can write a name's records, the challenge records, and a check that they are visible.

type ImportInput added in v0.5.0

type ImportInput struct {
	Chain      string // PEM, leaf first or in any order
	Key        string // PEM private key
	Passphrase string
	PKCS12     []byte
	Password   string
	Replace    string // the key of the certificate this replaces
	Actor      string
}

ImportInput brings a certificate in from a provider.

type ImportResult added in v0.5.0

type ImportResult struct {
	View     View     `json:"certificate"`
	Warnings []string `json:"warnings"`
}

ImportResult is the imported certificate and what to know about it.

type Manager

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

func New

func New(st *store.Store, box *secrets.Box, bus *events.Bus, log *slog.Logger, cfg Config) *Manager

func (*Manager) AddAuthority added in v0.5.0

func (m *Manager) AddAuthority(ctx context.Context, in AuthorityInput) (Authority, error)

AddAuthority registers an authority. Its account is created at the first use, or with TestAuthority.

func (*Manager) AddEvent added in v0.5.0

func (m *Manager) AddEvent(ctx context.Context, key, kind, detail, actor string)

AddEvent lets the API record what a person did.

func (*Manager) Attentions added in v0.5.0

func (m *Manager) Attentions() []Attention

Attentions lists managed certificates that need a person: expiring and not renewing by themselves, or failing. Thresholds are each certificate's own alert days.

func (*Manager) Authorities added in v0.5.0

func (m *Manager) Authorities(ctx context.Context) ([]Authority, error)

Authorities lists every authority, built-in ones first.

func (*Manager) Authority added in v0.5.0

func (m *Manager) Authority(ctx context.Context, id string) (Authority, error)

Authority returns one authority by id.

func (*Manager) Bundle added in v0.5.0

func (m *Manager) Bundle(ctx context.Context, key, actor string) (chain, privKey string, err error)

Bundle returns the chain and the private key of a certificate.

func (*Manager) Chain added in v0.5.0

func (m *Manager) Chain(key string) (string, error)

Chain returns the public chain of a certificate (no key).

func (*Manager) CompleteRequest added in v0.5.0

func (m *Manager) CompleteRequest(ctx context.Context, id, chainText, actor string) (ImportResult, error)

CompleteRequest takes the certificate the provider signed for a request.

func (*Manager) CountForZone added in v0.5.0

func (m *Manager) CountForZone(zone string) int

CountForZone counts the certificates that cover names in a domain.

func (*Manager) CreateRequest added in v0.5.0

func (m *Manager) CreateRequest(ctx context.Context, names []string, keyType string) (RequestView, error)

CreateRequest makes a key and a CSR for names: the CSR goes to the provider; the key never leaves.

func (*Manager) DefaultAuthorityID added in v0.5.0

func (m *Manager) DefaultAuthorityID(ctx context.Context) string

DefaultAuthorityID is the authority new certificates use.

func (*Manager) Delete added in v0.5.0

func (m *Manager) Delete(ctx context.Context, key string, force bool) error

Delete removes a certificate. A wildcard host that only this certificate covers keeps no valid certificate: refused unless force.

func (*Manager) DeleteAuthority added in v0.5.0

func (m *Manager) DeleteAuthority(ctx context.Context, id string) error

DeleteAuthority removes an authority nobody uses.

func (*Manager) DeleteRequest added in v0.5.0

func (m *Manager) DeleteRequest(ctx context.Context, id string) error

DeleteRequest discards a request (and its key).

func (*Manager) Events added in v0.5.0

func (m *Manager) Events(ctx context.Context, key string) ([]store.CertEvent, error)

Events returns a certificate's history, newest first.

func (*Manager) FallbackAuthorityID added in v0.5.0

func (m *Manager) FallbackAuthorityID(ctx context.Context) string

FallbackAuthorityID is the authority tried when the first one keeps failing ("" = none).

func (*Manager) Get added in v0.5.0

func (m *Manager) Get(ctx context.Context, key string) (View, bool)

Get returns one certificate by key (or by host for an automatic one).

func (*Manager) Import added in v0.5.0

func (m *Manager) Import(ctx context.Context, in ImportInput) (ImportResult, error)

Import stores a certificate (and its key) from a provider.

func (*Manager) Kick

func (m *Manager) Kick()

Kick asks the loop to reconcile now.

func (*Manager) List

func (m *Manager) List() []View

List returns the certificates for the current hosts and every certificate a person asked for.

func (*Manager) ListRequests added in v0.5.0

func (m *Manager) ListRequests(ctx context.Context) ([]RequestView, error)

ListRequests returns the requests waiting for a certificate.

func (*Manager) Load

func (m *Manager) Load(ctx context.Context) error

Load reads stored certificates. Call before serving Traefik config.

func (*Manager) PairFor added in v0.1.2

func (m *Manager) PairFor(host string) (Pair, bool)

PairFor returns the certificate and key that serve host, if there is one.

func (*Manager) Pairs

func (m *Manager) Pairs() []Pair

Pairs returns the certificates Traefik should serve: for every wanted host the one that serves it, and every other usable certificate a person asked for (an imported one for names no route lists yet).

func (*Manager) Pin

func (m *Manager) Pin(host string) string

Pin returns the public-key pin ("sha256//<base64>", as curl's --pinnedpubkey takes it) of host's certificate while it is self-signed, and "" once a CA issued it. Join commands carry the pin so new nodes can verify the controller on a private network where ACME cannot issue.

func (*Manager) PlanFor added in v0.5.0

func (m *Manager) PlanFor(host string) Plan

PlanFor describes the certificate a host has or will get.

func (*Manager) Reconcile

func (m *Manager) Reconcile(ctx context.Context)

Reconcile makes sure every host has a certificate and renews due ones.

func (*Manager) Reissue added in v0.5.0

func (m *Manager) Reissue(ctx context.Context, key string, names []string, actor string) (View, error)

Reissue changes the names and orders again; the old certificate serves until the new one is valid.

func (*Manager) Renew

func (m *Manager) Renew(ctx context.Context, host string) error

Renew clears any backoff for host and retries ACME now.

func (*Manager) RenewNow added in v0.5.0

func (m *Manager) RenewNow(ctx context.Context, key, actor string) error

RenewNow starts a new order now.

func (*Manager) Request added in v0.5.0

func (m *Manager) Request(ctx context.Context, in RequestInput) (View, error)

Request starts a certificate: a person asked for it. It is issued by the loop (or by Verify, once the TXT records are in place).

func (*Manager) Revoke added in v0.5.0

func (m *Manager) Revoke(ctx context.Context, key, actor string) (View, error)

Revoke tells the authority the certificate must not be trusted (ACME), or for an imported one stops serving it (you tell the provider).

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run reconciles on every Kick and every few minutes until ctx ends.

func (*Manager) SelfSignedBundle

func (m *Manager) SelfSignedBundle(hosts ...string) string

SelfSignedBundle concatenates the self-signed certificates of hosts (skipping CA-issued ones): what a client of the registry must trust, as Docker also fetches tokens from the dashboard host.

func (*Manager) SelfSignedPEM

func (m *Manager) SelfSignedPEM(host string) string

SelfSignedPEM returns host's certificate while it is self-signed, for clients that must be told to trust it (Docker on nodes, §5.9), else "".

func (*Manager) ServeHTTP

func (m *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP answers HTTP-01 challenges at /.well-known/acme-challenge/{token}.

func (*Manager) SetDNS added in v0.5.0

func (m *Manager) SetDNS(h DNSHost)

SetDNS connects the domains. Without it wildcard orders are manual.

func (*Manager) SetDefaultAuthority added in v0.5.0

func (m *Manager) SetDefaultAuthority(ctx context.Context, id string) error

SetDefaultAuthority chooses the authority new certificates use.

func (*Manager) SetFallbackAuthority added in v0.5.0

func (m *Manager) SetFallbackAuthority(ctx context.Context, id string) error

SetFallbackAuthority chooses the authority tried when the default keeps failing or is rate limited ("" turns it off).

func (*Manager) SetHosts

func (m *Manager) SetHosts(hosts []string)

SetHosts declares the hostnames that need certificates.

func (*Manager) TestAuthority added in v0.5.0

func (m *Manager) TestAuthority(ctx context.Context, id string) (Authority, error)

TestAuthority registers the account (or finds it) and records the result.

func (*Manager) Update added in v0.5.0

func (m *Manager) Update(ctx context.Context, key string, in UpdateInput, actor string) (View, error)

func (*Manager) UpdateAuthority added in v0.5.0

func (m *Manager) UpdateAuthority(ctx context.Context, id string, in AuthorityInput) (Authority, error)

UpdateAuthority changes a user-added authority.

func (*Manager) Verify added in v0.5.0

func (m *Manager) Verify(ctx context.Context, key, actor string) (View, error)

Verify checks the order's TXT records now and goes on if they are all there.

func (*Manager) ZoneOf added in v0.5.0

func (m *Manager) ZoneOf(key string) string

ZoneOf returns the registered domain of a certificate ("" if none).

type OrderView added in v0.5.0

type OrderView struct {
	State         string      `json:"state"` // awaiting_dns | verifying | issuing
	Manual        bool        `json:"manual"`
	Challenges    []Challenge `json:"challenges"`
	CreatedAt     time.Time   `json:"createdAt"`
	ExpiresAt     *time.Time  `json:"expiresAt,omitempty"`
	LastCheckedAt *time.Time  `json:"lastCheckedAt,omitempty"`
	LastError     string      `json:"lastError,omitempty"`
}

OrderView is an order in progress.

type Pair

type Pair struct{ CertPEM, KeyPEM string }

Pair is a PEM certificate chain and key, as Traefik takes them.

type Plan added in v0.5.0

type Plan struct {
	State         string     `json:"state"` // covered | issuing | automatic | needs_certificate
	CertificateID string     `json:"certificateId,omitempty"`
	Names         []string   `json:"names,omitempty"`
	ValidUntil    *time.Time `json:"validUntil,omitempty"`
	Note          string     `json:"note"`
}

Plan says how a host gets its certificate.

type Preset added in v0.5.0

type Preset struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	DirectoryURL string `json:"directoryUrl"`
	NeedsEAB     bool   `json:"needsEab"`
	Hint         string `json:"hint"`
}

Preset is a provider whose directory is known; the user adds only the keys.

type RequestInput added in v0.5.0

type RequestInput struct {
	Names     []string
	Authority string // "" = the domain's, else the cluster's
	Method    string // "" (decided from the names) | http-01 | dns-01
	KeyType   string
	Fallback  string
	AutoRenew *bool
	Days      int // origin certificates: validity in days
	Actor     string
	Key       string // internal: a fixed key (wildcard policy)
}

RequestInput asks for a certificate.

type RequestView added in v0.5.0

type RequestView struct {
	ID        string    `json:"id"`
	Names     []string  `json:"names"`
	KeyType   string    `json:"keyType"`
	CSR       string    `json:"csr"`
	CreatedAt time.Time `json:"createdAt"`
}

RequestView is a certificate request waiting for the provider's answer.

type UpdateInput added in v0.5.0

type UpdateInput struct {
	AutoRenew *bool
	Authority *string
	KeyType   *string
	Fallback  *string
	AlertDays *[]int
	Pinned    *[]string
}

UpdateInput changes a certificate's settings; nil fields stay.

type View

type View struct {
	Host          string     `json:"host"`
	Issuer        string     `json:"issuer"`
	Status        string     `json:"status"`
	NotAfter      time.Time  `json:"notAfter"`
	LastError     string     `json:"lastError"`
	Failures      int        `json:"failures"`
	NextAttemptAt *time.Time `json:"nextAttemptAt"`
	UpdatedAt     time.Time  `json:"updatedAt"`

	ID          string     `json:"id"`             // the key: the host of an automatic certificate, cert_… for one asked for
	Names       []string   `json:"names"`          // what it covers
	Wildcard    bool       `json:"wildcard"`       // covers a *. name
	Source      string     `json:"source"`         // acme | imported | origin-ca | self-signed
	Method      string     `json:"method"`         // http-01 | dns-01 | dns-01-manual | import | origin-ca | self-signed
	Managed     bool       `json:"managed"`        // asked for by a person (not made for a route)
	Zone        string     `json:"zone,omitempty"` // the registered domain it belongs to
	AuthorityID string     `json:"authorityId"`    // who issues it
	Authority   string     `json:"authority"`      // its name
	FallbackID  string     `json:"fallbackId,omitempty"`
	IssuerName  string     `json:"issuerName,omitempty"` // as the certificate says
	KeyType     string     `json:"keyType,omitempty"`
	AutoRenew   bool       `json:"autoRenew"`
	NotBefore   *time.Time `json:"notBefore,omitempty"`
	Serial      string     `json:"serial,omitempty"`
	Fingerprint string     `json:"fingerprint,omitempty"`
	RevokedAt   *time.Time `json:"revokedAt,omitempty"`
	AlertDays   []int      `json:"alertDays"`
	Pinned      []string   `json:"pinnedHosts"`
	CreatedAt   *time.Time `json:"createdAt,omitempty"`
	Trusted     bool       `json:"trusted"`         // browsers trust it
	UsedBy      []string   `json:"usedBy"`          // the hosts it serves
	Order       *OrderView `json:"order,omitempty"` // an order in progress
	DaysLeft    int        `json:"daysLeft"`
}

View is a certificate as shown in the API (never the key). The first fields are as they always were; the rest (Phase 28) are additive.

type ZonePolicy added in v0.5.0

type ZonePolicy struct{ Zone, AuthorityID string }

ZonePolicy is a domain that keeps a wildcard certificate (the domain and *.domain).

Jump to

Keyboard shortcuts

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