forked from mtusi2026/mtusi2026lab7
feat(security): add operator rotation and recovery commands
This commit is contained in:
@@ -270,7 +270,27 @@ def generate():
|
||||
).not_valid_after_utc
|
||||
< datetime.now(UTC) + timedelta(hours=1)
|
||||
)
|
||||
if not (directory / "key.pem").exists() or renew_operator:
|
||||
renew_bootstrap = (
|
||||
role != "operator"
|
||||
and (directory / "cert.pem").exists()
|
||||
and x509.load_pem_x509_certificate(
|
||||
(directory / "cert.pem").read_bytes()
|
||||
).not_valid_after_utc
|
||||
< datetime.now(UTC) + timedelta(minutes=5)
|
||||
)
|
||||
wrong_issuer = (
|
||||
directory / "cert.pem"
|
||||
).exists() and x509.load_pem_x509_certificate(
|
||||
(directory / "cert.pem").read_bytes()
|
||||
).issuer != cert.subject
|
||||
# Only this explicit operator command has the offline CA. Agents
|
||||
# cannot refresh a bootstrap credential by themselves after expiry.
|
||||
if (
|
||||
not (directory / "key.pem").exists()
|
||||
or renew_operator
|
||||
or renew_bootstrap
|
||||
or wrong_issuer
|
||||
):
|
||||
leaf_key, leaf = sign_leaf(
|
||||
key,
|
||||
cert,
|
||||
|
||||
Reference in New Issue
Block a user