Keep rotated credentials reproducible and verify expired allowed identity
This commit is contained in:
+17
-8
@@ -98,6 +98,17 @@ def certificate(name, replace=False):
|
||||
(dest / "combined.pem").chmod(0o644)
|
||||
|
||||
|
||||
def write_roles():
|
||||
# Generated first-init SQL must follow rotated password files as well as a
|
||||
# fresh bootstrap. Existing DB roles are changed only by operator rotation.
|
||||
statements = [
|
||||
f"CREATE ROLE {role} LOGIN PASSWORD '{(PRIVATE / (role + '_db_password')).read_text().strip()}';"
|
||||
for role in ("api", "worker", "dispatcher")
|
||||
]
|
||||
(PRIVATE / "db_roles.sql").write_text("\n".join(statements))
|
||||
(PRIVATE / "db_roles.sql").chmod(0o644)
|
||||
|
||||
|
||||
def main():
|
||||
os.umask(0o077)
|
||||
for folder in (PRIVATE, OPERATOR):
|
||||
@@ -171,7 +182,11 @@ def main():
|
||||
],
|
||||
"actions": ["Admin", "Read", "Write", "List"]
|
||||
if role == "admin"
|
||||
else (["Read:security-study", "Write:security-study", "List:security-study"] if role == "study_wide" else ["Read:messenger", "Write:messenger", "List:messenger"]),
|
||||
else (
|
||||
["Read:security-study", "Write:security-study", "List:security-study"]
|
||||
if role == "study_wide"
|
||||
else ["Read:messenger", "Write:messenger", "List:messenger"]
|
||||
),
|
||||
}
|
||||
)
|
||||
(PRIVATE / "s3_config").write_text(json.dumps({"identities": identities}))
|
||||
@@ -226,13 +241,7 @@ def main():
|
||||
)
|
||||
write(PRIVATE / "admin_s3_access_key", value("admin_s3_access"))
|
||||
write(PRIVATE / "admin_s3_secret_key", value("admin_s3_secret"))
|
||||
write(
|
||||
PRIVATE / "db_roles.sql",
|
||||
"\n".join(
|
||||
f"CREATE ROLE {role} LOGIN PASSWORD '{value(role + '_db_password')}';"
|
||||
for role in ("api", "worker", "dispatcher")
|
||||
),
|
||||
)
|
||||
write_roles()
|
||||
gateways = {
|
||||
"api": {"port": 9443, "upstream": 8080, "allowed": ["lb"]},
|
||||
"broker": {
|
||||
|
||||
@@ -65,6 +65,7 @@ def main():
|
||||
)
|
||||
path = ROOT / "secrets/worker_db_password"
|
||||
path.write_text(password)
|
||||
bootstrap.write_roles()
|
||||
seed_path = ROOT / "secrets/bao_seed.json"
|
||||
seed = json.loads(seed_path.read_text())
|
||||
seed["worker"]["DATABASE_URL"] = (
|
||||
|
||||
@@ -146,6 +146,7 @@ def test_expired_certificate_rejected(tcp_boundary, tmp_path):
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
assert exchange(tcp_boundary[0], client("lb")) == b"positive"
|
||||
cert = tmp_path / "expired.pem"
|
||||
subprocess.run(
|
||||
[
|
||||
@@ -153,7 +154,7 @@ def test_expired_certificate_rejected(tcp_boundary, tmp_path):
|
||||
"x509",
|
||||
"-req",
|
||||
"-in",
|
||||
str(ROOT / "operator-private/worker.csr"),
|
||||
str(ROOT / "operator-private/lb.csr"),
|
||||
"-CA",
|
||||
str(ROOT / "operator-private/ca.pem"),
|
||||
"-CAkey",
|
||||
@@ -163,7 +164,7 @@ def test_expired_certificate_rejected(tcp_boundary, tmp_path):
|
||||
"-days",
|
||||
"0",
|
||||
"-extfile",
|
||||
str(ROOT / "operator-private/worker.ext"),
|
||||
str(ROOT / "operator-private/lb.ext"),
|
||||
"-out",
|
||||
str(cert),
|
||||
],
|
||||
@@ -172,7 +173,7 @@ def test_expired_certificate_rejected(tcp_boundary, tmp_path):
|
||||
)
|
||||
time.sleep(1)
|
||||
ctx = client()
|
||||
ctx.load_cert_chain(cert, ROOT / "secrets/pki/worker/key.pem")
|
||||
ctx.load_cert_chain(cert, ROOT / "secrets/pki/lb/key.pem")
|
||||
try:
|
||||
result = exchange(tcp_boundary[0], ctx)
|
||||
except (OSError, ssl.SSLError):
|
||||
|
||||
Reference in New Issue
Block a user