lego
repository·main·Indexed 27 days ago
https://github.com/go-acme/legoA comprehensive ACME v2 client and Go library used to automate the acquisition and management of TLS certificates from Let's Encrypt and other ACME-compliant Certificate Authorities.
What's inside lego
- Lego is an ACME client and library written in Go. It is used to automate the process of obtaining, renewing, and revoking TLS certificates. It supports multiple ACME servers (such as Let's Encrypt and ZeroSSL) and provides support for various certificate challenges and DNS providers.
Overview of Lego ACME client
mainLego is an ACME v2 (RFC 8555) client and library written in Go, designed for Let's Encrypt and other ACME Certificate Authorities. It provides automated certificate management including registration, obtaining (from scratch or existing CSR), renewal, and revocation.
Key features include:
- Support for RFC 8737 (ALPN), RFC 8738 (IP addresses), and RFC 9773 (ARI).
- Support for various ACME profiles and persistent DNS TXT record validation.
- Support for over 200 DNS providers.
- Robust implementation of HTTP-01, DNS-01, and TLS-ALPN-01 challenges.
- SAN (Subject Alternative Name) certificate support.
- CNAME support by default.
- Certificate bundling and OCSP helper functions.
- Ability to use custom challenge solvers.
Use the Memcached HTTP provider for ACME challenges
mainThe Memcached HTTP provider publishes ACME challenges into Memcached, allowing them to be retrieved by a web server like nginx. This is useful for verifying domains hosted on a cluster of servers, as you can specify multiple Memcached servers and the responses will be published to all of them.Lego challenge types and certificate features
mainLego supports several ACME challenge types and certificate management features:
Challenge Types:
DNS-01HTTP-01TLS-ALPN-01DNS-PERSIST-01
Certificate Management:
- Obtain, renew, and revoke certificates.
- Support for Wildcard and SAN (Subject Alternative Name) certificates.
- CNAME support is enabled by default.
Configure the EasyDNS DNS provider
mainTo use EasyDNS as a DNS provider in
lego, use the provider codeeasydns. You must provide credentials via environment variables. You can also configure API endpoints, timeouts, and propagation settings using specific environment variables.To use file-based credentials instead of raw values, append
_FILEto the environment variable names (e.g.,EASYDNS_KEY_FILE).EASYDNS_TOKEN=xxx \ EASYDNS_KEY=yyy \ lego run --dns easydns -d '*.example.com' -d example.comConfigure Azure DNS Authentication Methods
mainSet the
AZURE_AUTH_METHODenvironment variable to specify your authentication strategy:env: Use Client Secret or Client Certificate (requiresAZURE_CLIENT_ID,AZURE_TENANT_ID, and eitherAZURE_CLIENT_SECRETorAZURE_CLIENT_CERTIFICATE_PATH).wli: Use Azure Workload Identity (for AKS clusters using federated credentials).msi: Use Azure Managed Identity (for Azure VMs or Azure Arc).cli: Use Azure CLI credentials (requiresaz login).oidc: Use OpenID Connect.pipeline: Use Azure DevOps Pipelines.
If no method is specified, Lego uses Default Azure Credentials, which attempts to authenticate in this order:
- Client Secret (
AZURE_CLIENT_ID,AZURE_TENANT_ID,AZURE_CLIENT_SECRET) - Client Certificate (
AZURE_CLIENT_ID,AZURE_TENANT_ID,AZURE_CLIENT_CERTIFICATE_PATH) - Workload Identity
- Azure CLI shared credentials (
~/.azurefolder)
Use the Hetzner DNS provider
mainTo use Hetzner for DNS challenges in Lego, use the provider code
hetzner. You must provide an API token via theHETZNER_API_TOKENenvironment variable.HETZNER_API_TOKEN="xxxxxxxxxxxxxxxxxxxxx" \ lego run --dns hetzner -d '*.example.com' -d example.comLocate and validate the lego configuration file
mainlego searches for configuration files in the current working directory using the following filenames:
.lego.yml.lego.yaml
You can validate your configuration file against the provided JSON Schema:
lego.jsonschema.json.Use the Nodion DNS provider with Lego
mainTo use Nodion for DNS-01 challenges in Lego, use the provider code
nodion. You must provide an API token via theNODION_API_TOKENenvironment variable.NODION_API_TOKEN="xxxxxxxxxxxxxxxxxxxxx" \ lego run --dns nodion -d '*.example.com' -d example.comMigrate from v4 to v5: Context usage
mainIn v5, most functions and methods now require a
context.Contextargument. When migrating, ensure you pass a context (e.g.,context.TODO()or a context with a timeout) to these methods.// Before client.Certificate.Obtain(request) // After client.Certificate.Obtain(context.TODO(), request)Configure Pre-Hooks
mainA
pre-hookis executed before a certificate is created or renewed, but only if a change is actually required. You can configure it via the CLI or a.lego.yamlconfiguration file.CLI usage: Use the
--pre-hookflag.Configuration file usage: Define the
precommand under thehookssection in your.lego.yamlfile.# CLI lego run -d 'example.com' --pre-hook='./my-pre-hook.sh'# .lego.yaml hooks: pre: command: './my-pre-hook.sh'Run Lego from Docker
mainYou can run Lego using the official Docker image. Use the following command to verify the installation by viewing the help text:
docker run goacme/lego -h