change app dns bind behavior
This commit is contained in:
1 parent
dd50a0d05e
commit
40a8ed23cd
17 files changed
+1440
-104
No files matched your search
@@ -10,29 +10,36 @@ broken config is rolled back before the reload.
|
||||
```
|
||||
$ proxdomain assign --vmid 101
|
||||
assign: ok
|
||||
[ok ] guest web01 (qemu 101 on pve)
|
||||
[ok ] address 10.0.0.5 (discovered)
|
||||
[ok ] domain web01.example.com
|
||||
[ok ] guest sftpgo (lxc 101 on vz)
|
||||
[ok ] address guest 10.3.0.22 (discovered)
|
||||
[ok ] dns-address 93.184.216.34 (detected via https://ipv4.icanhazip.com)
|
||||
[ok ] domain sftpgo.example.com
|
||||
[ok ] zone example.com (023e105f4ecef8ad9ca31a8372d0c353)
|
||||
[ok ] web-config created /etc/nginx/conf.d/proxdomain.d/web01.example.com.conf
|
||||
[warn] dns 10.0.0.5 is not a public address, so the Cloudflare proxy
|
||||
(orange cloud) was disabled; only the DNS record is created
|
||||
[done] dns created A web01.example.com -> 10.0.0.5 (proxied=no)
|
||||
[ok ] result web01.example.com -> http://10.0.0.5:80
|
||||
[done] web-config created /etc/caddy/conf.d/sftpgo.example.com.caddy
|
||||
[ok ] tls Caddy requests and renews a Let's Encrypt certificate for this site
|
||||
[done] dns created A sftpgo.example.com -> 93.184.216.34 (proxied=yes)
|
||||
[ok ] result sftpgo.example.com -> http://10.3.0.22:80 (published 93.184.216.34)
|
||||
```
|
||||
|
||||
## What it does
|
||||
|
||||
1. **Proxmox** — finds the guest (`--vmid` or `--name`), then resolves its IP from
|
||||
the QEMU guest agent, the LXC runtime interfaces, or the static `ip=` in the
|
||||
guest config (in that order).
|
||||
2. **Cloudflare** — discovers the zone by walking up from the FQDN, then creates
|
||||
guest config (in that order). This is the **proxy target**, not the DNS value.
|
||||
2. **Address** — `[dns] target = "host"` (the default) publishes the Proxmox
|
||||
host's public address, because the host runs the reverse proxy; the vhost
|
||||
still proxies to the guest's private IP. Set `dns.address` (or `dns.hostname`)
|
||||
to skip auto-detection, or `target = "guest"` when guests hold public IPs.
|
||||
3. **Cloudflare** — discovers the zone by walking up from the FQDN, then creates
|
||||
or patches the `A`/`AAAA` record. `proxied`, TTL and comment come from the
|
||||
config; private/loopback targets automatically get a grey cloud.
|
||||
3. **Web server** — renders one file per domain (`nginx`, `Caddy` or `Traefik`
|
||||
config; non-public targets automatically get a grey cloud.
|
||||
4. **Web server** — renders one file per domain (`nginx`, `Caddy` or `Traefik`
|
||||
file provider) into a managed directory, runs the config test, and reloads.
|
||||
If the test fails, the previous file is restored.
|
||||
4. **State** — records the assignment in `state.json` plus an append-only
|
||||
5. **TLS** — with `webserver.tls.mode = "letsencrypt"` the certificate is
|
||||
obtained automatically (certbot for nginx, Caddy's ACME issuer, Traefik's
|
||||
cert resolver) and renewed by the web server itself.
|
||||
6. **State** — records the assignment in `state.json` plus an append-only
|
||||
`audit.jsonl`, so `list`, `sync` and `remove` know what is managed.
|
||||
|
||||
The app never creates VMs and never installs a web server; it wires an existing
|
||||
@@ -87,6 +94,12 @@ for the guest-agent IP query. Put the token in the environment, not in the file:
|
||||
export PROXDOMAIN_PVE_TOKEN='00000000-0000-0000-0000-000000000000'
|
||||
```
|
||||
|
||||
`proxmox.token_secret_env` holds the **name** of that variable
|
||||
(`PROXDOMAIN_PVE_TOKEN`), not the secret. The secret goes in the variable, in
|
||||
`token_secret_file`, or in `token_secret`. Note that `VAR=value proxdomain ...`
|
||||
exports it for that one command, while `VAR=value && proxdomain ...` does not
|
||||
export it at all.
|
||||
|
||||
### Cloudflare API token
|
||||
|
||||
Create a token with **Zone → Zone:Read** and **Zone → DNS:Edit**, limited to the
|
||||
@@ -110,6 +123,28 @@ in [`config.example.toml`](config.example.toml).
|
||||
The config is read from `--config`, then `$PROXDOMAIN_CONFIG`, then
|
||||
`./proxdomain.toml`, then `/etc/proxdomain/config.toml`.
|
||||
|
||||
### DNS target
|
||||
|
||||
| `[dns] target` | Record points at | Use when |
|
||||
| --- | --- | --- |
|
||||
| `host` (default) | the Proxmox host's public address | guests sit on a private bridge and the host runs nginx/Caddy/Traefik |
|
||||
| `fixed` | `dns.address` verbatim | the public address is known and detection should never run |
|
||||
| `guest` | the guest's own address | every guest holds a public IP |
|
||||
|
||||
For `host`, the address is taken from `dns.address`, otherwise a DNS lookup of
|
||||
`dns.hostname`, otherwise an HTTPS detection endpoint (`detect_url_v4` /
|
||||
`detect_url_v6`). Pinning the address is recommended for a stable host:
|
||||
|
||||
```toml
|
||||
[dns]
|
||||
target = "host"
|
||||
address = "93.184.216.34" # optional; skips auto-detection
|
||||
```
|
||||
|
||||
`proxdomain doctor` prints the resolved target, and `assign --address <ip>`
|
||||
overrides it for a single command. After changing `target` (or the host's
|
||||
address), run `proxdomain sync` to re-point existing records.
|
||||
|
||||
Then create the managed directory and the include line:
|
||||
|
||||
```bash
|
||||
@@ -152,6 +187,9 @@ proxdomain assign --vmid 101 --subdomain app.example.net
|
||||
# guest IP discovery is wrong? override it, or force the orange cloud
|
||||
proxdomain assign --vmid 101 --ip 10.0.0.5 --proxied
|
||||
|
||||
# publish a one-off address instead of the configured host address
|
||||
proxdomain assign --vmid 101 --address 93.184.216.34
|
||||
|
||||
# after changing template/port/TLS settings, re-apply every site
|
||||
proxdomain sync --dry-run
|
||||
proxdomain sync
|
||||
@@ -207,21 +245,53 @@ Or in cron: `*/2 * * * * /usr/local/bin/proxdomain watch --once --auto-assign`.
|
||||
|
||||
## TLS
|
||||
|
||||
Set one section and every managed domain gets HTTPS automatically:
|
||||
|
||||
```toml
|
||||
[webserver.tls]
|
||||
mode = "letsencrypt"
|
||||
email = "ops@example.com"
|
||||
```
|
||||
|
||||
| `webserver.tls.mode` | What is written | When to use |
|
||||
| --- | --- | --- |
|
||||
| `none` (default) | Proxy on `:80` | Cloudflare orange cloud terminates TLS, or plain HTTP on the LAN |
|
||||
| `letsencrypt` | Automatic Let's Encrypt certificate (per web server, see below) | The normal choice for a public domain |
|
||||
| `files` | `:80` redirect + `:443` vhost with `cert_dir/<fqdn>/{fullchain,privkey}.pem` | Certificates already exist (wildcard, acme.sh, another certbot) |
|
||||
| `certbot` (nginx only) | Temporary HTTP vhost → `certbot certonly --webroot` → TLS vhost | Let the app obtain the certificate |
|
||||
| `certbot` | Alias of `letsencrypt` for nginx, kept for older configs | — |
|
||||
|
||||
For `certbot`, the domain must resolve to the host and port 80 must be reachable
|
||||
from the internet. Keep the Cloudflare record grey-clouded until the certificate
|
||||
is issued, otherwise Cloudflare's edge answers the challenge. Caddy manages its
|
||||
own certificates, so `none`/`files` are the only meaningful modes there; for
|
||||
Traefik set `webserver.cert_resolver`.
|
||||
How each web server gets the certificate:
|
||||
|
||||
* **nginx** — for a domain with no certificate, proxdomain first activates an
|
||||
HTTP-only vhost, runs `certbot certonly --webroot --keep-until-expiring`
|
||||
against `webserver.tls.webroot`, then writes the `:443` vhost. The renewal hook
|
||||
(`--deploy-hook`, default `webserver.reload_command`) makes certbot's systemd
|
||||
timer reload nginx after each renewal. Install certbot first
|
||||
(`apt install certbot`); `proxdomain doctor` reports whether it is present.
|
||||
* **Caddy** — the site block pins `tls { issuer acme { email … } }`, so Caddy
|
||||
obtains and renews the certificate itself and never falls back to ZeroSSL.
|
||||
* **Traefik** — the router keeps `certResolver` (`webserver.cert_resolver`),
|
||||
which must be defined in the static config with an ACME challenge.
|
||||
|
||||
`acme_ca` switches the ACME directory (staging, Pebble, Buypass); leave it empty
|
||||
for Let's Encrypt production. `renew_hook` overrides the post-renewal command.
|
||||
|
||||
`proxdomain assign` prints a `tls` line, `proxdomain list` has a `TLS` column, and
|
||||
`proxdomain doctor` checks the mode plus the certificate of every managed site.
|
||||
|
||||
### Ports, Cloudflare and the ACME challenge
|
||||
|
||||
HTTP-01 needs the name to point at the host and port 80 to answer. proxdomain
|
||||
publishes the record **before** requesting a certificate, so a fresh `assign`
|
||||
works without manual DNS steps. An orange-clouded record is fine for HTTP-01
|
||||
because Cloudflare forwards `/.well-known/acme-challenge` over HTTP; if issuance
|
||||
still fails, grey-cloud the record for the first run and re-enable it afterwards.
|
||||
|
||||
With a proxied (orange cloud) record, Cloudflare connects to the origin on the
|
||||
standard HTTP/HTTPS ports. Publish the reverse proxy on 80/443, not on an
|
||||
arbitrary high port, or disable proxying for that record.
|
||||
arbitrary high port, or disable proxying for that record. If Caddy or another
|
||||
origin serves a self-signed certificate, use Cloudflare's **Full** mode rather
|
||||
than **Full (strict)** until the Let's Encrypt certificate is in place.
|
||||
|
||||
## How an assignment is ordered
|
||||
|
||||
@@ -229,6 +299,13 @@ Web config first, DNS second: the vhost is valid and loaded before the name
|
||||
starts resolving, so a failure never leaves a public name pointing at an
|
||||
unconfigured proxy.
|
||||
|
||||
The one exception is a domain that needs an ACME certificate: then the DNS
|
||||
record is created first, because ACME must resolve the name, and the TLS vhost is
|
||||
written only after the certificate exists (for nginx, after certbot succeeds;
|
||||
Caddy always goes DNS-first because it starts issuing as soon as it reloads). If
|
||||
nginx issuance fails, the temporary HTTP vhost is removed and the error explains
|
||||
what to check; re-running `assign` retries (it is idempotent).
|
||||
|
||||
* Config test fails → the new file is removed (or the old one restored) and the
|
||||
error is reported; DNS is untouched.
|
||||
* Reload fails after a valid test → the config is kept (it is valid) and the
|
||||
@@ -258,9 +335,14 @@ records every config/DNS/remove action with a UTC timestamp.
|
||||
| --- | --- |
|
||||
| `no usable IP address found` | Install and start `qemu-guest-agent` in the VM, set a static `ip=` in the guest/cloud-init config, or pass `--ip`. |
|
||||
| `401/403` from Proxmox | Token ACL or `--privsep`. Grant `VM.Audit VM.Monitor` on `/` (or at least `/vms`). |
|
||||
| `token_secret_env ... must be the name of an environment variable` | The secret was pasted into the setting that should hold the variable name. Set `token_secret_env = "PROXDOMAIN_PVE_TOKEN"` and export the secret, or use `token_secret_file` / `token_secret`. |
|
||||
| Secret reported as empty although it was set inline | `VAR=value && proxdomain ...` sets a variable and then runs an unrelated command. Use `export VAR=value` first, or `VAR=value proxdomain ...`. |
|
||||
| `no Cloudflare zone found` | `general.base_domain` must be inside the zone, and the token must include that zone under Zone Resources. |
|
||||
| `cannot determine the Proxmox host's public address` | Detection endpoints were unreachable or returned non-public addresses. Set `dns.address` (recommended) or `dns.hostname`. |
|
||||
| `401/403` from Cloudflare | Token needs `Zone:Read` + `DNS:Edit`; check it was not restricted to another account. |
|
||||
| `web server configuration test failed` | The message includes `nginx -t` output. The file was rolled back; nothing was reloaded. |
|
||||
| `certbot failed for <domain>` | The name must resolve to this host and port 80 must be reachable. Check the A record, the firewall, and that nothing else answers `/.well-known/acme-challenge`. Rate limits need `acme_ca` pointed at staging while testing. |
|
||||
| Site shows a certificate warning | The `:443` vhost was written before a certificate existed (mode `files`). Issue the certificate, or switch to mode `letsencrypt`. |
|
||||
| `reloading the web server failed` | The config is valid and written. Run the reload command from `webserver.reload_command` manually. |
|
||||
| `certbot failed` | Port 80 unreachable, DNS not pointing at the host yet, or the record is orange-clouded. Use grey cloud until issuance succeeds. |
|
||||
| Cloudflare 522/521 | The origin address or port is unreachable from Cloudflare. Check the guest firewall and that the proxy listens on 80/443. |
|
||||
@@ -273,6 +355,7 @@ records every config/DNS/remove action with a UTC timestamp.
|
||||
proxdomain/
|
||||
cli.py argparse commands and output
|
||||
config.py TOML parsing, per-kind defaults, secret resolution
|
||||
addressing.py host/fixed/guest resolution for the published DNS address
|
||||
http.py urllib JSON client with retries and an injectable transport
|
||||
proxmox.py guest inventory, tag parsing, IP resolution
|
||||
cloudflare.py zone discovery, A/AAAA upsert, delete
|
||||
@@ -299,6 +382,11 @@ Proxmox host or Cloudflare account.
|
||||
## Limits
|
||||
|
||||
* One `A`/`AAAA` record per name; no CNAME, wildcard or Cloudflare Tunnel setup.
|
||||
* Host-address detection requires outbound HTTPS; pin `dns.address` on a host
|
||||
where outbound traffic is filtered or NATed behind a different address.
|
||||
* Automatic certificates cover the FQDN only: no wildcard, no DNS-01 (so a host
|
||||
whose port 80 is blocked cannot use `tls.mode = "letsencrypt"` with nginx),
|
||||
and `remove` leaves the Let's Encrypt certificate on disk for re-use.
|
||||
* The record type follows `proxmox.ip_preference`; a stale record of the other
|
||||
type is left alone and reported in `list` as managed separately.
|
||||
* Removal only knows about assignments in `state.json`; deleting the state file
|
||||
|
||||
Reference in new issue
Block a user