Compare commits

...
1 Commits
6 changed files with 79 additions and 31 deletions

No files matched your search

+8 -3
View File
@@ -109,7 +109,9 @@ exists. Users are changed by `cn=user-manager,ou=services`, whose ACLs allow wri
and setting passwords (`=wx`) but not reading them. Passwords are hashed with ARGON2, and the
ppolicy overlay locks a disabled user (`pwdAccountLockedTime`, effective with `pwdLockout`).
slapd listens on the local socket only. Provisioning checks every step before changing it, so it
runs at every start of `linux-manager-setup`.
runs at every start of `linux-manager-setup`. The database's `olcDbMaxSize` is 1 GiB, as the
default of slapd-mdb, 10 MB, is small for a database that holds the users and every certificate
issued, which is never deleted; a larger limit is left as it is.
Consequences: The package depends on `slapd`, `python3-ldap`, `openvpn` and
`openvpn-auth-ldap`, and `linux-manager-setup` and `linux-manager-user` import `python3-ldap`. The
@@ -833,7 +835,9 @@ enabled, then the Manager's port, which always exists. The files are DER, copied
them. The CRLs of the issuing CAs are valid for `pki.crl_days`, a week by default, signed again at
every revocation and by a daily timer once half their validity has passed; the root CRL has its own
`pki.root_crl_days`, half a year by default, so an offline root needs its CRL signed twice a year,
not weekly.
not weekly. A revocation and its CRL are separate writes to the directory, so the timer and setup
also sign a CRL again that lacks a revoked certificate that has not expired, for the CAs whose key
is on the server.
Consequences: A client that caches a CRL sees a revocation within a week. A client tries the URLs
in order, so one that cannot reach the status port falls back to the Manager's. The files are
@@ -928,7 +932,8 @@ retired CA keeps its entry, renamed, so its certificates stay in the inventory.
from outside, by cloud-init or by hand, is placed as files before the first setup with a platform,
which imports and removes them. strongSwan, OpenVPN, Caddy and the system's trust store read files,
so setup and every revocation write them from the directory. Setup provisions the directory before
the PKI; without the directory it leaves the PKI and its files as they are and configures the rest.
the PKI; without the directory it leaves the PKI and its files as they are and configures the rest,
Caddy with the copies it has of the certificates and keys.
Consequences: `slapcat` writes the users and the PKI into every backup in one consistent copy, and a
restore brings both back together. The PKI depends on slapd, as the users already do, and not on
+13
View File
@@ -1,5 +1,18 @@
# Changelog
## 0.45.3 - 2026-12-03 23:03:55 +0100
fix: the directory holds up to 1 GiB, a revocation missing from its CRL is signed into it, and a
setup without the directory keeps the certificates Caddy serves.
- The directory's database holds up to 1 GiB instead of slapd's default of 10 MB;
linux-manager-setup also raises the limit of an existing database.
- linux-manager-ca maintain, which the daily timer runs, and linux-manager-setup sign a CRL again
that lacks a revoked certificate that has not expired, as after a revocation that was interrupted.
- A run of linux-manager-setup that cannot read the directory keeps the certificates and keys copied
for Caddy and goes on serving the HTTPS sites, the ACME servers and the sites of issuing CAs with
them; it leaves out only what has no copy.
## 0.45.2 - 2026-11-24 20:41:04 +0100
fix: the copy icons of the Manager are shown only on a page opened over HTTPS, where the browser
+7 -4
View File
@@ -656,8 +656,9 @@ extensions are left out.
The CRLs of the issuing CAs are valid for `pki.crl_days`, and the root CRL, when the server signs
it, for `pki.root_crl_days`. A CRL is signed again at every revocation and, once half of its
validity has passed, by `linux-manager-pki.timer`, which runs `linux-manager-ca maintain` daily; it also
has `linux-manager-setup` renew the server's certificates when they are due. OpenVPN checks the CRL
validity has passed or when it lacks a revoked certificate that has not expired, by
`linux-manager-pki.timer`, which runs `linux-manager-ca maintain` daily; it also has
`linux-manager-setup` renew the server's certificates when they are due. OpenVPN checks the CRL
of every CA of a client's chain, the root's included, and refuses every client while one has
expired.
@@ -792,7 +793,7 @@ is switched on:
- its own database, `dc=linux-manager,dc=local` in `/var/lib/ldap/linux-manager`, next to the one the
slapd package creates; root manages it through the local socket, with no administrator
password;
password; its size limit (`olcDbMaxSize`) is 1 GiB, to which setup raises a smaller one;
- `ou=users` holds one entry per user, named by `uid`: an `inetOrgPerson` for a VPN user, an
`account` for a Manager-only account (see Managing users);
- the package's own schema under the OID `1.3.6.1.4.1.67380.10.1.2`, listed in
@@ -1708,7 +1709,9 @@ HTTPS certificate row makes the CSR and imports the certificates, and `/https` c
`/usr/lib/systemd/system/caddy.service.d/linux-manager.conf` makes `caddy.service` read;
`caddy.service` does not start before the file exists, and `/etc/caddy/Caddyfile` is not used.
Setup starts Caddy once the server is configured (`general.platform` other than `none`) and
reloads it when the file changes.
reloads it when the file changes. While the directory cannot be read, Caddy keeps serving the
certificates and keys an earlier run of setup copied for it, those of the HTTPS names and of the
issuing CAs; what has no copy is left out.
Caddy listens on every address, and the firewall decides who reaches it: `web.port` is open on the
interfaces `web.listen` names, the Manager's port on those of its `listen`, and `metrics.port` on
@@ -86,6 +86,9 @@ TOTP_WINDOW = 1
#: The value of pwdAccountLockedTime that disables a user until it is enabled again.
DISABLED = '000001010000Z'
#: The largest size of the database, in bytes: slapd-mdb's olcDbMaxSize.
DB_MAX_SIZE = 1024 ** 3
#: The indexes of the database.
INDEXES = ('objectClass eq', 'uid eq', 'uidNumber eq', 'linuxManagerConsoleLogin eq', 'linuxManagerCertificateName eq')
@@ -190,9 +193,10 @@ def _ensure_password_hash(connection):
def _ensure_database(connection):
"""The DN of the package's database in cn=config, created when missing; its ACLs are kept as ACCESS, and the
indexes of INDEXES it lacks are added, which slapd builds online."""
found = connection.search_s('cn=config', ldap.SCOPE_ONELEVEL, f'(olcSuffix={BASE})', ['olcAccess', 'olcDbIndex'])
"""The DN of the package's database in cn=config, created when missing; its ACLs are kept as ACCESS, a largest size
below DB_MAX_SIZE is raised to it, and the indexes of INDEXES it lacks are added, which slapd builds online."""
wanted = ['olcAccess', 'olcDbIndex', 'olcDbMaxSize']
found = connection.search_s('cn=config', ldap.SCOPE_ONELEVEL, f'(olcSuffix={BASE})', wanted)
if not found:
DB_DIRECTORY.mkdir(mode=0o700, parents=True, exist_ok=True)
openldap = pwd.getpwnam('openldap')
@@ -203,11 +207,14 @@ def _ensure_database(connection):
'olcSuffix': [BASE.encode()],
'olcDbDirectory': [str(DB_DIRECTORY).encode()],
'olcRootDN': [ROOT.encode()],
'olcDbMaxSize': [str(DB_MAX_SIZE).encode()],
'olcDbIndex': [index.encode() for index in INDEXES],
'olcAccess': [f'{{{index}}}{rule}'.encode() for index, rule in enumerate(ACCESS)],
}))
found = connection.search_s('cn=config', ldap.SCOPE_ONELEVEL, f'(olcSuffix={BASE})', ['olcAccess', 'olcDbIndex'])
found = connection.search_s('cn=config', ldap.SCOPE_ONELEVEL, f'(olcSuffix={BASE})', wanted)
dn, attributes = found[0]
if int(attributes.get('olcDbMaxSize', [b'0'])[0]) < DB_MAX_SIZE:
connection.modify_s(dn, [(ldap.MOD_REPLACE, 'olcDbMaxSize', [str(DB_MAX_SIZE).encode()])])
if unordered(attributes.get('olcAccess', [])) != list(ACCESS):
connection.modify_s(dn, [(ldap.MOD_REPLACE, 'olcAccess', [f'{{{index}}}{rule}'.encode() for index, rule in enumerate(ACCESS)])])
present = [value.decode() for value in attributes.get('olcDbIndex', [])]
@@ -523,6 +523,12 @@ def check_subject(kind, subject):
return subject.lower() if kind == 'dns' else subject
def revoked_unexpired(connection, name, moment):
"""The entries of the certificates the CA revoked that have not expired at moment, which its CRL lists."""
return [entry for entry in certificate_entries(connection, authority_dn(name), '(linuxManagerRevoked=*)')
if not entry['expires'] or entry['expires'] > iso(moment)]
def sign_crl(connection, cfg, name):
"""Sign a new CRL of the CA with the certificates it revoked that have not expired, valid for pki.root_crl_days for
the root and pki.crl_days for an issuing CA."""
@@ -537,9 +543,7 @@ def sign_crl(connection, cfg, name):
.next_update(moment + datetime.timedelta(days=days))
.add_extension(x509.CRLNumber(number), False)
.add_extension(authority_key_id(cert), False))
for revoked_entry in certificate_entries(connection, authority_dn(name), '(linuxManagerRevoked=*)'):
if revoked_entry['expires'] and revoked_entry['expires'] <= iso(moment):
continue
for revoked_entry in revoked_unexpired(connection, name, moment):
revoked = (x509.RevokedCertificateBuilder()
.serial_number(int(revoked_entry['serial'], 16))
.revocation_date(datetime.datetime.strptime(revoked_entry['revoked'], '%Y-%m-%dT%H:%M:%SZ')
@@ -569,10 +573,13 @@ def ready(name):
def refresh_crls(connection, cfg, force=()):
"""Sign a new CRL for each CA with its key on the server whose CRL is stale, or that force names."""
"""Sign a new CRL for each CA with its key on the server whose CRL is stale or lacks a revoked certificate that
has not expired, or that force names."""
for name in ['root', *issuing(connection)]:
entry = authority(connection, name)
if entry and entry['key'] and entry['cert'] and (name in force or crl_stale(entry['crl'])):
if entry and entry['key'] and entry['cert'] and (name in force or crl_stale(entry['crl']) or any(
entry['crl'].get_revoked_certificate_by_serial_number(int(revoked['serial'], 16)) is None
for revoked in revoked_unexpired(connection, name, now()))):
sign_crl(connection, cfg, name)
@@ -1582,9 +1589,9 @@ def import_root_crl(cfg, data):
def maintain(cfg):
"""Sign the stale CRLs again or, with simple-ca, fetch them, publish and install them; the notices, and True when
one of the server's certificates is due for renewal, the HTTPS certificate among them while the server issues it,
or, with simple-ca, an issuing CA waits for Simple CA, which linux-manager-setup does."""
"""Sign the CRLs of refresh_crls again and, with simple-ca, fetch the stale ones, publish and install them; the
notices, and True when one of the server's certificates is due for renewal, the HTTPS certificate among them while
the server issues it, or, with simple-ca, an issuing CA waits for Simple CA, which linux-manager-setup does."""
with directory() as connection:
refresh_crls(connection, cfg)
notices = fetch_crls(connection) if cfg['pki']['root'] == 'simple-ca' else []
+25 -12
View File
@@ -739,6 +739,12 @@ def manage_resolver(changed):
run(['systemctl', 'restart', RESOLVER_UNIT], check=False)
def caddy_copies(folder):
"""The certificate and key copied to folder for Caddy, cert.pem and key.pem; None when it has not both."""
files = (folder / 'cert.pem', folder / 'key.pem')
return tuple(file.read_bytes() for file in files) if all(file.is_file() for file in files) else None
def manage_caddy(cfg, ctx):
"""Run Caddy, a dependency of the package, which serves every HTTP and HTTPS port of the server's services and the
web sites; the services listen on loopback only.
@@ -753,15 +759,16 @@ def manage_caddy(cfg, ctx):
names; a client without SNI gets the certificate of the first HTTPS name. Every site calls
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
CADDY_HTTPS_DIR; while there is none, 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 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
keys of the issuing CAs of both are copied to CADDY_PKI_DIR. While the sites cannot be read (ctx's sites is None),
the Caddyfile is left as it is.
keys of the issuing CAs of both are copied to CADDY_PKI_DIR. While the directory cannot be read, the copies in
CADDY_HTTPS_DIR and CADDY_PKI_DIR are served and kept, and what has none is left out. While the sites cannot be
read (ctx's sites is None), the Caddyfile is left as it is.
"""
sites = ctx['sites']
if shutil.which('caddy') is None:
@@ -777,15 +784,19 @@ def manage_caddy(cfg, ctx):
fail(f'the group {CADDY_GROUP} does not exist; is the caddy package installed?')
https = True
own = None
if https and cfg['https']['certificate'] != 'acme':
unread = False
if cfg['https']['certificate'] != 'acme':
try:
own = linuxmanager_pki.https_files(cfg)
except ldap.LDAPError as exc:
warn(f'the HTTPS sites are left out: the HTTPS certificate cannot be read: {exc}')
https = False
if https and own is None:
warn('the HTTPS sites are left out: the server has no HTTPS certificate yet')
https = False
unread = True
own = caddy_copies(CADDY_HTTPS_DIR)
outcome = 'the HTTPS sites are left out' if own is None else 'the HTTPS sites keep its copy'
warn(f'the HTTPS certificate cannot be read, so {outcome}: {exc}')
else:
if own is None:
warn('the HTTPS sites are left out: the server has no HTTPS certificate yet')
https = own is not None
copied = False
if own is None:
if CADDY_HTTPS_DIR.is_dir():
@@ -801,14 +812,16 @@ def manage_caddy(cfg, ctx):
try:
credentials = {name: linuxmanager_pki.authority_files(name) for name in wanted}
except ldap.LDAPError as exc:
warn(f'the ACME servers and the sites of issuing CAs are left out: the PKI cannot be read: {exc}')
credentials = {}
unread = True
warn(f'the PKI cannot be read, so the ACME servers and the sites of issuing CAs keep its copies, and those '
f'without one are left out: {exc}')
credentials = {name: caddy_copies(CADDY_PKI_DIR / name) for name in wanted}
authorities = [name for name, files in credentials.items() if files is not None]
for site in sites:
if site['tls'] == 'ca' and site['ca'] not in authorities:
warn(f'site {site["name"]} is left out: issuing CA {site["ca"]} has no certificate')
sites = [site for site in sites if site['tls'] != 'ca' or site['ca'] in authorities]
for folder in (CADDY_PKI_DIR.iterdir() if CADDY_PKI_DIR.is_dir() else []):
for folder in (CADDY_PKI_DIR.iterdir() if CADDY_PKI_DIR.is_dir() and not unread else []):
if folder.name not in authorities:
shutil.rmtree(folder)
for name in authorities: