ACME with a Windows CA: automatic certificates for Linux servers

A Windows CA (AD CS) does not speak ACME. Linux servers can still get their certificates from it just as automatically as from Let's Encrypt. The trick is a small gateway in between: acme2certifier accepts ACME requests and passes only the verified CSR on to the Windows CA.

Three ways to automatic renewal

Internal servers often get their certificates from the company CA on Windows. Renewal is then usually manual, and sooner or later one expires. There are three ways to automate it:

This guide covers the first way.

How an issuance works

Until the very end the Linux server only talks to acme2certifier. The Windows CA only sees the finished CSR, submitted via a service account.

  1. Fetch the directory: the client loads https://acme.corp.example.com/directory and gets the endpoints.
  2. Create an account: the client creates its own key pair and registers, with key ID and HMAC key if External Account Binding (EAB) is enabled.
  3. Create an order: the client names the desired host names. acme2certifier checks them against allowed_domainlist.
  4. Solve the challenge: with http-01 the client places a token under /.well-known/acme-challenge/, with dns-01 a TXT record. acme2certifier fetches it itself.
  5. Finalize: the client sends the CSR. acme2certifier checks that the names match the order exactly and hands it to the CA handler.
  6. Issuance: the handler submits the CSR to AD CS with the configured template and fetches certificate and chain.
  7. Download: the client stores certificate and chain and runs its deploy hook, e.g. a reload of nginx.
  8. Renewal: not a special case; the client simply goes through a new order. certbot renews 30 days before expiry; acme2certifier can recommend a time via ACME Renewal Information (ARI).

The Microsoft handlers cannot revoke. That is still done in the Certification Authority console (certsrv.msc).

The two handlers for AD CS

mscertsrvmsicpr (formerly mswcce)
Route to the CAHTTPS to /certsrv/RPC (MS-ICPR) over SMB
PortsTCP 443TCP 445, if needed 135 and dynamic RPC ports
Windows roleCertification Authority Web Enrollment (IIS)none extra
AuthenticationKerberos (gssapi), NTLM, BasicKerberos or NTLM
Typical pitfallExtended Protection in IIS set to “Required”firewall between gateway and CA

Rule of thumb: mscertsrv if web enrollment already runs or only HTTPS may pass the firewall. msicpr if no IIS should run on the CA. For both, Kerberos is the better choice; NTLM is considered deprecated.

Preparing the Windows CA

curl -I --negotiate -u : https://ca01.corp.example.com/certsrv/

acme2certifier with Docker

The gateway is easiest to run as a container. Everything persistent lives in the volume: configuration, database, keytab and CA chain. If the configuration is missing, the container creates a template on first start.

services:
  acme2certifier:
    image: grindsa/acme2certifier:apache2-wsgi
    container_name: acme2certifier
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./data:/var/www/acme2certifier/volume

The configuration data/acme_srv.cfg for AD CS with Kerberos via web enrollment:

[DEFAULT]
debug: False

[Account]
contact_check_disable: True

[Order]
allowed_domainlist: ["corp.example.com", "*.corp.example.com"]
wildcard_certificate_disable: True

[Challenge]
http_01_support: True
dns_01_support: True

[CAhandler]
handler_module: acme2certifier.cahandlers.mscertsrv_ca_handler
host: ca01.corp.example.com
auth_method: gssapi
template: WebServer-Linux
allowed_templates: ["WebServer-Linux"]
allowed_domainlist: ["corp.example.com", "*.corp.example.com"]
krb5_principal: svc-a2c-enroll@CORP.EXAMPLE.COM
krb5_keytab: /var/www/acme2certifier/volume/svc-a2c-enroll.keytab
krb5_config: /var/www/acme2certifier/volume/krb5.conf
ca_bundle: /var/www/acme2certifier/volume/ca-chain.pem

For msicpr only the [CAhandler] section changes: module acme2certifier.cahandlers.msicpr_ca_handler, plus ca_name, target_domain, domain_controller and use_kerberos: True. HTTPS is enabled as soon as the gateway's own server certificate is in the volume, for the Apache image as acme2certifier.pem with key and chain. Restart the container after every configuration change.

docker compose up -d
docker compose logs -f acme2certifier
curl https://acme.corp.example.com/directory

Connecting the Linux servers

Compared with Let's Encrypt, only the address of the ACME server changes on the servers. First the server must trust the company CA, otherwise even the connection to the gateway fails:

# Debian/Ubuntu
cp corp-root-ca.crt /usr/local/share/ca-certificates/
update-ca-certificates
# RHEL/Rocky/Alma
cp corp-root-ca.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust

certbot with http-01 via the existing webroot; renewal is handled by the bundled systemd timer:

certbot certonly --server https://acme.corp.example.com/directory \
  --webroot -w /var/www/html -d app01.corp.example.com \
  --register-unsafely-without-email --agree-tos \
  --deploy-hook "systemctl reload nginx"

systemctl list-timers | grep certbot
certbot renew --dry-run

acme.sh as an alternative without Python:

acme.sh --issue --server https://acme.corp.example.com/directory \
  -d app01.corp.example.com -w /var/www/html
acme.sh --install-cert -d app01.corp.example.com \
  --key-file /etc/ssl/private/app01.key \
  --fullchain-file /etc/ssl/certs/app01-fullchain.pem \
  --reloadcmd "systemctl reload apache2"

In nginx and Apache, fullchain.pem and privkey.pem are configured as for Let's Encrypt with nginx and with Apache. Tomcat 8.5 and later reads PEM directly, see Tomcat with Let's Encrypt. If you need a keystore, rebuild it in the deploy hook:

#!/bin/sh
# /etc/letsencrypt/renewal-hooks/deploy/tomcat.sh
set -e
D=/etc/letsencrypt/live/app01.corp.example.com
openssl pkcs12 -export -in "$D/fullchain.pem" -inkey "$D/privkey.pem" \
  -out /opt/tomcat/conf/app01.p12 -name tomcat -passout pass:changeit \
  -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -macalg sha1
chown tomcat: /opt/tomcat/conf/app01.p12
systemctl restart tomcat

The ACME helper generates the matching commands for your server; just replace the server address. Windows servers can join in too: win-acme accepts a custom ACME server with --baseuri.

Hardening: the gateway is powerful

Anyone who reaches the gateway and passes a challenge gets a certificate signed by the company CA. These restrictions are therefore mandatory:

Typical errors

SymptomCauseFix
SSL error fetching /directorycompany root missing from the client's trust storedistribute the root, update-ca-certificates
Challenge fails (http-01)gateway cannot reach port 80 of the server, or DNS resolves differentlycheck the firewall, set dns_server_list, or use dns-01
Order stays “processing”template requires CA certificate manager approvalturn off approval in the template
Certificate without SAN or with the wrong nametemplate builds the subject from AD“Supply in the request”
mscertsrv: HTTP 401 despite correct loginExtended Protection in IIS set to “Required”set it to “Accept” or use a current requests-gssapi
mscertsrv with NTLM: MD4 errorOpenSSL 3 without legacy providerenable the legacy provider or use Kerberos
msicpr: timeoutTCP 445 or RPC ports blockedopen the firewall between gateway and CA
Kerberos: “Clock skew too great”gateway and DC clocks differset up NTP on the Docker host

CA errors only appear in the gateway log (docker logs acme2certifier, more detail with debug: True); the client only sees a short message. Whether the issued certificate and chain are right is shown by the SSL check for publicly reachable servers or the certificate converter for the file.

FAQ

Do the Linux servers have to be domain members?

No. Only the gateway logs on to the CA with a service account. The Linux servers only speak ACME with the gateway and just need the company CA's root certificate.

Can acme2certifier revoke certificates?

Not with the two AD CS handlers. Revocation is still done in the Certification Authority console, and the CA's revocation list applies as usual.

Does it work for internal names like server01?

Yes, as long as the name is allowed in allowed_domainlist and the gateway can validate the challenge, i.e. resolve the name and reach port 80. For servers without a web server, dns-01 is the alternative.

How long are the certificates valid?

The template on the Windows CA decides, not acme2certifier. Shorter lifetimes such as 90 days are no longer a problem with automatic renewal and limit the damage if a key is lost.

Sources and documentation