Spaces:
Running
Running
fix: restore supervisor after host reboot
Browse files- scripts/first_kill.py +1 -0
- scripts/install.py +41 -2
- scripts/run_installer_p0.py +1 -0
- scripts/uninstall.py +2 -1
- scripts/upgrade.py +17 -4
- scripts/verify_uninstalled.py +1 -0
- src/lumi_eggcracker/containment_probe.py +1 -0
- src/lumi_eggcracker/supervisor.py +1 -0
- tests/test_installer_security.py +14 -0
scripts/first_kill.py
CHANGED
|
@@ -46,6 +46,7 @@ INSTALL_TARGETS = (
|
|
| 46 |
Path("/run/lumi-eggcracker-watchdog"),
|
| 47 |
Path("/etc/systemd/system/lumi-eggcracker.service"),
|
| 48 |
Path("/etc/systemd/system/lumi-eggcracker-watchdog.service"),
|
|
|
|
| 49 |
)
|
| 50 |
MAX_DOWNLOAD_BYTES = 2 * 1024 * 1024
|
| 51 |
DETECTIONS = Path("/var/lib/lumi-eggcracker/detections")
|
|
|
|
| 46 |
Path("/run/lumi-eggcracker-watchdog"),
|
| 47 |
Path("/etc/systemd/system/lumi-eggcracker.service"),
|
| 48 |
Path("/etc/systemd/system/lumi-eggcracker-watchdog.service"),
|
| 49 |
+
Path("/etc/tmpfiles.d/lumi-eggcracker.conf"),
|
| 50 |
)
|
| 51 |
MAX_DOWNLOAD_BYTES = 2 * 1024 * 1024
|
| 52 |
DETECTIONS = Path("/var/lib/lumi-eggcracker/detections")
|
scripts/install.py
CHANGED
|
@@ -41,15 +41,27 @@ BIN = Path("/usr/local/bin/eggcracker")
|
|
| 41 |
ETC = Path("/etc/lumi-eggcracker")
|
| 42 |
UNIT = Path("/etc/systemd/system/lumi-eggcracker.service")
|
| 43 |
WATCHDOG_UNIT = Path("/etc/systemd/system/lumi-eggcracker-watchdog.service")
|
|
|
|
| 44 |
STATE = Path("/var/lib/lumi-eggcracker")
|
| 45 |
RUNTIME = Path("/run/lumi-eggcracker")
|
|
|
|
| 46 |
QUERY_SOCKET = RUNTIME / "query.sock"
|
| 47 |
OPERATOR_SOCKET = RUNTIME / "operator.sock"
|
| 48 |
ADMIN_SOCKET = RUNTIME / "admin.sock"
|
| 49 |
WATCHDOG_RUNTIME = Path("/run/lumi-eggcracker-watchdog")
|
| 50 |
HEARTBEAT_SOCKET = WATCHDOG_RUNTIME / "heartbeat.sock"
|
| 51 |
WORKLOAD_NAME = "lumi-eggcracker-workload"
|
| 52 |
-
TARGETS = (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
INSTALLER_VERSION = "1.0.0"
|
| 54 |
MAX_RELEASE_MANIFEST_BYTES = 32 * 1024
|
| 55 |
|
|
@@ -228,6 +240,30 @@ def watchdog_service() -> bytes:
|
|
| 228 |
return b"""[Unit]\nDescription=Lumi Eggcracker fail-closed watchdog\nBefore=lumi-eggcracker.service\n\n[Service]\nType=simple\nExecStart=/usr/bin/python3 -I -S /usr/local/lib/lumi-eggcracker/lumi-eggcracker.pyz _watchdog --policy /etc/lumi-eggcracker/policy.json\nRestart=always\nRestartSec=0.1\nRuntimeDirectory=lumi-eggcracker-watchdog\nRuntimeDirectoryMode=0700\nUMask=0077\nNoNewPrivileges=yes\nMemoryMin=16M\nMemoryMax=64M\nCPUWeight=10000\nIOWeight=1000\nTasksMax=32\nLimitNOFILE=4096\nOOMScoreAdjust=-1000\nProtectSystem=strict\nReadWritePaths=/var/lib/lumi-eggcracker /run/lumi-eggcracker-watchdog\nProtectHome=yes\nPrivateTmp=yes\nPrivateDevices=yes\nProtectKernelTunables=yes\nProtectKernelModules=yes\nProtectKernelLogs=yes\nRestrictSUIDSGID=yes\nLockPersonality=yes\nRestrictRealtime=yes\nRestrictAddressFamilies=AF_UNIX\nSystemCallArchitectures=native\n\n[Install]\nWantedBy=multi-user.target\n"""
|
| 229 |
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
def autonomous_primitives_available() -> bool:
|
| 232 |
if not hasattr(os, "pidfd_open") or not hasattr(signal, "pidfd_send_signal"):
|
| 233 |
return False
|
|
@@ -380,7 +416,10 @@ def main() -> int:
|
|
| 380 |
created.append(UNIT)
|
| 381 |
write_new(WATCHDOG_UNIT, watchdog_service().replace(b"Before=lumi-eggcracker.service\n\n", b"Before=lumi-eggcracker.service\nStartLimitIntervalSec=0\n\n"), 0o644)
|
| 382 |
created.append(WATCHDOG_UNIT)
|
| 383 |
-
|
|
|
|
|
|
|
|
|
|
| 384 |
write_new(STATE / "install-manifest.json", (json.dumps(manifest, sort_keys=True) + "\n").encode(), 0o600)
|
| 385 |
checked = run(["/usr/bin/systemctl", "daemon-reload"])
|
| 386 |
started_watchdog = run(["/usr/bin/systemctl", "enable", "--now", "lumi-eggcracker-watchdog.service"])
|
|
|
|
| 41 |
ETC = Path("/etc/lumi-eggcracker")
|
| 42 |
UNIT = Path("/etc/systemd/system/lumi-eggcracker.service")
|
| 43 |
WATCHDOG_UNIT = Path("/etc/systemd/system/lumi-eggcracker-watchdog.service")
|
| 44 |
+
TMPFILES = Path("/etc/tmpfiles.d/lumi-eggcracker.conf")
|
| 45 |
STATE = Path("/var/lib/lumi-eggcracker")
|
| 46 |
RUNTIME = Path("/run/lumi-eggcracker")
|
| 47 |
+
NETNS_RUNTIME = Path("/run/netns")
|
| 48 |
QUERY_SOCKET = RUNTIME / "query.sock"
|
| 49 |
OPERATOR_SOCKET = RUNTIME / "operator.sock"
|
| 50 |
ADMIN_SOCKET = RUNTIME / "admin.sock"
|
| 51 |
WATCHDOG_RUNTIME = Path("/run/lumi-eggcracker-watchdog")
|
| 52 |
HEARTBEAT_SOCKET = WATCHDOG_RUNTIME / "heartbeat.sock"
|
| 53 |
WORKLOAD_NAME = "lumi-eggcracker-workload"
|
| 54 |
+
TARGETS = (
|
| 55 |
+
LIB,
|
| 56 |
+
BIN,
|
| 57 |
+
ETC,
|
| 58 |
+
UNIT,
|
| 59 |
+
WATCHDOG_UNIT,
|
| 60 |
+
TMPFILES,
|
| 61 |
+
STATE,
|
| 62 |
+
RUNTIME,
|
| 63 |
+
WATCHDOG_RUNTIME,
|
| 64 |
+
)
|
| 65 |
INSTALLER_VERSION = "1.0.0"
|
| 66 |
MAX_RELEASE_MANIFEST_BYTES = 32 * 1024
|
| 67 |
|
|
|
|
| 240 |
return b"""[Unit]\nDescription=Lumi Eggcracker fail-closed watchdog\nBefore=lumi-eggcracker.service\n\n[Service]\nType=simple\nExecStart=/usr/bin/python3 -I -S /usr/local/lib/lumi-eggcracker/lumi-eggcracker.pyz _watchdog --policy /etc/lumi-eggcracker/policy.json\nRestart=always\nRestartSec=0.1\nRuntimeDirectory=lumi-eggcracker-watchdog\nRuntimeDirectoryMode=0700\nUMask=0077\nNoNewPrivileges=yes\nMemoryMin=16M\nMemoryMax=64M\nCPUWeight=10000\nIOWeight=1000\nTasksMax=32\nLimitNOFILE=4096\nOOMScoreAdjust=-1000\nProtectSystem=strict\nReadWritePaths=/var/lib/lumi-eggcracker /run/lumi-eggcracker-watchdog\nProtectHome=yes\nPrivateTmp=yes\nPrivateDevices=yes\nProtectKernelTunables=yes\nProtectKernelModules=yes\nProtectKernelLogs=yes\nRestrictSUIDSGID=yes\nLockPersonality=yes\nRestrictRealtime=yes\nRestrictAddressFamilies=AF_UNIX\nSystemCallArchitectures=native\n\n[Install]\nWantedBy=multi-user.target\n"""
|
| 241 |
|
| 242 |
|
| 243 |
+
def tmpfiles() -> bytes:
|
| 244 |
+
"""Provision the standard volatile network-namespace mount directory."""
|
| 245 |
+
return b"d /run/netns 0755 root root -\n"
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def ensure_netns_runtime() -> None:
|
| 249 |
+
"""Create or validate /run/netns without taking ownership of its contents."""
|
| 250 |
+
try:
|
| 251 |
+
metadata = NETNS_RUNTIME.lstat()
|
| 252 |
+
except FileNotFoundError:
|
| 253 |
+
NETNS_RUNTIME.mkdir(mode=0o755)
|
| 254 |
+
os.chown(NETNS_RUNTIME, 0, 0)
|
| 255 |
+
os.chmod(NETNS_RUNTIME, 0o755)
|
| 256 |
+
metadata = NETNS_RUNTIME.lstat()
|
| 257 |
+
if (
|
| 258 |
+
stat.S_ISLNK(metadata.st_mode)
|
| 259 |
+
or not stat.S_ISDIR(metadata.st_mode)
|
| 260 |
+
or metadata.st_uid != 0
|
| 261 |
+
or metadata.st_gid != 0
|
| 262 |
+
or stat.S_IMODE(metadata.st_mode) & 0o022
|
| 263 |
+
):
|
| 264 |
+
raise RuntimeError("/run/netns must be a root-owned non-writable directory")
|
| 265 |
+
|
| 266 |
+
|
| 267 |
def autonomous_primitives_available() -> bool:
|
| 268 |
if not hasattr(os, "pidfd_open") or not hasattr(signal, "pidfd_send_signal"):
|
| 269 |
return False
|
|
|
|
| 416 |
created.append(UNIT)
|
| 417 |
write_new(WATCHDOG_UNIT, watchdog_service().replace(b"Before=lumi-eggcracker.service\n\n", b"Before=lumi-eggcracker.service\nStartLimitIntervalSec=0\n\n"), 0o644)
|
| 418 |
created.append(WATCHDOG_UNIT)
|
| 419 |
+
write_new(TMPFILES, tmpfiles(), 0o644)
|
| 420 |
+
created.append(TMPFILES)
|
| 421 |
+
ensure_netns_runtime()
|
| 422 |
+
manifest = {"created_workload_group": created_group, "created_workload_user": created_user, "files": {str(BIN): digest(BIN), str(catalogue_path): digest(catalogue_path), str(ETC / "policy.json"): digest(ETC / "policy.json"), str(LIB / "lumi-eggcracker.pyz"): digest(LIB / "lumi-eggcracker.pyz"), str(TMPFILES): digest(TMPFILES), str(UNIT): digest(UNIT), str(WATCHDOG_UNIT): digest(WATCHDOG_UNIT)}, "operator": operator.pw_name, "operator_uid": operator.pw_uid, "schema_version": "lumi-eggcracker.install.v5", "targets": [str(path) for path in TARGETS], "version": release["version"], "workload_group": group.gr_name, "workload_uid": account.pw_uid, "workload_user": account.pw_name}
|
| 423 |
write_new(STATE / "install-manifest.json", (json.dumps(manifest, sort_keys=True) + "\n").encode(), 0o600)
|
| 424 |
checked = run(["/usr/bin/systemctl", "daemon-reload"])
|
| 425 |
started_watchdog = run(["/usr/bin/systemctl", "enable", "--now", "lumi-eggcracker-watchdog.service"])
|
scripts/run_installer_p0.py
CHANGED
|
@@ -25,6 +25,7 @@ TARGETS = (
|
|
| 25 |
Path("/etc/lumi-eggcracker"),
|
| 26 |
Path("/etc/systemd/system/lumi-eggcracker.service"),
|
| 27 |
Path("/etc/systemd/system/lumi-eggcracker-watchdog.service"),
|
|
|
|
| 28 |
Path("/var/lib/lumi-eggcracker"),
|
| 29 |
Path("/run/lumi-eggcracker"),
|
| 30 |
Path("/run/lumi-eggcracker-watchdog"),
|
|
|
|
| 25 |
Path("/etc/lumi-eggcracker"),
|
| 26 |
Path("/etc/systemd/system/lumi-eggcracker.service"),
|
| 27 |
Path("/etc/systemd/system/lumi-eggcracker-watchdog.service"),
|
| 28 |
+
Path("/etc/tmpfiles.d/lumi-eggcracker.conf"),
|
| 29 |
Path("/var/lib/lumi-eggcracker"),
|
| 30 |
Path("/run/lumi-eggcracker"),
|
| 31 |
Path("/run/lumi-eggcracker-watchdog"),
|
scripts/uninstall.py
CHANGED
|
@@ -34,6 +34,7 @@ BIN = Path("/usr/local/bin/eggcracker")
|
|
| 34 |
ETC = Path("/etc/lumi-eggcracker")
|
| 35 |
UNIT = Path("/etc/systemd/system/lumi-eggcracker.service")
|
| 36 |
WATCHDOG_UNIT = Path("/etc/systemd/system/lumi-eggcracker-watchdog.service")
|
|
|
|
| 37 |
STATE = Path("/var/lib/lumi-eggcracker")
|
| 38 |
RUNTIME = Path("/run/lumi-eggcracker")
|
| 39 |
WATCHDOG_RUNTIME = Path("/run/lumi-eggcracker-watchdog")
|
|
@@ -193,7 +194,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 193 |
raise SystemExit("refusing uninstall because cgroups remained populated after stop")
|
| 194 |
reset_failed(SUPERVISOR)
|
| 195 |
reset_failed(WATCHDOG)
|
| 196 |
-
for path in (UNIT, WATCHDOG_UNIT, BIN, LIB, ETC, STATE, RUNTIME, WATCHDOG_RUNTIME):
|
| 197 |
if path.exists() and not path.is_symlink():
|
| 198 |
shutil.rmtree(path) if path.is_dir() else path.unlink()
|
| 199 |
if manifest.get("created_workload_user"):
|
|
|
|
| 34 |
ETC = Path("/etc/lumi-eggcracker")
|
| 35 |
UNIT = Path("/etc/systemd/system/lumi-eggcracker.service")
|
| 36 |
WATCHDOG_UNIT = Path("/etc/systemd/system/lumi-eggcracker-watchdog.service")
|
| 37 |
+
TMPFILES = Path("/etc/tmpfiles.d/lumi-eggcracker.conf")
|
| 38 |
STATE = Path("/var/lib/lumi-eggcracker")
|
| 39 |
RUNTIME = Path("/run/lumi-eggcracker")
|
| 40 |
WATCHDOG_RUNTIME = Path("/run/lumi-eggcracker-watchdog")
|
|
|
|
| 194 |
raise SystemExit("refusing uninstall because cgroups remained populated after stop")
|
| 195 |
reset_failed(SUPERVISOR)
|
| 196 |
reset_failed(WATCHDOG)
|
| 197 |
+
for path in (UNIT, WATCHDOG_UNIT, TMPFILES, BIN, LIB, ETC, STATE, RUNTIME, WATCHDOG_RUNTIME):
|
| 198 |
if path.exists() and not path.is_symlink():
|
| 199 |
shutil.rmtree(path) if path.is_dir() else path.unlink()
|
| 200 |
if manifest.get("created_workload_user"):
|
scripts/upgrade.py
CHANGED
|
@@ -143,16 +143,21 @@ def drain(operator: str, transaction: str) -> None:
|
|
| 143 |
def snapshot_files(manifest: dict[str, Any], backup: Path) -> dict[str, Any]:
|
| 144 |
files: dict[str, Any] = {}
|
| 145 |
paths = {Path(path) for path in manifest["files"]}
|
| 146 |
-
paths.update({installer.BIN, installer.LIB / "lumi-eggcracker.pyz", installer.ETC / "detector_catalogue.json", installer.ETC / "policy.json", installer.UNIT, installer.WATCHDOG_UNIT, STATE / "install-manifest.json"})
|
| 147 |
target = backup / "files"
|
| 148 |
target.mkdir(mode=0o700, parents=True)
|
| 149 |
for index, path in enumerate(sorted(paths, key=str)):
|
| 150 |
-
if path.is_symlink()
|
|
|
|
|
|
|
|
|
|
| 151 |
continue
|
|
|
|
|
|
|
| 152 |
stored = target / f"{index:03d}.bin"
|
| 153 |
shutil.copyfile(path, stored)
|
| 154 |
metadata = path.stat()
|
| 155 |
-
files[str(path)] = {"stored": stored.name, "mode": stat.S_IMODE(metadata.st_mode), "uid": metadata.st_uid, "gid": metadata.st_gid}
|
| 156 |
if RUNS.is_dir() and not RUNS.is_symlink():
|
| 157 |
shutil.copytree(RUNS, backup / "runs")
|
| 158 |
return files
|
|
@@ -161,6 +166,11 @@ def snapshot_files(manifest: dict[str, Any], backup: Path) -> dict[str, Any]:
|
|
| 161 |
def restore_snapshot(backup: Path, files: dict[str, Any]) -> None:
|
| 162 |
for raw_path, metadata in files.items():
|
| 163 |
path = Path(raw_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
stored = backup / "files" / str(metadata["stored"])
|
| 165 |
if not stored.is_file() or path.is_symlink():
|
| 166 |
raise RuntimeError(f"upgrade backup is incomplete for {path}")
|
|
@@ -225,12 +235,13 @@ def replace_install(release: dict[str, Any], operator: pwd.struct_passwd, manife
|
|
| 225 |
atomic_bytes(installer.ETC / "detector_catalogue.json", catalogue, 0o644)
|
| 226 |
policy = new_policy(release, operator, manifest)
|
| 227 |
atomic_bytes(installer.ETC / "policy.json", (json.dumps(policy, sort_keys=True) + "\n").encode())
|
|
|
|
| 228 |
atomic_bytes(installer.UNIT, installer._SERVICE_RELEASE.replace(b"Requires=lumi-eggcracker-watchdog.service\n\n", b"Requires=lumi-eggcracker-watchdog.service\nStartLimitIntervalSec=0\n\n"), 0o644)
|
| 229 |
atomic_bytes(installer.WATCHDOG_UNIT, installer.watchdog_service().replace(b"Before=lumi-eggcracker.service\n\n", b"Before=lumi-eggcracker.service\nStartLimitIntervalSec=0\n\n"), 0o644)
|
| 230 |
updated = {
|
| 231 |
"created_workload_group": bool(manifest.get("created_workload_group")),
|
| 232 |
"created_workload_user": bool(manifest.get("created_workload_user")),
|
| 233 |
-
"files": {str(path): digest(path) for path in (installer.BIN, installer.ETC / "detector_catalogue.json", installer.ETC / "policy.json", installer.LIB / "lumi-eggcracker.pyz", installer.UNIT, installer.WATCHDOG_UNIT)},
|
| 234 |
"operator": operator.pw_name,
|
| 235 |
"operator_uid": operator.pw_uid,
|
| 236 |
"schema_version": "lumi-eggcracker.install.v5",
|
|
@@ -266,6 +277,7 @@ def socket_ready(operator_gid: int) -> bool:
|
|
| 266 |
|
| 267 |
def start_services(operator: str) -> None:
|
| 268 |
operator_account = pwd.getpwnam(operator)
|
|
|
|
| 269 |
for unit in ("lumi-eggcracker-watchdog.service", "lumi-eggcracker.service"):
|
| 270 |
result = run(["/usr/bin/systemctl", "enable", "--now", unit])
|
| 271 |
if result.returncode:
|
|
@@ -314,6 +326,7 @@ def upgrade(args: argparse.Namespace) -> int:
|
|
| 314 |
descriptor = os.open(args.artifact, os.O_RDONLY | os.O_CLOEXEC | os.O_NOFOLLOW)
|
| 315 |
try:
|
| 316 |
release = installer.manifest_for(args.artifact, descriptor, args.expected_sha256)
|
|
|
|
| 317 |
transaction = secrets.token_hex(8)
|
| 318 |
backup = BACKUPS / transaction
|
| 319 |
backup.mkdir(mode=0o700, parents=True)
|
|
|
|
| 143 |
def snapshot_files(manifest: dict[str, Any], backup: Path) -> dict[str, Any]:
|
| 144 |
files: dict[str, Any] = {}
|
| 145 |
paths = {Path(path) for path in manifest["files"]}
|
| 146 |
+
paths.update({installer.BIN, installer.LIB / "lumi-eggcracker.pyz", installer.ETC / "detector_catalogue.json", installer.ETC / "policy.json", installer.TMPFILES, installer.UNIT, installer.WATCHDOG_UNIT, STATE / "install-manifest.json"})
|
| 147 |
target = backup / "files"
|
| 148 |
target.mkdir(mode=0o700, parents=True)
|
| 149 |
for index, path in enumerate(sorted(paths, key=str)):
|
| 150 |
+
if path.is_symlink():
|
| 151 |
+
raise RuntimeError(f"upgrade snapshot target is a symlink: {path}")
|
| 152 |
+
if not path.exists():
|
| 153 |
+
files[str(path)] = {"absent": True}
|
| 154 |
continue
|
| 155 |
+
if not path.is_file():
|
| 156 |
+
raise RuntimeError(f"upgrade snapshot target is not a file: {path}")
|
| 157 |
stored = target / f"{index:03d}.bin"
|
| 158 |
shutil.copyfile(path, stored)
|
| 159 |
metadata = path.stat()
|
| 160 |
+
files[str(path)] = {"absent": False, "stored": stored.name, "mode": stat.S_IMODE(metadata.st_mode), "uid": metadata.st_uid, "gid": metadata.st_gid}
|
| 161 |
if RUNS.is_dir() and not RUNS.is_symlink():
|
| 162 |
shutil.copytree(RUNS, backup / "runs")
|
| 163 |
return files
|
|
|
|
| 166 |
def restore_snapshot(backup: Path, files: dict[str, Any]) -> None:
|
| 167 |
for raw_path, metadata in files.items():
|
| 168 |
path = Path(raw_path)
|
| 169 |
+
if metadata.get("absent") is True:
|
| 170 |
+
if path.is_symlink() or (path.exists() and not path.is_file()):
|
| 171 |
+
raise RuntimeError(f"upgrade rollback target changed type: {path}")
|
| 172 |
+
path.unlink(missing_ok=True)
|
| 173 |
+
continue
|
| 174 |
stored = backup / "files" / str(metadata["stored"])
|
| 175 |
if not stored.is_file() or path.is_symlink():
|
| 176 |
raise RuntimeError(f"upgrade backup is incomplete for {path}")
|
|
|
|
| 235 |
atomic_bytes(installer.ETC / "detector_catalogue.json", catalogue, 0o644)
|
| 236 |
policy = new_policy(release, operator, manifest)
|
| 237 |
atomic_bytes(installer.ETC / "policy.json", (json.dumps(policy, sort_keys=True) + "\n").encode())
|
| 238 |
+
atomic_bytes(installer.TMPFILES, installer.tmpfiles(), 0o644)
|
| 239 |
atomic_bytes(installer.UNIT, installer._SERVICE_RELEASE.replace(b"Requires=lumi-eggcracker-watchdog.service\n\n", b"Requires=lumi-eggcracker-watchdog.service\nStartLimitIntervalSec=0\n\n"), 0o644)
|
| 240 |
atomic_bytes(installer.WATCHDOG_UNIT, installer.watchdog_service().replace(b"Before=lumi-eggcracker.service\n\n", b"Before=lumi-eggcracker.service\nStartLimitIntervalSec=0\n\n"), 0o644)
|
| 241 |
updated = {
|
| 242 |
"created_workload_group": bool(manifest.get("created_workload_group")),
|
| 243 |
"created_workload_user": bool(manifest.get("created_workload_user")),
|
| 244 |
+
"files": {str(path): digest(path) for path in (installer.BIN, installer.ETC / "detector_catalogue.json", installer.ETC / "policy.json", installer.LIB / "lumi-eggcracker.pyz", installer.TMPFILES, installer.UNIT, installer.WATCHDOG_UNIT)},
|
| 245 |
"operator": operator.pw_name,
|
| 246 |
"operator_uid": operator.pw_uid,
|
| 247 |
"schema_version": "lumi-eggcracker.install.v5",
|
|
|
|
| 277 |
|
| 278 |
def start_services(operator: str) -> None:
|
| 279 |
operator_account = pwd.getpwnam(operator)
|
| 280 |
+
installer.ensure_netns_runtime()
|
| 281 |
for unit in ("lumi-eggcracker-watchdog.service", "lumi-eggcracker.service"):
|
| 282 |
result = run(["/usr/bin/systemctl", "enable", "--now", unit])
|
| 283 |
if result.returncode:
|
|
|
|
| 326 |
descriptor = os.open(args.artifact, os.O_RDONLY | os.O_CLOEXEC | os.O_NOFOLLOW)
|
| 327 |
try:
|
| 328 |
release = installer.manifest_for(args.artifact, descriptor, args.expected_sha256)
|
| 329 |
+
start_services(operator.pw_name)
|
| 330 |
transaction = secrets.token_hex(8)
|
| 331 |
backup = BACKUPS / transaction
|
| 332 |
backup.mkdir(mode=0o700, parents=True)
|
scripts/verify_uninstalled.py
CHANGED
|
@@ -28,6 +28,7 @@ PATHS = (
|
|
| 28 |
Path("/usr/local/lib/lumi-eggcracker"), Path("/usr/local/bin/eggcracker"),
|
| 29 |
Path("/etc/lumi-eggcracker"), Path("/etc/systemd/system/lumi-eggcracker.service"),
|
| 30 |
Path("/etc/systemd/system/lumi-eggcracker-watchdog.service"),
|
|
|
|
| 31 |
Path("/var/lib/lumi-eggcracker"), Path("/run/lumi-eggcracker"),
|
| 32 |
Path("/run/lumi-eggcracker-watchdog"),
|
| 33 |
)
|
|
|
|
| 28 |
Path("/usr/local/lib/lumi-eggcracker"), Path("/usr/local/bin/eggcracker"),
|
| 29 |
Path("/etc/lumi-eggcracker"), Path("/etc/systemd/system/lumi-eggcracker.service"),
|
| 30 |
Path("/etc/systemd/system/lumi-eggcracker-watchdog.service"),
|
| 31 |
+
Path("/etc/tmpfiles.d/lumi-eggcracker.conf"),
|
| 32 |
Path("/var/lib/lumi-eggcracker"), Path("/run/lumi-eggcracker"),
|
| 33 |
Path("/run/lumi-eggcracker-watchdog"),
|
| 34 |
)
|
src/lumi_eggcracker/containment_probe.py
CHANGED
|
@@ -56,6 +56,7 @@ INSTALL_TARGETS = (
|
|
| 56 |
Path("/run/lumi-eggcracker-watchdog"),
|
| 57 |
Path("/etc/systemd/system/lumi-eggcracker.service"),
|
| 58 |
Path("/etc/systemd/system/lumi-eggcracker-watchdog.service"),
|
|
|
|
| 59 |
)
|
| 60 |
SUCCESS_KEYS = frozenset(
|
| 61 |
{
|
|
|
|
| 56 |
Path("/run/lumi-eggcracker-watchdog"),
|
| 57 |
Path("/etc/systemd/system/lumi-eggcracker.service"),
|
| 58 |
Path("/etc/systemd/system/lumi-eggcracker-watchdog.service"),
|
| 59 |
+
Path("/etc/tmpfiles.d/lumi-eggcracker.conf"),
|
| 60 |
)
|
| 61 |
SUCCESS_KEYS = frozenset(
|
| 62 |
{
|
src/lumi_eggcracker/supervisor.py
CHANGED
|
@@ -2744,6 +2744,7 @@ class Supervisor:
|
|
| 2744 |
"/etc/lumi-eggcracker/policy.json",
|
| 2745 |
"/etc/systemd/system/lumi-eggcracker.service",
|
| 2746 |
"/etc/systemd/system/lumi-eggcracker-watchdog.service",
|
|
|
|
| 2747 |
}
|
| 2748 |
if not isinstance(files, dict) or set(files) != expected_paths:
|
| 2749 |
return {"state": "DRIFT", "journal": False, "files_match": False}
|
|
|
|
| 2744 |
"/etc/lumi-eggcracker/policy.json",
|
| 2745 |
"/etc/systemd/system/lumi-eggcracker.service",
|
| 2746 |
"/etc/systemd/system/lumi-eggcracker-watchdog.service",
|
| 2747 |
+
"/etc/tmpfiles.d/lumi-eggcracker.conf",
|
| 2748 |
}
|
| 2749 |
if not isinstance(files, dict) or set(files) != expected_paths:
|
| 2750 |
return {"state": "DRIFT", "journal": False, "files_match": False}
|
tests/test_installer_security.py
CHANGED
|
@@ -78,3 +78,17 @@ class InstallerSecurityTests(unittest.TestCase):
|
|
| 78 |
self.assertIn("/proc/self/fd/{artifact_descriptor}", installer)
|
| 79 |
self.assertIn("read_stable_regular", installer)
|
| 80 |
self.assertIn("artifact_source_commit", installer)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
self.assertIn("/proc/self/fd/{artifact_descriptor}", installer)
|
| 79 |
self.assertIn("read_stable_regular", installer)
|
| 80 |
self.assertIn("artifact_source_commit", installer)
|
| 81 |
+
|
| 82 |
+
def test_install_tracks_cold_boot_network_namespace_runtime(self) -> None:
|
| 83 |
+
installer = INSTALLER.read_text(encoding="utf-8")
|
| 84 |
+
upgrader = (ROOT / "scripts" / "upgrade.py").read_text(encoding="utf-8")
|
| 85 |
+
uninstaller = UNINSTALLER.read_text(encoding="utf-8")
|
| 86 |
+
verifier = (ROOT / "scripts" / "verify_uninstalled.py").read_text(
|
| 87 |
+
encoding="utf-8"
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
for value in (installer, upgrader, uninstaller, verifier):
|
| 91 |
+
self.assertIn("/etc/tmpfiles.d/lumi-eggcracker.conf", value)
|
| 92 |
+
self.assertIn("d /run/netns 0755 root root -", installer)
|
| 93 |
+
self.assertIn("ensure_netns_runtime()", installer)
|
| 94 |
+
self.assertIn("installer.ensure_netns_runtime()", upgrader)
|