mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-11-21 04:23:15 +01:00
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:
@@ -1,7 +1,57 @@
|
||||
import ipaddress
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
INTERNAL_WEBADMIN_HOSTNAME = 'wireguard-webadmin'
|
||||
|
||||
|
||||
def is_ip_address(hostname):
|
||||
try:
|
||||
ipaddress.ip_address(hostname.strip('[]'))
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_webadmin_hostnames():
|
||||
# Mirrors the host selection made by containers/caddy/export_wireguard_webadmin_config.py
|
||||
hostnames = []
|
||||
for hostname in settings.ALLOWED_HOSTS:
|
||||
hostname = hostname.strip().lower()
|
||||
if not hostname or hostname == INTERNAL_WEBADMIN_HOSTNAME or hostname in hostnames:
|
||||
continue
|
||||
if is_ip_address(hostname) or hostname == 'localhost' or hostname.endswith('.localhost'):
|
||||
continue
|
||||
hostnames.append(hostname)
|
||||
return hostnames
|
||||
|
||||
|
||||
def sync_webadmin_hosts(application):
|
||||
from app_gateway.models import ApplicationHost
|
||||
|
||||
webadmin_hostnames = get_webadmin_hostnames()
|
||||
|
||||
removed_hosts = application.hosts.exclude(hostname__in=webadmin_hostnames)
|
||||
for application_host in removed_hosts:
|
||||
logger.info("Removed WireGuard WebAdmin host: %s", application_host.hostname)
|
||||
removed_hosts.delete()
|
||||
|
||||
for hostname in webadmin_hostnames:
|
||||
existing_host = ApplicationHost.objects.filter(hostname=hostname).select_related('application').first()
|
||||
if existing_host:
|
||||
if existing_host.application_id != application.id:
|
||||
logger.warning(
|
||||
"Hostname '%s' is used by WireGuard WebAdmin but is also assigned to application '%s'. "
|
||||
"Remove it from that application to manage its certificate settings.",
|
||||
hostname, existing_host.application
|
||||
)
|
||||
continue
|
||||
ApplicationHost.objects.create(application=application, hostname=hostname)
|
||||
logger.info("Added WireGuard WebAdmin host: %s", hostname)
|
||||
|
||||
|
||||
def create_default_entries(**kwargs):
|
||||
from app_gateway.models import AccessPolicy, Application, ApplicationPolicy, RESERVED_APP_NAME
|
||||
@@ -26,3 +76,5 @@ def create_default_entries(**kwargs):
|
||||
if not ApplicationPolicy.objects.filter(application=app).exists():
|
||||
ApplicationPolicy.objects.create(application=app, default_policy=public_policy)
|
||||
logger.info("Assigned default policy 'Public' to application '%s'", RESERVED_APP_NAME)
|
||||
|
||||
sync_webadmin_hosts(app)
|
||||
|
||||
Reference in New Issue
Block a user