Skip to content

Per-tenant SSL automation on PaaS — wildcard vs per-domain certificate orchestration

You host 60 customer domains on a shared PaaS environment. Half are vanity domains (`acme.yourapp.com`) and half are customer-owned (`shop.acme.com`). The cert strategy that works for one is wrong for the other.

You host 60 customer domains on a shared PaaS environment. Half are subdomains under your platform name (acme.yourapp.com, widgets.yourapp.com). Half are customer-owned domains (shop.acme.com, store.widgets.io). For the subdomains, a single wildcard certificate covers everything. For the customer-owned domains, you need a per-domain certificate that the customer has pointed their DNS at, issued only after their CNAME or A record resolves to your IP. Doing both well at scale is the difference between a self-serve onboarding flow and a Slack channel full of “my cert is broken” tickets.

What’s happening

Let’s Encrypt has two challenge types that matter for multi-tenant PaaS. The HTTP-01 challenge proves you control a domain by serving a file at http://<domain>/.well-known/acme-challenge/<token>. It works only after the customer has pointed DNS at you, requires plain HTTP-80 to be reachable, and cannot issue wildcard certs. The DNS-01 challenge proves you control a domain by creating a TXT record at _acme-challenge.<domain>. It can issue wildcards (*.yourapp.com), works before HTTP routing is wired up, and requires API access to the DNS provider — which is fine for domains you own and impossible for customer-owned domains.

The pragmatic split:

  • Vanity / platform subdomains (*.yourapp.com): one DNS-01 wildcard certificate, automated against your own DNS provider, renewed monthly, served by the LB for every tenant subdomain under it. One renewal, 60 tenants covered.
  • Customer-owned domains (shop.acme.com): per-domain HTTP-01 certificate, issued the moment their CNAME resolves to your edge, renewed automatically. One renewal per customer domain.

Three failure modes show up at scale:

  1. Renewal rate-limit. Let’s Encrypt enforces 50 certs per registered domain per week. Wildcards count as one cert but cover many subdomains. If you mistakenly issue per-subdomain certs against the wildcard, you’ll hit the limit at customer 51.
  2. Issuing before DNS resolves. A customer CNAMEs shop.acme.com to your edge, you immediately attempt issuance, Let’s Encrypt cache says no AAAA/A yet, you get rate-limited on the failures. Wait for DNS to resolve before issuing.
  3. OCSP / chain rotation. ISRG Root X1 chain changed in late 2024 and again in 2025. If your LB serves a stale chain, modern clients reject the connection. Reload the LB after every renewal, not just on cert change.

How to verify

Confirm what certs the LB is actually serving for each tenant domain:

# What cert does this domain resolve to?
echo | openssl s_client -servername shop.acme.com \
  -connect shop.acme.com:443 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates -ext subjectAltName

# Bulk check across all tenant domains
while read domain; do
  expiry=$(echo | openssl s_client -servername "$domain" \
    -connect "${domain}:443" -timeout 5 2>/dev/null \
    | openssl x509 -noout -enddate 2>/dev/null \
    | cut -d= -f2)
  echo "$domain | $expiry"
done < /etc/tenants.txt

Check how close any domain is to renewal cliff (anything within 14 days needs attention now, anything within 7 is a Sev-2):

# Days until expiry, sorted
while read domain; do
  expiry=$(echo | openssl s_client -servername "$domain" \
    -connect "${domain}:443" -timeout 5 2>/dev/null \
    | openssl x509 -noout -enddate 2>/dev/null | cut -d= -f2)
  if [[ -n "$expiry" ]]; then
    days=$(( ($(date -d "$expiry" +%s) - $(date +%s)) / 86400 ))
    echo "${days} ${domain}"
  fi
done < /etc/tenants.txt | sort -n | head

Confirm DNS-01 prerequisites for the wildcard cert — your wildcard renewer needs API credentials with TXT-record write rights on the platform zone:

# Smoke test the DNS API used by certbot's DNS plugin
dig @ns1.your-dns.example.com TXT _acme-challenge.yourapp.com

The fix

A two-track orchestrator that handles both patterns from one place. Track 1 is the wildcard, refreshed monthly via DNS-01. Track 2 is per-customer-domain, issued via HTTP-01 the moment their domain resolves.

Track 1 — wildcard renewer, runs weekly:

#!/usr/bin/env bash
set -euo pipefail

CERT_NAME="yourapp-wildcard"
DOMAINS="*.yourapp.com,yourapp.com"
DNS_PLUGIN="cloudflare"  # or route53, ovh, etc.

certbot certonly \
  --non-interactive --agree-tos \
  -m ops@yourapp.com \
  --dns-${DNS_PLUGIN} \
  --dns-${DNS_PLUGIN}-credentials /etc/letsencrypt/${DNS_PLUGIN}.ini \
  --dns-${DNS_PLUGIN}-propagation-seconds 30 \
  --cert-name "${CERT_NAME}" \
  -d "${DOMAINS}"

# Push to the LB via Jelastic API
JEM_USER="${JEM_USER:?}"
JEM_PASS="${JEM_PASS:?}"
JEM_API="${JEM_API:-https://app.your-paas.example.com}"

SESSION=$(curl -fsS -X POST \
  "${JEM_API}/1.0/users/authentication/rest/signin" \
  -d "login=${JEM_USER}&password=${JEM_PASS}" \
  | jq -r .session)

CERT=$(cat /etc/letsencrypt/live/${CERT_NAME}/fullchain.pem | jq -Rs .)
KEY=$(cat /etc/letsencrypt/live/${CERT_NAME}/privkey.pem | jq -Rs .)

curl -fsS -X POST \
  "${JEM_API}/1.0/environment/control/rest/bindsslcert" \
  -d "session=${SESSION}" \
  -d "envName=shared-prod" \
  --data-urlencode "cert_key=${KEY}" \
  --data-urlencode "cert=${CERT}"

Track 2 — per-customer-domain issuer, triggered by webhook the moment the customer marks DNS as configured in your customer portal:

#!/usr/bin/env bash
set -euo pipefail

TENANT_SLUG="${1:?}"
CUSTOMER_DOMAIN="${2:?}"
ENV_NAME="${TENANT_SLUG}-prod"
PUBLIC_IP="${LB_PUBLIC_IP:?}"

# 1. Confirm DNS resolves to our edge — back off otherwise
resolved=$(dig +short "${CUSTOMER_DOMAIN}" @1.1.1.1 | head -1)
if [[ "$resolved" != "$PUBLIC_IP" ]]; then
  # Could be CNAME — follow it
  cname=$(dig +short "${CUSTOMER_DOMAIN}" CNAME @1.1.1.1 | head -1)
  if [[ -z "$cname" || "$cname" != "edge.yourapp.com." ]]; then
    echo "DNS not pointing at us yet (got: $resolved $cname) — retry later"
    exit 75  # EX_TEMPFAIL — let the queue retry
  fi
fi

# 2. Issue cert via HTTP-01
certbot certonly \
  --non-interactive --agree-tos \
  -m ops@yourapp.com \
  --webroot -w /var/www/acme-webroot \
  --cert-name "${TENANT_SLUG}-${CUSTOMER_DOMAIN}" \
  -d "${CUSTOMER_DOMAIN}"

# 3. Push to LB as SNI cert for that hostname
CERT=$(cat /etc/letsencrypt/live/${TENANT_SLUG}-${CUSTOMER_DOMAIN}/fullchain.pem | jq -Rs .)
KEY=$(cat /etc/letsencrypt/live/${TENANT_SLUG}-${CUSTOMER_DOMAIN}/privkey.pem | jq -Rs .)

curl -fsS -X POST \
  "${JEM_API}/1.0/environment/control/rest/addsslcert" \
  -d "session=${SESSION}" \
  -d "envName=${ENV_NAME}" \
  -d "extdomains=${CUSTOMER_DOMAIN}" \
  --data-urlencode "cert_key=${KEY}" \
  --data-urlencode "cert=${CERT}"

echo "Issued + bound cert for ${CUSTOMER_DOMAIN}"

Terraform for the wildcard renewer as code (the per-domain issuer is too dynamic to live in TF):

resource "jelastic_environment" "shared_prod" {
  env_name = "shared-prod"
  # ... nodes ...
}

resource "jelastic_ssl_certificate" "wildcard" {
  env_name    = jelastic_environment.shared_prod.env_name
  cert_pem    = file("/etc/letsencrypt/live/yourapp-wildcard/fullchain.pem")
  key_pem     = file("/etc/letsencrypt/live/yourapp-wildcard/privkey.pem")
  ext_domains = ["yourapp.com", "*.yourapp.com"]
}

Two operational rules: (1) renew certs on a 30-day cycle, not 60 — gives you a week to react to a broken DNS provider before the customer notices, (2) ship a daily “domains expiring in less than 14 days” report to the team channel, gated by a slug allowlist so you don’t get paged for domains a customer offboarded but forgot to remove DNS for.

Stack Harbor operates per-tenant TLS at scale on managed PaaS for agencies and SaaS hosts as part of environment management, including the renewal monitoring most teams forget to build. If you’re an agency rolling out customer-domain SSL on tenant subdomains, our agency partner program automates the whole flow — book a TLS onboarding review.