feat(security): add operator rotation and recovery commands
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-11-20 19:02:00 +03:00
parent 1dd020d060
commit f2ea9d65a8
22 changed files with 983 additions and 46 deletions
+44
View File
@@ -1,4 +1,7 @@
import io
import json
import ssl
import sys
import time
import pytest
@@ -58,3 +61,44 @@ def test_bootstrap_repairs_config_without_changing_credentials(
assert config.read_bytes() == expected
assert bootstrap.OPERATOR.stat().st_mode & 0o777 == 0o700
assert private.stat().st_mode & 0o777 == 0o600
def test_operator_leaf_install_preserves_pem_and_matching_pair(
tmp_path, monkeypatch
):
from cryptography import x509
from scripts.bootstrap_security import (
key_bytes,
make_root,
public,
sign_leaf,
)
from scripts.credentials import INSTALL
root_key, root_cert = make_root()
key, leaf = sign_leaf(root_key, root_cert, "worker", ["worker"])
payload = {
"certificate": public(leaf).decode(),
"private_key": key_bytes(key).decode(),
"ca_chain": [public(root_cert).decode()],
}
monkeypatch.setattr(sys, "stdin", io.StringIO(json.dumps(payload)))
code = INSTALL.replace(
"pathlib.Path('/run/identity')",
"pathlib.Path(" + repr(str(tmp_path)) + ")",
)
exec(compile(code, "operator-install-test", "exec"), {})
current = tmp_path / "current"
assert current.is_symlink()
assert (
len(
x509.load_pem_x509_certificates(
(current / "cert.pem").read_bytes()
)
)
== 2
)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(current / "cert.pem", current / "key.pem")
assert (current / "key.pem").stat().st_mode & 0o777 == 0o600