Help us shape the future of Go! Take the 2026 Go Developer Survey

acme

package
v1.4.13 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProdDirectory    = "https://acme-v02.api.letsencrypt.org/directory"
	StagingDirectory = "https://acme-staging-v02.api.letsencrypt.org/directory"
)

Directory URLs.

View Source
const (
	SchemaVersion = "1"
	ChallengeDNS  = "dns-01"
	RenewWindow   = 30 * 24 * time.Hour
)

Contract constants; RenewWindow is how close to expiry a lineage is due.

View Source
const ChallengeHTTP = "http-01"

ChallengeHTTP is the lineage challenge name for HTTP-01.

View Source
const ChallengePrefix = "/.well-known/acme-challenge/"

ChallengePrefix is the URL prefix HTTP-01 uses.

View Source
const NginxChallengeLocation = `` /* 663-byte string literal not displayed */

NginxChallengeLocation is the location block (4-space indented, newline terminated) placed in the default server and in every server block that listens on port 80, before any catch-all redirect or proxy. `^~` on the ACME prefix only, so no application path is shadowed; a request is served only when it is a bare token ([A-Za-z0-9_-]+) and a GET or HEAD, and never through a symlink below the webroot.

View Source
const WebrootName = ".acme-webroot"

WebrootName is the directory under the served ssl dir that holds challenge files; inside nginx it is NginxSSLContainerPath + "/" + WebrootName.

Variables

View Source
var LegoImage = lockedLego()

LegoImage is the pinned ACME client image: goacme/lego at its multi-arch index digest, read from the image lock.

Functions

func Due

func Due(notAfter, now time.Time, force bool) bool

Due reports whether a certificate expiring at notAfter is due: force, or 30 days or fewer left.

func EnsureState

func EnsureState(sslDir string) error

EnsureState creates the 0700 state dir and its `*` .gitignore if absent.

func EnsureWebroot

func EnsureWebroot(sslDir string) error

EnsureWebroot creates the webroot and its challenge directory (0755: nginx runs as another user and must traverse it).

func Install

func Install(ctx context.Context, r InstallReq) (map[string]int, error)

Install writes a new generation per target, switches them, reloads, verifies and prunes. A failure after the switch restores every previous generation.

func Issue

func Issue(ctx context.Context, r IssueReq) (cert, key string, err error)

Issue runs `lego run` and returns the certificate and key paths on the host.

func IssueHTTP01

func IssueHTTP01(ctx context.Context, r IssueReq) (cert, key string, err error)

IssueHTTP01 issues r.Domains over HTTP-01 (no wildcard: the CA only validates a wildcard over DNS-01) and returns the certificate and key paths. r.Provider is ignored; r.Secret is never called.

func Lock

func Lock(sslDir string, wait time.Duration) (release func(), err error)

Lock takes the exclusive run lock, waiting up to wait, and returns its release func. A busy lock returns an *Error naming the holder's pid.

func NeedsTOS

func NeedsTOS(sslDir string, staging bool, contact string) bool

NeedsTOS reports whether no ACME account for contact exists yet.

func ParseINI

func ParseINI(data []byte) map[string]string

ParseINI parses `key = value` lines (`#`/`;` comments, `[sections]` ignored, whitespace trimmed) into one flat map.

func ProbeWebroot

func ProbeWebroot(ctx context.Context, sslDir, addr, host string, get func(*http.Request) (*http.Response, error)) error

ProbeWebroot writes a random token file into the webroot, GETs it from addr (host:port of the served nginx over plain HTTP) with Host: host, and removes it. A nil error means the served nginx answers the challenge location from the webroot. get defaults to a short-timeout HTTP client.

func Refuse

func Refuse(fix, format string, a ...any) error

Refuse builds an *Error from a remediation and a formatted message.

func Repair

func Repair(sslDir string, targets []string) error

Repair re-links each target whose link is missing, dangling or mismatched to its newest valid generation; a real directory (not yet converted) is left.

func Save

func Save(sslDir string, f File) error

Save writes f atomically (temp + rename), lineages sorted, nil lists as [].

func SecretNames

func SecretNames(provider string) (names []string, ok bool)

SecretNames returns the secret names a provider needs; ok is false for an unknown provider. Provider "exec" (test hook) needs none.

func StateDir

func StateDir(sslDir string) string

StateDir returns <sslDir>/.acme.

func ValidTarget

func ValidTarget(t string) bool

ValidTarget reports whether t is a safe lineage target: certificates/<one plain name>, never `.`, empty, absolute, hidden or containing `..`.

func WebrootDir

func WebrootDir(sslDir string) string

WebrootDir returns <sslDir>/.acme-webroot.

Types

type Certbot

type Certbot struct {
	Name, Authenticator, Conf string
	Domains                   []string
	Err                       error
}

Certbot is one certbot lineage as found on disk; Err is set when its live certificate could not be read.

func ReadCertbot

func ReadCertbot(dir string) (out []Certbot, err error)

ReadCertbot lists the lineages under dir (renewal/*.conf), sorted by name.

type Error

type Error struct{ What, Fix string }

Error is a refusal with its remediation.

func (*Error) Error

func (e *Error) Error() string

type File

type File struct {
	SchemaVersion string    `json:"schema_version"`
	Contact       string    `json:"contact"`
	Lineages      []Lineage `json:"lineages"`
}

File is the lineages.json document.

func Load

func Load(sslDir string) (f File, err error)

Load reads lineages.json; a missing file is an empty File.

type Hooks

type Hooks struct{ Directory, CABundle, Network, Resolvers, Fault string }

Hooks are the test-only knobs read from NSELF_ACME_*.

func HooksFromEnv

func HooksFromEnv(get func(string) string) (Hooks, error)

HooksFromEnv reads the hooks; any of them without a non-Let's-Encrypt NSELF_ACME_DIRECTORY (i.e. against production) is refused.

type Input

type Input struct {
	ProjectDir, FrontedBy, ProjectName, NginxContainer, Contact, AgeKeyPath string
	// NoSecrets is set for runs that handle no DNS credential (HTTP-01): `age` and the age key are not required.
	NoSecrets bool
	FindNginx func(context.Context, docker.ServiceMatch) (string, error)
	Mounts    func(context.Context, string) ([]docker.Mount, error)
	LookPath  func(string) (string, error)
}

Input is what Resolve needs; the func fields default to the docker funnel and exec.LookPath.

type InstallReq

type InstallReq struct {
	SSLDir    string
	Targets   []string // dirs relative to SSLDir, e.g. certificates/api-example-org
	Cert, Key []byte
	Reloader  Reloader
	Verify    func(context.Context) error
	Fault     string
	Exit      func(int)
}

InstallReq is one install of one certificate into one or more targets. Verify (optional) runs after the reload; Fault and Exit are the test hook.

type IssueReq

type IssueReq struct {
	SSLDir, Name, Provider, Contact string
	Domains                         []string
	Staging, AcceptTOS              bool
	Hooks                           Hooks
	Secret                          func(name string) (string, error)
	Run                             func(context.Context, docker.RunSpec) (string, string, error)
}

IssueReq describes one issuance. AcceptTOS adds --accept-tos (set only when NeedsTOS and the terms were agreed); Secret reads the secret store.

type Lineage

type Lineage struct {
	Name              string   `json:"name"`
	Domains           []string `json:"domains"`
	Challenge         string   `json:"challenge"`
	DNSProvider       string   `json:"dns_provider"`
	CredentialSecrets []string `json:"credential_secrets"`
	Targets           []string `json:"targets"`
	KeyType           string   `json:"key_type"`
	AdoptedFrom       *string  `json:"adopted_from"`
	LastIssued        *string  `json:"last_issued"`
}

Lineage is one managed certificate.

func Plan

func Plan(cbs []Certbot, hosts map[string]string, provider, only string) (adopt []Lineage, refused []string)

Plan maps certbot lineages onto served targets. provider is the DNS provider of the supplied credential ("" when none); only, when set, limits adoption to that lineage. Refusals are "<name>: <reason and remediation>".

func PlanWith

func PlanWith(cbs []Certbot, hosts map[string]string, provider, only string, probe ProbeFunc) (adopt []Lineage, refused []string)

PlanWith is Plan with an HTTP-01 probe. With a probe, a webroot lineage and no DNS credential, every name is probed: all answering adopts the lineage as http-01, any failure refuses it with the remediation.

type NginxReloader

type NginxReloader struct {
	Container string
	Exec      func(ctx context.Context, container string, cmd []string) (string, string, error)
}

NginxReloader runs `nginx -t` then `nginx -s reload` in Container (Exec defaults to docker.ExecCapture; no socket, no restart).

func (NginxReloader) Reload

func (n NginxReloader) Reload(ctx context.Context) error

Reload implements Reloader; a failing `nginx -t` means nothing was reloaded.

type ProbeFunc

type ProbeFunc func(host string) error

ProbeFunc reports whether the served nginx answers the HTTP-01 challenge location for host (see ProbeWebroot); nil means http-01 adoption is off.

type Reloader

type Reloader interface {
	Reload(ctx context.Context) error
}

Reloader makes the serving process pick up installed files.

type Resolution

type Resolution struct{ Root, SSLDir, NginxDir, Container, Contact, AgeBin, AgeKey string }

Resolution is the printed answer to "where does this write, who reloads".

func Resolve

func Resolve(ctx context.Context, in Input) (*Resolution, error)

Resolve runs the preflight list in order and returns the first failure.

func (*Resolution) Print

func (r *Resolution) Print(w io.Writer)

Print writes the resolution, one fact per line.

Jump to

Keyboard shortcuts

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