diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 3812d84a93..cb04a8064b 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -1178,15 +1178,53 @@ switching protocol or observation location is not proof that ICMP recovered. ## ๐Ÿ”’ HTTPS / TLS -Enable HTTPS by providing certificate files via environment variables. +Enable HTTPS with a certificate and its matching private key. With direct HTTPS, +use `https://` on the existing `FRONTEND_PORT` (normally `7655`). Pulse does +not open port `443` automatically. If existing agents must keep their HTTP +address, use an [HTTPS reverse proxy](REVERSE_PROXY.md) for the new address +instead of switching their listener to HTTPS. + +[systemd setup](#https-with-systemd) ยท [Docker setup](#https-with-docker) + +### HTTPS with systemd + +For the standard `pulse.service`, run `sudo systemctl edit pulse.service` +and put these lines in the editable portion of the drop-in. Use your actual +service name and certificate paths if they differ. + +```ini +[Service] +Environment="HTTPS_ENABLED=true" +Environment="TLS_CERT_FILE=/etc/pulse/cert.pem" +Environment="TLS_KEY_FILE=/etc/pulse/key.pem" +``` + +Bare assignments under `[Service]` are ignored. If the unit's +`EnvironmentFile=` already sets these variables (normally in +`/etc/pulse/.env`), update those values instead: systemd gives them precedence. +The service must be able to read both files. For the standard `pulse` user +and group, keep the key owned by `root:pulse` with mode `0640` and its parent +directories accessible to the service. On a custom unit, grant read access +only to its service identity. Do not make the private key world-readable. + +Restart the server service in a maintenance window; monitoring and alerts are +unavailable during the restart. From the client or new agent host, use a name +that matches the certificate's Subject Alternative Name and the actual port. +For a private CA or self-signed certificate, use a separately verified copy of +the public CA certificate or self-signed certificate, never the private key: ```bash -# Systemd -HTTPS_ENABLED=true -TLS_CERT_FILE=/etc/pulse/cert.pem -TLS_KEY_FILE=/etc/pulse/key.pem +curl --disable --fail --cacert /path/to/trusted-cert.pem \ + https://pulse.example.net:7655/api/health +``` -# Docker +A successful check verifies that client can reach the HTTPS health endpoint, +not that an agent is enrolled. For the installer and agent connection, see +[private-file agent installation](UNIFIED_AGENT.md#private-file-installation-linux-macos-and-nas). + +### HTTPS with Docker + +```bash docker run --init -e HTTPS_ENABLED=true \ -v /path/to/certs:/certs \ -e TLS_CERT_FILE=/certs/cert.pem \ diff --git a/frontend-modern/public/docs/CONFIGURATION.md b/frontend-modern/public/docs/CONFIGURATION.md index 3812d84a93..cb04a8064b 100644 --- a/frontend-modern/public/docs/CONFIGURATION.md +++ b/frontend-modern/public/docs/CONFIGURATION.md @@ -1178,15 +1178,53 @@ switching protocol or observation location is not proof that ICMP recovered. ## ๐Ÿ”’ HTTPS / TLS -Enable HTTPS by providing certificate files via environment variables. +Enable HTTPS with a certificate and its matching private key. With direct HTTPS, +use `https://` on the existing `FRONTEND_PORT` (normally `7655`). Pulse does +not open port `443` automatically. If existing agents must keep their HTTP +address, use an [HTTPS reverse proxy](REVERSE_PROXY.md) for the new address +instead of switching their listener to HTTPS. + +[systemd setup](#https-with-systemd) ยท [Docker setup](#https-with-docker) + +### HTTPS with systemd + +For the standard `pulse.service`, run `sudo systemctl edit pulse.service` +and put these lines in the editable portion of the drop-in. Use your actual +service name and certificate paths if they differ. + +```ini +[Service] +Environment="HTTPS_ENABLED=true" +Environment="TLS_CERT_FILE=/etc/pulse/cert.pem" +Environment="TLS_KEY_FILE=/etc/pulse/key.pem" +``` + +Bare assignments under `[Service]` are ignored. If the unit's +`EnvironmentFile=` already sets these variables (normally in +`/etc/pulse/.env`), update those values instead: systemd gives them precedence. +The service must be able to read both files. For the standard `pulse` user +and group, keep the key owned by `root:pulse` with mode `0640` and its parent +directories accessible to the service. On a custom unit, grant read access +only to its service identity. Do not make the private key world-readable. + +Restart the server service in a maintenance window; monitoring and alerts are +unavailable during the restart. From the client or new agent host, use a name +that matches the certificate's Subject Alternative Name and the actual port. +For a private CA or self-signed certificate, use a separately verified copy of +the public CA certificate or self-signed certificate, never the private key: ```bash -# Systemd -HTTPS_ENABLED=true -TLS_CERT_FILE=/etc/pulse/cert.pem -TLS_KEY_FILE=/etc/pulse/key.pem +curl --disable --fail --cacert /path/to/trusted-cert.pem \ + https://pulse.example.net:7655/api/health +``` -# Docker +A successful check verifies that client can reach the HTTPS health endpoint, +not that an agent is enrolled. For the installer and agent connection, see +[private-file agent installation](UNIFIED_AGENT.md#private-file-installation-linux-macos-and-nas). + +### HTTPS with Docker + +```bash docker run --init -e HTTPS_ENABLED=true \ -v /path/to/certs:/certs \ -e TLS_CERT_FILE=/certs/cert.pem \ diff --git a/scripts/tests/test_server_https_docs.py b/scripts/tests/test_server_https_docs.py new file mode 100644 index 0000000000..488d3c9262 --- /dev/null +++ b/scripts/tests/test_server_https_docs.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +"""Check the copyable HTTPS drop-in without installing or starting any unit.""" + +import os +from pathlib import Path +import re +import shutil +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[2] + + +def https_drop_in(): + guide = (ROOT / "docs/CONFIGURATION.md").read_text(encoding="utf-8") + _, _, section = guide.partition("### HTTPS with systemd\n") + section = section.split("\n### ", 1)[0] + matches = re.findall(r"^\x60\x60\x60ini\n(.*?)^\x60\x60\x60$", section, re.M | re.S) + if len(matches) != 1: + raise AssertionError("expected one copyable systemd HTTPS drop-in") + return matches[0] + + +class ServerHttpsDocsTest(unittest.TestCase): + def test_drop_in_contains_all_three_service_environment_assignments(self): + header, *assignments = https_drop_in().splitlines() + self.assertEqual(header, "[Service]") + variables = {} + for assignment in assignments: + match = re.fullmatch(r'Environment="([A-Z_]+)=([^"]+)"', assignment) + self.assertIsNotNone(match, assignment) + name, value = match.groups() + self.assertNotIn(name, variables) + variables[name] = value + self.assertEqual(set(variables), {"HTTPS_ENABLED", "TLS_CERT_FILE", "TLS_KEY_FILE"}) + self.assertEqual(variables["HTTPS_ENABLED"], "true") + for key in ("TLS_CERT_FILE", "TLS_KEY_FILE"): + self.assertTrue(Path(variables[key]).is_absolute(), variables[key]) + + @unittest.skipUnless(shutil.which("systemd-analyze"), "systemd parser unavailable") + def test_systemd_accepts_the_example_as_a_drop_in(self): + with tempfile.TemporaryDirectory(prefix="pulse-https-docs-") as directory: + root = Path(directory) + unit = root / "pulse-https-example.service" + unit.write_text( + "[Unit]\nDefaultDependencies=no\n[Service]\nExecStart=/bin/true\n", + encoding="utf-8", + ) + drop_ins = root / (unit.name + ".d") + drop_ins.mkdir() + (drop_ins / "override.conf").write_text(https_drop_in(), encoding="utf-8") + result = subprocess.run( + ["systemd-analyze", "verify", "--man=no", "--generators=no", str(unit)], + env={**os.environ, "SYSTEMD_UNIT_PATH": directory}, + capture_output=True, text=True, timeout=10, + ) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stderr, "", result.stderr) + + +if __name__ == "__main__": + unittest.main()