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
- Variables
- func NamesOfPEM(pemText string) []string
- func ValidKeyType(t string) bool
- func ValidName(n string) error
- type Attention
- type Authority
- type AuthorityInput
- type Challenge
- type ChallengeInfo
- type Config
- type DNSHost
- type ImportInput
- type ImportResult
- type Manager
- func (m *Manager) AddAuthority(ctx context.Context, in AuthorityInput) (Authority, error)
- func (m *Manager) AddEvent(ctx context.Context, key, kind, detail, actor string)
- func (m *Manager) Attentions() []Attention
- func (m *Manager) Authorities(ctx context.Context) ([]Authority, error)
- func (m *Manager) Authority(ctx context.Context, id string) (Authority, error)
- func (m *Manager) Bundle(ctx context.Context, key, actor string) (chain, privKey string, err error)
- func (m *Manager) Chain(key string) (string, error)
- func (m *Manager) CompleteRequest(ctx context.Context, id, chainText, actor string) (ImportResult, error)
- func (m *Manager) CountForZone(zone string) int
- func (m *Manager) CreateRequest(ctx context.Context, names []string, keyType string) (RequestView, error)
- func (m *Manager) DefaultAuthorityID(ctx context.Context) string
- func (m *Manager) Delete(ctx context.Context, key string, force bool) error
- func (m *Manager) DeleteAuthority(ctx context.Context, id string) error
- func (m *Manager) DeleteRequest(ctx context.Context, id string) error
- func (m *Manager) Events(ctx context.Context, key string) ([]store.CertEvent, error)
- func (m *Manager) FallbackAuthorityID(ctx context.Context) string
- func (m *Manager) Get(ctx context.Context, key string) (View, bool)
- func (m *Manager) Import(ctx context.Context, in ImportInput) (ImportResult, error)
- func (m *Manager) Kick()
- func (m *Manager) List() []View
- func (m *Manager) ListRequests(ctx context.Context) ([]RequestView, error)
- func (m *Manager) Load(ctx context.Context) error
- func (m *Manager) PairFor(host string) (Pair, bool)
- func (m *Manager) Pairs() []Pair
- func (m *Manager) Pin(host string) string
- func (m *Manager) PlanFor(host string) Plan
- func (m *Manager) Reconcile(ctx context.Context)
- func (m *Manager) Reissue(ctx context.Context, key string, names []string, actor string) (View, error)
- func (m *Manager) Renew(ctx context.Context, host string) error
- func (m *Manager) RenewNow(ctx context.Context, key, actor string) error
- func (m *Manager) Request(ctx context.Context, in RequestInput) (View, error)
- func (m *Manager) Revoke(ctx context.Context, key, actor string) (View, error)
- func (m *Manager) Run(ctx context.Context)
- func (m *Manager) SelfSignedBundle(hosts ...string) string
- func (m *Manager) SelfSignedPEM(host string) string
- func (m *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Manager) SetDNS(h DNSHost)
- func (m *Manager) SetDefaultAuthority(ctx context.Context, id string) error
- func (m *Manager) SetFallbackAuthority(ctx context.Context, id string) error
- func (m *Manager) SetHosts(hosts []string)
- func (m *Manager) TestAuthority(ctx context.Context, id string) (Authority, error)
- func (m *Manager) Update(ctx context.Context, key string, in UpdateInput, actor string) (View, error)
- func (m *Manager) UpdateAuthority(ctx context.Context, id string, in AuthorityInput) (Authority, error)
- func (m *Manager) Verify(ctx context.Context, key, actor string) (View, error)
- func (m *Manager) ZoneOf(key string) string
- type OrderView
- type Pair
- type Plan
- type Preset
- type RequestInput
- type RequestView
- type UpdateInput
- type View
- type ZonePolicy
Constants ¶
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" )
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.
const ( KeyECDSA = "ecdsa-p256" KeyRSA2048 = "rsa-2048" KeyRSA3072 = "rsa-3072" KeyRSA4096 = "rsa-4096" )
Key types.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrInvalid = errors.New("invalid") ErrConflict = errors.New("conflict") )
Errors the API maps.
var ErrUnknownHost = errors.New("no certificate is managed for this host")
ErrUnknownHost is returned by Renew for hosts that need no certificate.
var KeyTypes = []string{KeyECDSA, KeyRSA2048, KeyRSA3072, KeyRSA4096}
KeyTypes lists what a certificate's key can be.
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
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
ValidKeyType reports whether t is a known key type ("" means the default).
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 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
ImportResult is the imported certificate and what to know about it.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) AddAuthority ¶ added in v0.5.0
AddAuthority registers an authority. Its account is created at the first use, or with TestAuthority.
func (*Manager) Attentions ¶ added in v0.5.0
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
Authorities lists every authority, built-in ones first.
func (*Manager) Bundle ¶ added in v0.5.0
Bundle returns the chain and the private key of a certificate.
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
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
DefaultAuthorityID is the authority new certificates use.
func (*Manager) Delete ¶ added in v0.5.0
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
DeleteAuthority removes an authority nobody uses.
func (*Manager) DeleteRequest ¶ added in v0.5.0
DeleteRequest discards a request (and its key).
func (*Manager) FallbackAuthorityID ¶ added in v0.5.0
FallbackAuthorityID is the authority tried when the first one keeps failing ("" = none).
func (*Manager) Get ¶ added in v0.5.0
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) List ¶
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) PairFor ¶ added in v0.1.2
PairFor returns the certificate and key that serve host, if there is one.
func (*Manager) Pairs ¶
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 ¶
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) 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) Request ¶ added in v0.5.0
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
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) SelfSignedBundle ¶
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 ¶
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
SetDNS connects the domains. Without it wildcard orders are manual.
func (*Manager) SetDefaultAuthority ¶ added in v0.5.0
SetDefaultAuthority chooses the authority new certificates use.
func (*Manager) SetFallbackAuthority ¶ added in v0.5.0
SetFallbackAuthority chooses the authority tried when the default keeps failing or is rate limited ("" turns it off).
func (*Manager) TestAuthority ¶ added in v0.5.0
TestAuthority registers the account (or finds it) and records the result.
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.
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).