lego

repository·main·Indexed 27 days ago

https://github.com/go-acme/lego

A 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.

Tokens
147.7K
Snippets
537
Records
1.1K
Agent score
91%

What's inside lego

  1. Overview of Lego ACME client and library

    main
    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.
  2. Overview of Lego ACME client

    main

    Lego 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.
  3. Use the Memcached HTTP provider for ACME challenges

    main
    The 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.
  4. Lego challenge types and certificate features

    main

    Lego supports several ACME challenge types and certificate management features:

    Challenge Types:

    • DNS-01
    • HTTP-01
    • TLS-ALPN-01
    • DNS-PERSIST-01

    Certificate Management:

    • Obtain, renew, and revoke certificates.
    • Support for Wildcard and SAN (Subject Alternative Name) certificates.
    • CNAME support is enabled by default.
  5. Configure the EasyDNS DNS provider

    main

    To use EasyDNS as a DNS provider in lego, use the provider code easydns. 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 _FILE to the environment variable names (e.g., EASYDNS_KEY_FILE).

    EASYDNS_TOKEN=xxx \
    EASYDNS_KEY=yyy \
    lego run --dns easydns -d '*.example.com' -d example.com
  6. Configure Azure DNS Authentication Methods

    main

    Set the AZURE_AUTH_METHOD environment variable to specify your authentication strategy:

    • env: Use Client Secret or Client Certificate (requires AZURE_CLIENT_ID, AZURE_TENANT_ID, and either AZURE_CLIENT_SECRET or AZURE_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 (requires az 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:

    1. Client Secret (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET)
    2. Client Certificate (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_CERTIFICATE_PATH)
    3. Workload Identity
    4. Azure CLI shared credentials (~/.azure folder)
  7. Migrate from v4 to v5: Context usage

    main

    In v5, most functions and methods now require a context.Context argument. 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)
  8. Configure Pre-Hooks

    main

    A pre-hook is 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.yaml configuration file.

    CLI usage: Use the --pre-hook flag.

    Configuration file usage: Define the pre command under the hooks section in your .lego.yaml file.

    # CLI
    lego run -d 'example.com' --pre-hook='./my-pre-hook.sh'
    # .lego.yaml
    hooks:
      pre:
        command: './my-pre-hook.sh'