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
@@ -19,6 +19,12 @@
{% trans 'Access Policies' %}
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if active_tab == 'dns_credentials' %}active{% endif %}"
href="{% url 'app_gateway_list' %}?tab=dns_credentials" role="tab">
{% trans 'DNS Credentials' %}
</a>
</li>
</ul>
<div class="tab-content mt-4">
@@ -108,6 +114,7 @@
<tr>
<th>{% trans 'Hostname' %}</th>
<th>{% trans 'Application' %}</th>
<th>{% trans 'Certificate' %}</th>
</tr>
</thead>
<tbody>
@@ -119,6 +126,10 @@
{{ host.application }}
</a>
</td>
<td>
{{ host.get_certificate_type_display }}
{% if host.dns_credential %}<small class="text-muted">({{ host.dns_credential }})</small>{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
@@ -178,6 +189,51 @@
</div>
{% endif %}
{% elif active_tab == 'dns_credentials' %}
<div class="mb-3">
<a href="{% url 'manage_dns_credential' %}" class="btn btn-outline-primary btn-sm">
<i class="fas fa-plus"></i> {% trans 'Add DNS Credential' %}
</a>
</div>
{% if dns_credentials %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>{% trans 'Name' %}</th>
<th>{% trans 'Provider' %}</th>
<th>{% trans 'Hosts' %}</th>
<th>{% trans 'Actions' %}</th>
</tr>
</thead>
<tbody>
{% for dns_credential in dns_credentials %}
<tr>
<td>{{ dns_credential.display_name|default:dns_credential.name }}</td>
<td>{{ dns_credential.get_provider_display }}</td>
<td>{{ dns_credential.hosts.count }}</td>
<td style="width: 15%">
<a href="{% url 'manage_dns_credential' %}?uuid={{ dns_credential.uuid }}"
class="btn btn-sm btn-info" title="{% trans 'Edit' %}">
<i class="fas fa-edit"></i>
</a>
<a href="{% url 'delete_dns_credential' %}?uuid={{ dns_credential.uuid }}"
class="btn btn-sm btn-danger" title="{% trans 'Delete' %}">
<i class="fas fa-trash"></i>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="alert alert-info">
{% trans 'No DNS Credentials found.' %}
</div>
{% endif %}
{% endif %}
</div>
@@ -67,28 +67,28 @@
{% endif %}
</div>
{% if hosts or django_hostnames %}
{% if hosts %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>{% trans 'Hostname' %}</th>
<th>{% trans 'Certificate' %}</th>
<th>{% trans 'Actions' %}</th>
</tr>
</thead>
<tbody>
{% for hostname in django_hostnames %}
<tr class="text-muted">
<td>{{ hostname }}</td>
<td style="width: 15%"></td>
</tr>
{% endfor %}
{% for host in hosts %}
<tr>
<td>{{ host.hostname }}</td>
<td>
{{ host.get_certificate_type_display }}
{% if host.dns_credential %}<small class="text-muted">({{ host.dns_credential }})</small>{% endif %}
</td>
<td style="width: 15%">
{% if is_reserved %}
<a class="btn btn-sm btn-secondary disabled" aria-disabled="true" tabindex="-1" title="{% trans 'This application cannot be modified' %}">
<a href="{% url 'manage_application_host' %}?uuid={{ host.uuid }}"
class="btn btn-sm btn-info" title="{% trans 'Edit' %}">
<i class="fas fa-edit"></i>
</a>
<a class="btn btn-sm btn-secondary disabled" aria-disabled="true" tabindex="-1" title="{% trans 'This application cannot be modified' %}">
@@ -0,0 +1,53 @@
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% load i18n %}
{% block content %}
<div class='row'>
<div class='col-lg-6'>
<div class="card card-primary card-outline">
<div class="card-header">
<h3 class="card-title">{{ page_title }}</h3>
</div>
<div class="card-body row">
<div class="col-lg-12">
{% crispy form %}
</div>
</div>
</div>
</div>
<div class='col-lg-6'>
<div class="card card-primary card-outline">
<div class="card-body row">
<div class="col-lg-12">
<h5>{% trans 'DNS Credential' %}</h5>
<p>{% trans 'Credentials used to create the DNS records required by the ACME DNS challenge.' %}</p>
<p>{% blocktrans trimmed %}
Use a token restricted to editing DNS records of the zones you need. For Cloudflare, create an
API Token with the <strong>Zone / DNS / Edit</strong> permission.
{% endblocktrans %}</p>
<p>{% trans 'Secret values are never displayed after saving. Leave them blank when editing to keep the current value.' %}</p>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block custom_page_scripts %}
<script>
$(document).ready(function () {
function toggleProviderFields() {
var provider = $('#id_provider').val();
$('.provider-group').hide();
if (provider) {
$('.provider-' + provider).show();
}
}
$('#id_provider').change(toggleProviderFields);
toggleProviderFields();
});
</script>
{% endblock %}