remove standalone certbot fallback, fail on missing certs
This commit is contained in:
+5
-12
@@ -91,8 +91,8 @@ client sends a command string (e.g., `deploy-example.com`), and `deploy.sh`
|
|||||||
parses it to determine the action:
|
parses it to determine the action:
|
||||||
|
|
||||||
- `deploy-<app>` — deploy a specific app
|
- `deploy-<app>` — deploy a specific app
|
||||||
- `deploy-nginx` — deploy nginx (with cert handling)
|
- `deploy-nginx` — deploy nginx (fails if certs are missing)
|
||||||
- `cert-<domain>` — issue a cert only
|
- `cert-<domain>` — issue a cert only (via `certbot --webroot`, zero downtime)
|
||||||
- `provision` — run `configure.sh`
|
- `provision` — run `configure.sh`
|
||||||
|
|
||||||
## SSL certificate handling
|
## SSL certificate handling
|
||||||
@@ -101,16 +101,9 @@ Cert names are derived from nginx conf filenames (e.g., `example.com.conf` →
|
|||||||
cert `example.com`). All `server_name` values in the conf are included in the
|
cert `example.com`). All `server_name` values in the conf are included in the
|
||||||
cert as SANs.
|
cert as SANs.
|
||||||
|
|
||||||
**New domain (nginx not yet running):**
|
**New domain:** issue cert before deploying nginx config:
|
||||||
1. `deploy.sh` detects missing cert files
|
1. Run `app.sh cert <domain>` (uses `certbot --webroot`, zero downtime)
|
||||||
2. Stops nginx temporarily
|
2. Deploy nginx config — `deploy.sh` verifies certs exist, fails if missing
|
||||||
3. Issues cert via `certbot --standalone`
|
|
||||||
4. Starts nginx
|
|
||||||
5. On error, cleans up the temp conf file (trap)
|
|
||||||
|
|
||||||
**New domain (nginx already running):**
|
|
||||||
1. Issues cert via `certbot --webroot` using the ACME challenge directory
|
|
||||||
2. Zero downtime
|
|
||||||
|
|
||||||
**Renewal:** certbot timer/cron runs daily, deploy hook reloads nginx.
|
**Renewal:** certbot timer/cron runs daily, deploy hook reloads nginx.
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ nodes.
|
|||||||
scripts/
|
scripts/
|
||||||
bootstrap.sh # First-time server setup (manual, uses Bitwarden)
|
bootstrap.sh # First-time server setup (manual, uses Bitwarden)
|
||||||
configure.sh # Idempotent server config (CI-safe)
|
configure.sh # Idempotent server config (CI-safe)
|
||||||
deploy.sh # Deploy + cert issuance + provision (called via SSH)
|
deploy.sh # Deploy + provision (called via SSH)
|
||||||
tools/
|
tools/
|
||||||
new-app.sh # Add a new static site (run from dev machine)
|
new-app.sh # Add a new static site (run from dev machine)
|
||||||
new-service.sh # Add a new Docker service (run from dev machine)
|
new-service.sh # Add a new Docker service (run from dev machine)
|
||||||
|
|||||||
+4
-22
@@ -92,33 +92,15 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$APP" = "nginx" ]; then
|
if [ "$APP" = "nginx" ]; then
|
||||||
# Issue certs for any new domains (brief nginx downtime while certbot binds port 80)
|
# Fail loudly if any certs are missing — issue them first with: app.sh cert <domain>
|
||||||
missing_certs=false
|
|
||||||
for conf in /opt/hantim/docker/nginx/conf.d/*.*.conf; do
|
for conf in /opt/hantim/docker/nginx/conf.d/*.*.conf; do
|
||||||
cert_name=$(basename "$conf" .conf)
|
cert_name=$(basename "$conf" .conf)
|
||||||
if [ ! -d "/etc/letsencrypt/live/$cert_name" ]; then
|
if [ ! -d "/etc/letsencrypt/live/$cert_name" ]; then
|
||||||
missing_certs=true
|
echo "ERROR: Missing certificate for $cert_name"
|
||||||
break
|
echo " Run: app.sh cert $cert_name"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ "$missing_certs" = true ]; then
|
|
||||||
docker stop nginx 2>/dev/null || true
|
|
||||||
trap 'docker start nginx 2>/dev/null || true' EXIT
|
|
||||||
for conf in /opt/hantim/docker/nginx/conf.d/*.*.conf; do
|
|
||||||
cert_name=$(basename "$conf" .conf)
|
|
||||||
if [ ! -d "/etc/letsencrypt/live/$cert_name" ]; then
|
|
||||||
domains=$(grep -oP 'server_name\s+\K[^;]+' "$conf" | tr ' ' '\n' | sort -u)
|
|
||||||
domain_args=""
|
|
||||||
for d in $domains; do
|
|
||||||
domain_args="$domain_args -d $d"
|
|
||||||
done
|
|
||||||
echo "Issuing cert for $cert_name..."
|
|
||||||
certbot certonly --standalone --non-interactive --agree-tos \
|
|
||||||
--register-unsafely-without-email --cert-name "$cert_name" $domain_args
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
trap - EXIT
|
|
||||||
fi
|
|
||||||
# Test config before applying — a bad config would take down all sites
|
# Test config before applying — a bad config would take down all sites
|
||||||
docker compose run --rm -T nginx nginx -t
|
docker compose run --rm -T nginx nginx -t
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user