Acmebot for Microsoft Azure

repository·master·Indexed 22 days ago

https://github.com/polymind-inc/acmebot

An automation solution for managing the lifecycle of ACME SSL/TLS certificates in Microsoft Azure. Acmebot automates issuance and renewal using DNS-01 validation and stores certificates in Azure Key Vault. It supports ACME v2 compliant Certification Authorities including Let's Encrypt, GlobalSign, Google Trust Services, SSL.com, and ZeroSSL, and integrates with Azure services such as App Service, Front Door, Application Gateway v2, and API Management.

Tokens
33.4K
Snippets
85
Records
169
Agent score
75%

What's inside Acmebot

  1. Overview of Acmebot for Microsoft Azure

    master

    Acmebot is an automation tool for ACME SSL/TLS certificate issuance and renewal within Microsoft Azure. It is built around DNS-01 validation and uses Azure Key Vault to securely store private keys and issued certificates.

    Key capabilities include:

    • Automating certificate fleets with per-certificate renewal state.
    • Centralizing certificates for multiple Azure services and domains.
    • Monitoring operations via Application Insights and webhooks.
    • Supporting zone apex names, wildcards, and SANs (Subject Alternative Names).
  2. Overview of Acmebot functionality

    master

    Acmebot is an automation tool for ACME SSL/TLS certificate issuance and ARI-aware renewal on Microsoft Azure. It operates as an Azure Function App and uses DNS-01 validation to prove domain ownership.

    Key Capabilities:

    • ACME Management: Registers/maintains ACME accounts and creates orders for zone apex, wildcard, and multi-domain certificates.
    • DNS Automation: Automatically manages _acme-challenge TXT records via configured DNS providers.
    • Key Vault Integration: Requests certificates directly in Azure Key Vault and merges the issued chain into the existing Key Vault certificate object.
    • Metadata & State: Tags managed certificates with renewal state, next check time, and fallback behavior.
    • ARI Support: Uses ACME Renewal Information (ARI) to respect CA-suggested renewal windows and Retry-After timings.
    • Notifications: Sends webhook notifications for successful or failed operations.
  3. Configure Managed Identity for Acmebot

    master

    Acmebot supports two identity modes for the Function App:

    1. System-assigned managed identity: Best for a single, isolated deployment.
    2. User-assigned managed identity: Recommended for stable identities across redeployments or when using multiple apps. If using a user-assigned identity, the template sets the Acmebot__ManagedIdentityClientId app setting to the identity's Client ID.
  4. How Acmebot handles scheduled certificate renewal

    master

    Acmebot performs automated renewals using a daily timer. The renewal logic is designed to be ARI-aware (ACME Renewal Information) to optimize timing.

    Renewal Logic

    1. Discovery: The system lists certificates in Key Vault and filters for those tagged as Acmebot-managed and matching the current ACME endpoint.
    2. ARI-Awareness: If the CA provides ARI, Acmebot uses the suggested window and Retry-After timing for the next check.
    3. Fallback: If ARI is unavailable, Acmebot uses a RenewBeforeExpiry lifetime-percentage strategy.
    4. Execution: Certificates are reissued using their stored Key Vault policy. When ARI is used, the previous certificate identifier is sent as the replaces parameter.

    Error Handling

    If a renewal fails, only that specific certificate enters a retrying state. It will be re-evaluated after a six-hour delay.

  5. Understand the Acmebot Operation Lifecycle

    master

    Long-running operations like certificate issuance (POST /api/certificates) and manual renewal (POST /api/certificates/{certificateName}/renew) follow an asynchronous pattern:

    1. Initiate: Call the endpoint. It returns 202 Accepted with a Location header.
    2. Resolve URL: The Location header contains a path relative to the original request. Resolve it against the base endpoint to get the polling URL.
    3. Poll: Request the polling URL repeatedly until you receive one of the following:
      • 202 Accepted: The operation is still pending or running.
      • 200 OK: The operation completed successfully.
      • Problem response: The operation failed.
  6. Configure Managed Identity for Azure and Cloud DNS providers

    master

    Acmebot uses managed identities to access Azure resources and perform cross-cloud federation. By default, it uses the app-wide managed identity. For provider-specific requirements (Azure DNS, Azure Private DNS, Route 53, or Google Cloud DNS), you can configure a user-assigned managed identity client ID. If no client ID is provided, the Azure SDK defaults to the Function App's system-assigned managed identity.

    Recommended Scopes and Permissions:

    ResourcePermission
    Key VaultKey Vault Certificates Officer or equivalent
    Azure DNS zoneDNS Zone Contributor or narrower
    Azure Private DNS zonePrivate DNS Zone Contributor or narrower
    Route 53 IAM roleTrust policy allowing the managed identity web identity token
    Google Cloud service accountWorkload identity principal binding for impersonation

    Best Practice: Assign roles at the individual zone or vault scope rather than the subscription scope.

  7. How ACME DNS-01 validation works in Acmebot

    master

    Acmebot uses the ACME DNS-01 validation method to issue certificates. The process follows these steps:

    1. Record Creation: Acmebot creates one or more _acme-challenge TXT records in your DNS provider.
    2. Propagation Wait: Acmebot waits for a predefined propagation delay (specific to the provider) to ensure the records are visible globally.
    3. Validation: Acmebot asks the ACME server to validate the existence of these records.
    4. Cleanup: Once validation is complete, Acmebot deletes the _acme-challenge TXT records.

    To use this, you must configure at least one DNS provider under the Acmebot configuration section in your Function App settings before starting the app.

  8. Understand the Acmebot certificate rollout workflow

    master

    Acmebot manages the issuance and storage of certificates in Azure Key Vault. However, Acmebot does not push certificates to your services. You must treat issuance and rollout as two connected workflows:

    1. Issuance: Acmebot renews the certificate and creates a new version in Azure Key Vault.
    2. Rollout: The consuming Azure service (e.g., App Service, Front Door) must pick up that new version based on its own Key Vault integration settings.

    To ensure a successful rollout, follow these principles:

    • Stable Naming: Keep the Key Vault certificate name constant so downstream service references do not break during renewal.
    • Versionless References: Whenever possible, use Latest or versionless Key Vault references (omitting the specific version GUID) to allow services to rotate automatically.
    • Permissions: Ensure the consuming service's managed identity has read access to the certificate or secret in Key Vault.
    • Validation: Verify that the certificate's Subject Alternative Names (SANs) match your service's custom domain.
  9. How Acmebot coordinates certificate issuance

    master

    Acmebot uses a Durable Functions orchestration to manage the lifecycle of a certificate order. The process follows these steps:

    1. Request: A certificate policy is posted to POST /api/certificates via the Dashboard.
    2. Validation: The HTTP function validates authentication and the request shape.
    3. DNS Setup: Acmebot identifies the correct DNS zone, creates DNS-01 TXT records via a provider, and waits for propagation.
    4. Challenge: Acmebot queries DNS to verify the TXT values and answers the ACME challenges.
    5. Key Vault Integration: Key Vault creates the certificate operation and CSR. Acmebot finalizes the ACME order using the Key Vault CSR.
    6. Finalization: Acmebot downloads the issued chain, merges it into Key Vault, applies metadata tags, and triggers a completion webhook.

    Note: DNS records are automatically cleaned up after challenge processing, even if the operation fails.

  10. Core concepts: Key Vault, DNS, and CAs in Acmebot

    master

    To use Acmebot effectively, understand these three core pillars:

    Key Vault

    Key Vault acts as the primary certificate store. Acmebot initiates certificate operations within Key Vault, allowing Key Vault to handle private key generation or reuse, and then merges the ACME-issued chain into the pending operation.

    DNS Providers

    Acmebot relies exclusively on DNS-01 validation. This method is required for wildcard certificates and allows for certificate issuance even if the target application is not publicly reachable. You must configure at least one DNS provider before deploying the Function App.

    Certificate Authorities (CAs)

    Acmebot supports ACME v2 directory endpoints. You can use common providers like Let's Encrypt, GlobalSign, Google Trust Services, SSL.com, and ZeroSSL, or provide a custom ACME directory URL via the deployment form.

  11. Understand Acmebot automatic renewal behavior

    master

    Acmebot manages certificate renewals via the RenewCertificates timer, which runs daily for enabled managed certificates. Each certificate maintains its own renewal state and next check time.

    Renewal logic follows these rules:

    1. ARI-Aware Renewal: If the Certificate Authority (CA) provides ACME Renewal Information (ARI), Acmebot uses the CA's suggested renewal window and Retry-After timing. It renews after the suggested window has started.
    2. Threshold-Based Renewal: If ARI is unavailable, Acmebot falls back to a percentage-based threshold. It renews when the remaining certificate lifetime is less than or equal to the value defined in Acmebot__RenewBeforeExpiry (default is 30%).

    Note: Azure Functions timer schedules run in UTC unless the WEBSITE_TIME_ZONE setting is configured in the hosting plan.

    Acmebot__RenewBeforeExpiry=30
  12. Configure build metadata for versioning and upgrades

    master

    The dashboard footer displays build metadata embedded by Vite. You can control the versioning and upgrade notification behavior by setting specific environment variables before running npm run build.

    • Version-based Upgrades: If ACMEBOT_VERSION is set to a release-like value (e.g., v5.0.0), the dashboard will check GitHub releases (including prereleases) and display an upgrade notification if a newer version is found.
    • Disabling Upgrade Checks: Setting the version to a non-version value like dev will skip the upgrade check.
    • Commit Linking: Setting ACMEBOT_COMMIT_HASH allows the dashboard to link directly to the specific GitHub commit.