feature: the CA certificates and CRLs are always published over HTTP and HTTPS on the status and Manager ports, the Shell page is an entry of the page menu, and the web interface passes its lint.
Release / release (push) Successful in 26s

This commit is contained in:
slawek committed 2026-11-24 18:06:34 +01:00
1 parent 4b5318c676
commit 0cec95c19b
72 files changed
+910 -861

No files matched your search

@@ -87,7 +87,7 @@ SCHEMA = {
'sites': {'enabled': False, 'upload_max_mb': 512, 'webdav': False, 'webdav_port': 7445},
'dns': {'enabled': False, 'secondary': '', 'listen': 'external', 'ttl': 300},
'pki': {'root_name': 'Linux Manager Root CA', 'root_days': 7300, 'ca_days': 3650, 'key': 'rsa-4096',
'crl_days': 7, 'root_crl_days': 180, 'publish': ['http'], 'p2s_name': 'Linux Manager VPN CA',
'crl_days': 7, 'root_crl_days': 180, 'p2s_name': 'Linux Manager VPN CA',
's2s_name': 'Linux Manager Site-to-Site CA', 'servers_name': 'Linux Manager Servers CA',
'issuing_cas': {}, 'templates': {},
'extended_key_usages': {}, 'root': 'local', 'simple_ca_url': ''},
@@ -148,7 +148,7 @@ PBS_NAMESPACE = re.compile(r'^[A-Za-z0-9_][A-Za-z0-9._-]*(/[A-Za-z0-9_][A-Za-z0-
#: The port of Let's Encrypt's HTTP challenge, which Caddy answers while HTTPS is on.
ACME_HTTP_PORT = 80
#: The default port of HTTPS, where Caddy publishes the CA files when pki.publish has https-default.
#: The default port of HTTPS.
HTTPS_DEFAULT_PORT = 443
#: The most files web.log_files lists.
@@ -171,8 +171,9 @@ COMPONENTS = {
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 and a site chooses the address of its records.
RETIRED = {'dns': ('nameserver', 'addresses')}
#: 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',)}
#: The shortest and the longest dns.ttl, in seconds.
DNS_TTL_RANGE = (60, 86400)
@@ -212,9 +213,6 @@ PKI_KEYS = ('rsa-2048', 'rsa-3072', 'rsa-4096', 'ec-p256', 'ec-p384')
#: Where the root CA comes from, pki.root: the server creates it, an offline CA, or a Simple CA service.
PKI_ROOTS = ('local', 'offline', 'simple-ca')
#: Where the CA certificates and CRLs are published, pki.publish, as the URLs in the certificates list them.
PKI_PUBLISH = ('http', 'http-80', 'https', 'https-default')
#: The key usages a template may give, as the arguments of cryptography's KeyUsage.
KEY_USAGES = ('digital_signature', 'content_commitment', 'key_encipherment', 'data_encipherment', 'key_agreement')
@@ -749,18 +747,6 @@ def validate(cfg):
raise ConfigError('pki.simple_ca_url must be an https:// URL without a query or a fragment')
if _get(cfg, 'pki', 'key') not in PKI_KEYS:
raise ConfigError(f'pki.key: {_get(cfg, "pki", "key")!r} is not one of {", ".join(PKI_KEYS)}')
publish = _get_list(cfg, 'pki', 'publish')
for item in publish:
if item not in PKI_PUBLISH:
raise ConfigError(f'pki.publish: {item!r} is not one of {", ".join(PKI_PUBLISH)}')
if len(set(publish)) != len(publish):
raise ConfigError('pki.publish names an endpoint twice')
if publish and not _get(cfg, 'wan', 'local_fqdn'):
raise ConfigError('pki.publish needs wan.local_fqdn, the name in the published URLs')
if 'http' in publish and not _get(cfg, 'web', 'enabled'):
raise ConfigError('pki.publish: http is served by the web service, which needs web.enabled')
if set(publish) - {'http'} and not _get(cfg, 'https', 'enabled'):
raise ConfigError('pki.publish: http-80, https and https-default are served by Caddy, which needs https.enabled')
for name, oid in cfg['pki']['extended_key_usages'].items():
prefix = f'pki.extended_key_usages.{name}'
if not EKU_NAME.match(name) or name in EXTENDED_KEY_USAGES:
@@ -833,13 +819,6 @@ def validate(cfg):
if port in taken:
raise ConfigError(f'{taken[port]}: {port} is the port of {owner}')
taken[port] = owner
if 'https-default' in publish:
if HTTPS_DEFAULT_PORT in taken:
raise ConfigError(f'pki.publish: https-default takes port {HTTPS_DEFAULT_PORT}, the port of '
f'{taken[HTTPS_DEFAULT_PORT]}')
if _get(cfg, 'openvpn', 'protocol') == 'tcp' and _get(cfg, 'openvpn', 'port') == HTTPS_DEFAULT_PORT:
raise ConfigError(f'pki.publish: https-default takes port {HTTPS_DEFAULT_PORT}, the port of openvpn.port')
taken[HTTPS_DEFAULT_PORT] = 'pki.publish https-default'
for section_name, option in (('metrics', 'port'), ('metrics', 'https_port'), ('sites', 'webdav_port')):
port = _get(cfg, section_name, option)
if isinstance(port, bool) or not isinstance(port, int) or not 1 <= port <= 65535:
@@ -920,7 +899,7 @@ def validate(cfg):
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, *([HTTPS_DEFAULT_PORT] if 'https-default' in publish else []))
*((ACME_HTTP_PORT, *https_ports)
if _get(cfg, 'https', 'enabled') else ()))
for port in caddy_ports:
if int(first) <= port <= int(last or first):
@@ -963,15 +942,14 @@ def issuing_cas(cfg):
def pki_base_urls(cfg):
"""The base URLs, ending in /, under which the CA certificates and CRLs are published, in the order of pki.publish."""
"""The plain HTTP base URLs, ending in /, under which Caddy publishes the CA certificates and CRLs and the
certificates name them: the status web service's web.port while it is enabled, then the Manager's port; none without
wan.local_fqdn."""
fqdn = _get(cfg, 'wan', 'local_fqdn')
bases = {
'http': f'http://{fqdn}:{_get(cfg, "web", "port")}/pki/',
'http-80': f'http://{fqdn}/pki/',
'https': f'https://{fqdn}:{_get(cfg, "https", "web_port")}/pki/',
'https-default': f'https://{fqdn}/pki/',
}
return [bases[item] for item in _get_list(cfg, 'pki', 'publish') if item in bases] if fqdn else []
if not fqdn:
return []
ports = [*([_get(cfg, 'web', 'port')] if _get(cfg, 'web', 'enabled') else []), manager_port()]
return [f'http://{fqdn}:{port}/pki/' for port in ports]
def manager_port():
@@ -1211,7 +1189,6 @@ def build_context(cfg, public_ip=None):
'https_zerossl_api_key': _get(cfg, 'https', 'zerossl_api_key'),
'https_web_port': _get(cfg, 'https', 'web_port'),
'https_manager_port': _get(cfg, 'https', 'manager_port'),
'pki_publish': _get_list(cfg, 'pki', 'publish'),
'pki_acme': [name for name, authority in issuing_cas(cfg).items() if authority['acme']],
'metrics_enabled': _get(cfg, 'metrics', 'enabled'),
'metrics_port': _get(cfg, 'metrics', 'port'),
@@ -20,8 +20,8 @@ The root comes from one of ROOT_SOURCES, pki.root, fixed once the root exists:
issuing CAs, the upstream CA, kept on cn=root; the upstream CA's certificate and CRL are the entry cn=upstream, and
it stands between the root and the issuing CAs in every chain.
The certificates carry the URLs of pki.publish for their issuer's certificate (AIA) and CRL (CRL distribution point);
PUBLISH_DIR holds the DER copies served there. distribute writes the files strongSwan, OpenVPN and the system's trust
The certificates carry the URLs of linuxmanager.pki_base_urls for their issuer's certificate (AIA) and CRL (CRL
distribution point); PUBLISH_DIR holds the DER copies Caddy serves there. distribute writes the files strongSwan, OpenVPN and the system's trust
store read.
Callers hold locked() around every operation that writes, which is the lock of the user module's sessions too. A request
@@ -30,9 +30,6 @@ Pages:
/ca the PKI: its settings, the root and issuing CAs, the certificates issued; change the
settings, issue and revoke certificates, and take the certificate of an issuing CA
and a root CRL signed offline (see ca())
/pki/<name>.crt, /pki/<name>.crl
the DER certificate and CRL of the root (root) and of each issuing CA, which the
certificates name in their AIA and CRL distribution points; no authentication
/shell while web.shell is true, a login shell of the user's console account on a terminal, for
a member of admins whose console login is on and who has a TOTP token: POST signs the user in again,
with the password and the TOTP code or with a passkey whose proof POST /shell/passkey begins,
@@ -8,11 +8,9 @@ from http.server import BaseHTTPRequestHandler
import ldap
import linuxmanager
import linuxmanager_auth
import linuxmanager_net
import linuxmanager_oidc
import linuxmanager_pki
import linuxmanager_sites
from .auth import auth, auth_wait, refusal
@@ -25,7 +23,7 @@ from .identities import account, groups, service_accounts, users
from .logs import logs
from .https import PATHS as HTTPS_PATHS, https
from .metrics import metrics_history, metrics_settings
from .pki import PUBLISHED, ca
from .pki import ca
from .shell import EDITOR_BODY_LIMIT, shell, shell_editor, shell_passkey, shell_ticket
from .sites import SITE_FILES, site_files, sites
from .status import cached, details, html_of, postgresql_databases, shown, text_of
@@ -182,9 +180,6 @@ class Handler(BaseHTTPRequestHandler):
extra += headers
elif self.command not in ('GET', 'HEAD'):
body, kind, code = b'Method not allowed\n', 'text/plain; charset=utf-8', 405
elif path.startswith('/pki/') and linuxmanager.PKI_NAME.match(path[5:-4]) and path[-4:] in PUBLISHED and \
(linuxmanager_pki.PUBLISH_DIR / path[5:]).is_file():
body, kind, code = (linuxmanager_pki.PUBLISH_DIR / path[5:]).read_bytes(), PUBLISHED[path[-4:]], 200
elif path in ('/status', '/'):
document = shown(cached(), section(read_json(CONFIG_FILE), 'web').get('status_content'), self.client())
agent = self.headers.get('User-Agent', '').lower()
@@ -1,4 +1,4 @@
"""The PKI: /ca, and the certificates and CRLs /pki/ serves without authentication."""
"""The PKI: /ca."""
import ldap
@@ -7,9 +7,6 @@ import linuxmanager_pki
from .common import PKI_STATUS
#: A file /pki/ serves: the certificate or the CRL of a CA, and its content type.
PUBLISHED = {'.crt': 'application/pkix-cert', '.crl': 'application/pkix-crl'}
def ca(method, path, body):
"""Answer a /ca request with linuxmanager_pki: the HTTP status and the JSON document.
+8 -11
View File
@@ -293,22 +293,18 @@ def filter_block(ctx):
lines += ['', '# METRICS RULES START', *opened(ctx['metrics_listen'], ctx['metrics_port']),
'# METRICS RULES END']
# The ACME CA reaches the HTTP challenge on the external interface while it issues the server's certificate, and
# the CA files published on port 80 are read on both; the HTTPS ports are open on both.
# The ACME CA reaches the HTTP challenge on the external interface while it issues the server's certificate; the
# HTTPS ports are open on both.
if linuxmanager.https_ready(ctx) and interfaces:
publish = ctx['pki_publish']
ports = [port for wanted, port in ((ctx['web_enabled'] or 'https' in publish or ctx['pki_acme'],
ctx['https_web_port']),
ports = [port for wanted, port in ((ctx['web_enabled'] or ctx['pki_acme'], ctx['https_web_port']),
(True, ctx['https_manager_port']),
(linuxmanager.metrics_ready(ctx), ctx['metrics_https_port']),
(linuxmanager.webdav_ready(ctx), ctx['webdav_port']),
('http-80' in publish, linuxmanager.ACME_HTTP_PORT),
('https-default' in publish, linuxmanager.HTTPS_DEFAULT_PORT)) if wanted]
(linuxmanager.webdav_ready(ctx), ctx['webdav_port'])) if wanted]
lines += [
'',
'# HTTPS RULES START',
*([f'-A ufw-before-input -i {ctx["wan_iface"]} -p tcp --dport {linuxmanager.ACME_HTTP_PORT} -j ACCEPT']
if ctx['wan_iface'] and 'http-80' not in publish and ctx['https_certificate'] == 'acme' else []),
if ctx['wan_iface'] and ctx['https_certificate'] == 'acme' else []),
*(f'-A ufw-before-input -i {name} -p tcp --dport {port} -j ACCEPT' for name in interfaces for port in ports),
'# HTTPS RULES END',
]
@@ -757,8 +753,9 @@ def manage_caddy(cfg, ctx):
its service on its loopback port. The certificate comes from the ACME CA of https.acme_provider, the global issuer,
with https.certificate acme, and otherwise is the one linuxmanager_pki.https_files gives, written to
CADDY_HTTPS_DIR; while that cannot be read, the HTTPS sites are left out, so that no ACME CA is asked for it. It
also serves the CA files of linuxmanager_pki.PUBLISH_DIR at /pki/ on the endpoints of pki.publish that are Caddy's,
and an ACME server at /acme/<name>/ on https.web_port for each issuing CA with acme and a certificate.
also serves the CA files of linuxmanager_pki.PUBLISH_DIR at /pki/ on web.port, the Manager's port, https.web_port
and https.manager_port, ahead of the redirect to HTTPS, and an ACME server at /acme/<name>/ on https.web_port for
each issuing CA with acme and a certificate.
It serves each site of ctx's sites from its folder, with the TLS of the site: an issuing CA of tls ca issues its
certificates, and the certificate and key of tls file are written to CADDY_SITES_DIR/<name>. The certificates and
@@ -106,7 +106,6 @@
"key": "rsa-4096",
"crl_days": 7,
"root_crl_days": 180,
"publish": ["http"],
"p2s_name": "Linux Manager VPN CA",
"s2s_name": "Linux Manager Site-to-Site CA",
"issuing_cas": {
@@ -33,23 +33,40 @@
}
{%- endif %}
}
{#- The CA certificates and CRLs of directory at /pki/, as DER with the content types of RFC 5280. #}
{%- macro pki_files(directory) %}
handle_path /pki/* {
@crt path *.crt
@crl path *.crl
header @crt Content-Type application/pkix-cert
header @crl Content-Type application/pkix-crl
root * {{ directory }}
file_server
}
{%- endmacro %}
{% if web_enabled %}
http://:{{ web_port }} {
header -Server
reverse_proxy {{ loopback }}:{{ web_loopback_port }} {
header_down -Server
{{- pki_files(pki_publish_dir) }}
handle {
reverse_proxy {{ loopback }}:{{ web_loopback_port }} {
header_down -Server
}
}
}
{% endif %}
http://:{{ manager_port }} {
header -Server
{{- pki_files(pki_publish_dir) }}
handle {
{%- if redirect %}
redir https://{{ local_fqdn }}:{{ https_manager_port }}{uri} 308
redir https://{{ local_fqdn }}:{{ https_manager_port }}{uri} 308
{%- else %}
reverse_proxy {{ loopback }}:{{ manager_loopback_port }} {
header_down -Server
}
reverse_proxy {{ loopback }}:{{ manager_loopback_port }} {
header_down -Server
}
{%- endif %}
}
}
{% if metrics_enabled %}
http://:{{ metrics_port }} {
@@ -59,18 +76,13 @@ http://:{{ metrics_port }} {
}
}
{% endif %}
{%- if https and (web_enabled or 'https' in pki_publish or acme_cas) %}
{%- if https and (web_enabled or acme_cas) %}
{{ local_fqdn }}:{{ https_web_port }} {
header -Server
{%- if https_tls %}
tls {{ https_tls.cert }} {{ https_tls.key }}
{%- endif %}
{%- if 'https' in pki_publish %}
handle_path /pki/* {
root * {{ pki_publish_dir }}
file_server
}
{%- endif %}
{{- pki_files(pki_publish_dir) }}
{%- for ca in acme_cas %}
handle /acme/{{ ca }}/* {
acme_server {
@@ -89,41 +101,17 @@ http://:{{ metrics_port }} {
}
}
{% endif %}
{%- if https and 'http-80' in pki_publish %}
http://{{ local_fqdn }} {
header -Server
handle_path /pki/* {
root * {{ pki_publish_dir }}
file_server
}
handle {
respond 404
}
}
{% endif %}
{%- if https and 'https-default' in pki_publish %}
{{ local_fqdn }}:443 {
header -Server
{%- if https_tls %}
tls {{ https_tls.cert }} {{ https_tls.key }}
{%- endif %}
handle_path /pki/* {
root * {{ pki_publish_dir }}
file_server
}
handle {
respond 404
}
}
{% endif %}
{%- if https %}
{{ local_fqdn }}:{{ https_manager_port }} {
header -Server
{%- if https_tls %}
tls {{ https_tls.cert }} {{ https_tls.key }}
{%- endif %}
reverse_proxy {{ loopback }}:{{ manager_loopback_port }} {
header_down -Server
{{- pki_files(pki_publish_dir) }}
handle {
reverse_proxy {{ loopback }}:{{ manager_loopback_port }} {
header_down -Server
}
}
}
{% endif %}