feature: HTTPS is always on, for wan.local_fqdn or, without it, the host name and its mDNS name, optionally also for the server's addresses, and the redirect to HTTPS covers the status page by name.
Release / release (push) Successful in 23s
Release / release (push) Successful in 23s
This commit is contained in:
1 parent
7efacfa3bb
commit
64c3ae4c36
18 files changed
+317
-187
No files matched your search
@@ -12,6 +12,7 @@ import os
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -79,7 +80,7 @@ SCHEMA = {
|
||||
'status_content': 'basic', 'shell': False, 'shell_idle_minutes': 15, 'shell_auth_timeout': 15,
|
||||
'log_files': []},
|
||||
'ssh': {'ldap_login': False},
|
||||
'https': {'enabled': True, 'email': '', 'web_port': 7444, 'manager_port': 7443,
|
||||
'https': {'email': '', 'web_port': 7444, 'manager_port': 7443, 'ip_sans': False,
|
||||
'disable_auto_redirect': False, 'acme_staging': False, 'certificate': 'self-signed', 'self_signed_days': 365,
|
||||
'acme_provider': 'letsencrypt', 'acme_url': '', 'acme_eab_key_id': '', 'acme_eab_mac_key': '',
|
||||
'zerossl_api_key': ''},
|
||||
@@ -172,8 +173,8 @@ UPLOAD_MAX_MB = 10240
|
||||
|
||||
#: Settings that no longer exist, section -> options, left out when the file is read so that a file of an earlier
|
||||
#: version loads: the name server is wan.local_fqdn, a site chooses the address of its records, and the CA certificates
|
||||
#: and CRLs are always published.
|
||||
RETIRED = {'dns': ('nameserver', 'addresses'), 'pki': ('publish',)}
|
||||
#: and CRLs are always published, and HTTPS is always on.
|
||||
RETIRED = {'dns': ('nameserver', 'addresses'), 'pki': ('publish',), 'https': ('enabled',)}
|
||||
|
||||
#: The shortest and the longest dns.ttl, in seconds.
|
||||
DNS_TTL_RANGE = (60, 86400)
|
||||
@@ -684,19 +685,16 @@ def validate(cfg):
|
||||
for option in ('email', 'acme_url', 'acme_eab_key_id', 'acme_eab_mac_key', 'zerossl_api_key'):
|
||||
if any(character.isspace() or character in '{}"' for character in _get(cfg, 'https', option)):
|
||||
raise ConfigError(f'https.{option} must not hold spaces, braces or quotes')
|
||||
if _get(cfg, 'https', 'certificate') == 'acme' and not _get(cfg, 'wan', 'local_fqdn'):
|
||||
raise ConfigError('https.certificate: an ACME CA issues the certificate of wan.local_fqdn, which is not set')
|
||||
|
||||
if _get(cfg, 'oidc', 'enabled') and not (_get(cfg, 'web', 'enabled') and _get(cfg, 'https', 'enabled')
|
||||
and _get(cfg, 'wan', 'local_fqdn')):
|
||||
if _get(cfg, 'oidc', 'enabled') and not _get(cfg, 'web', 'enabled'):
|
||||
raise ConfigError('oidc.enabled: the OpenID Provider is the web service served by Caddy at '
|
||||
'https://<wan.local_fqdn>:<https.web_port>, which needs web.enabled, https.enabled and '
|
||||
'wan.local_fqdn')
|
||||
'https://<HTTPS name>:<https.web_port>, which needs web.enabled')
|
||||
|
||||
upload_max = _get(cfg, 'sites', 'upload_max_mb')
|
||||
if not 1 <= upload_max <= UPLOAD_MAX_MB:
|
||||
raise ConfigError(f'sites.upload_max_mb: {upload_max} is not between 1 and {UPLOAD_MAX_MB}')
|
||||
if _get(cfg, 'sites', 'webdav') and not (_get(cfg, 'https', 'enabled') and _get(cfg, 'wan', 'local_fqdn')):
|
||||
raise ConfigError('sites.webdav: WebDAV is served by Caddy at https://<wan.local_fqdn>:<sites.webdav_port>, '
|
||||
'which needs https.enabled and wan.local_fqdn')
|
||||
|
||||
_check_address(_get(cfg, 'wan', 'public_address'), 'wan.public_address')
|
||||
dns = cfg['dns']
|
||||
@@ -805,8 +803,6 @@ def validate(cfg):
|
||||
raise ConfigError(f'{prefix}.templates: {template!r} is not a template')
|
||||
if template in ROUTER_TEMPLATES:
|
||||
raise ConfigError(f'{prefix}.templates: {template} is issued by the P2S CA only')
|
||||
if authority['acme'] and not _get(cfg, 'https', 'enabled'):
|
||||
raise ConfigError(f'{prefix}.acme: the ACME server is Caddy\'s, which needs https.enabled')
|
||||
|
||||
taken = {web_port: 'web.port', ACME_HTTP_PORT: 'the HTTP challenge',
|
||||
https_ports[0]: 'https.web_port', https_ports[1]: 'https.manager_port'}
|
||||
@@ -898,9 +894,7 @@ def validate(cfg):
|
||||
f'docker.exposed_ports: {item!r} is not a port or a port range')
|
||||
weight += 2 if ':' in item else 1
|
||||
first, _, last = item.partition(':')
|
||||
caddy_ports = (web_port, manager_port(), _get(cfg, 'metrics', 'port'),
|
||||
*((ACME_HTTP_PORT, *https_ports)
|
||||
if _get(cfg, 'https', 'enabled') else ()))
|
||||
caddy_ports = (web_port, manager_port(), _get(cfg, 'metrics', 'port'), ACME_HTTP_PORT, *https_ports)
|
||||
for port in caddy_ports:
|
||||
if int(first) <= port <= int(last or first):
|
||||
raise ConfigError(f'docker.exposed_ports: {item!r} takes port {port}, which Caddy serves')
|
||||
@@ -973,9 +967,10 @@ def manager_listen():
|
||||
|
||||
|
||||
def oidc_issuer(cfg):
|
||||
"""The issuer of the OpenID Provider: the web service's HTTPS site, without the port when it is HTTPS_DEFAULT_PORT."""
|
||||
"""The issuer of the OpenID Provider: the web service's HTTPS site on the first HTTPS name, without the port when it
|
||||
is HTTPS_DEFAULT_PORT."""
|
||||
port = _get(cfg, 'https', 'web_port')
|
||||
return f'https://{_get(cfg, "wan", "local_fqdn")}' + ('' if port == HTTPS_DEFAULT_PORT else f':{port}')
|
||||
return f'https://{https_names(cfg)[0]}' + ('' if port == HTTPS_DEFAULT_PORT else f':{port}')
|
||||
|
||||
|
||||
def resolve_psk(connection, name):
|
||||
@@ -1177,7 +1172,9 @@ def build_context(cfg, public_ip=None):
|
||||
'web_enabled': _get(cfg, 'web', 'enabled'),
|
||||
'web_port': _get(cfg, 'web', 'port'),
|
||||
'web_listen': _get(cfg, 'web', 'listen'),
|
||||
'https_enabled': _get(cfg, 'https', 'enabled'),
|
||||
'https_names': https_names(cfg),
|
||||
'https_ips': https_addresses(cfg, local_addrs, int_addr),
|
||||
'mdns': not local_fqdn,
|
||||
'https_email': _get(cfg, 'https', 'email'),
|
||||
'https_certificate': _get(cfg, 'https', 'certificate'),
|
||||
'https_acme_provider': _get(cfg, 'https', 'acme_provider'),
|
||||
@@ -1241,9 +1238,30 @@ def vpn_pools(ctx):
|
||||
(wg_ready(ctx), ctx['wg_network'])) if ready]
|
||||
|
||||
|
||||
def https_ready(ctx):
|
||||
"""Caddy serves HTTPS once it is enabled and wan.local_fqdn names the certificate."""
|
||||
return bool(ctx['https_enabled'] and ctx['local_fqdn'])
|
||||
def https_names(cfg):
|
||||
"""The names of the server's HTTPS certificate and sites: wan.local_fqdn alone when it is set, else the host name
|
||||
and <host name>.local, which Avahi announces with mDNS."""
|
||||
fqdn = _get(cfg, 'wan', 'local_fqdn').lower()
|
||||
if fqdn:
|
||||
return [fqdn]
|
||||
host = socket.gethostname().split('.')[0].lower()
|
||||
return [host, f'{host}.local']
|
||||
|
||||
|
||||
def https_addresses(cfg, local_addrs, int_addr):
|
||||
"""The IP addresses of the server's HTTPS certificate and sites while https.ip_sans is on: those of its interfaces
|
||||
and wan.public_address, without link-local ones; [] while it is off."""
|
||||
if not _get(cfg, 'https', 'ip_sans'):
|
||||
return []
|
||||
found = []
|
||||
for value in (*local_addrs, int_addr, _get(cfg, 'wan', 'public_address')):
|
||||
try:
|
||||
address = ipaddress.ip_address(str(value).split('/')[0])
|
||||
except ValueError:
|
||||
continue
|
||||
if not address.is_link_local and str(address) not in found:
|
||||
found.append(str(address))
|
||||
return found
|
||||
|
||||
|
||||
def metrics_ready(ctx):
|
||||
@@ -1252,8 +1270,8 @@ def metrics_ready(ctx):
|
||||
|
||||
|
||||
def webdav_ready(ctx):
|
||||
"""WebDAV of the sites' folders is served by Caddy, on the server's own name, while it is on and HTTPS is ready."""
|
||||
return bool(ctx['webdav_enabled'] and https_ready(ctx))
|
||||
"""WebDAV of the sites' folders is served by Caddy, on the server's HTTPS names, while it is on."""
|
||||
return bool(ctx['webdav_enabled'])
|
||||
|
||||
|
||||
def packages_installed(packages):
|
||||
|
||||
Reference in new issue
Block a user