Add per-host certificate type and DNS challenge support to App Gateway

Each application host now selects how its TLS certificate is issued:
self-signed, ACME HTTP challenge, or ACME DNS challenge using a stored
DNS credential. ACME modes fall back to the internal CA when issuance
fails, so hosts stay reachable with a browser warning instead of a TLS
error.

- Add DnsChallengeCredential model and provider registry (Cloudflare)
- Add certificate_type and dns_credential to ApplicationHost
- Sync WireGuard WebAdmin hosts from .env into the reserved application
- Export per-host TLS settings to tls.json, read only by Caddy
- Group hosts by certificate settings into separate Caddy site blocks
- Build Caddy with the Cloudflare DNS module using xcaddy
- Regenerate the Caddyfile without DNS challenge if validation fails
This commit is contained in:
Eduardo Silva
2026-11-17 15:59:40 -03:00
parent 433761e365
commit c5f215d9df
15 changed files with 624 additions and 35 deletions
@@ -0,0 +1,44 @@
# Generated by Django 5.2.19 on 2026-11-17 18:30
import uuid
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app_gateway', '0008_accesspolicy_display_name_applicationroute_display_name'),
]
operations = [
migrations.CreateModel(
name='DnsChallengeCredential',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.SlugField(max_length=64, unique=True)),
('display_name', models.CharField(blank=True, max_length=128)),
('provider', models.CharField(choices=[('cloudflare', 'Cloudflare')], max_length=32)),
('credentials', models.JSONField(default=dict)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
],
options={
'verbose_name': 'DNS Challenge Credential',
'verbose_name_plural': 'DNS Challenge Credentials',
'ordering': ['name'],
},
),
migrations.AddField(
model_name='applicationhost',
name='certificate_type',
field=models.CharField(choices=[('self_signed', 'Self-signed'), ('http_challenge', 'HTTP challenge'), ('dns_challenge', 'DNS challenge')], default='http_challenge', max_length=16),
),
migrations.AddField(
model_name='applicationhost',
name='dns_credential',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='hosts', to='app_gateway.dnschallengecredential'),
),
]
@@ -0,0 +1,25 @@
import ipaddress
from django.db import migrations
def set_self_signed_for_ip_hosts(apps, schema_editor):
ApplicationHost = apps.get_model('app_gateway', 'ApplicationHost')
for application_host in ApplicationHost.objects.all():
try:
ipaddress.ip_address(application_host.hostname.strip('[]'))
except ValueError:
continue
application_host.certificate_type = 'self_signed'
application_host.save(update_fields=['certificate_type'])
class Migration(migrations.Migration):
dependencies = [
('app_gateway', '0009_dns_challenge_credentials'),
]
operations = [
migrations.RunPython(set_self_signed_for_ip_hosts, migrations.RunPython.noop),
]