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)
|
(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():
|
def main():
|
||||||
os.umask(0o077)
|
os.umask(0o077)
|
||||||
for folder in (PRIVATE, OPERATOR):
|
for folder in (PRIVATE, OPERATOR):
|
||||||
@@ -171,7 +182,11 @@ def main():
|
|||||||
],
|
],
|
||||||
"actions": ["Admin", "Read", "Write", "List"]
|
"actions": ["Admin", "Read", "Write", "List"]
|
||||||
if role == "admin"
|
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}))
|
(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_access_key", value("admin_s3_access"))
|
||||||
write(PRIVATE / "admin_s3_secret_key", value("admin_s3_secret"))
|
write(PRIVATE / "admin_s3_secret_key", value("admin_s3_secret"))
|
||||||
write(
|
write_roles()
|
||||||
PRIVATE / "db_roles.sql",
|
|
||||||
"\n".join(
|
|
||||||
f"CREATE ROLE {role} LOGIN PASSWORD '{value(role + '_db_password')}';"
|
|
||||||
for role in ("api", "worker", "dispatcher")
|
|
||||||
),
|
|
||||||
)
|
|
||||||
gateways = {
|
gateways = {
|
||||||
"api": {"port": 9443, "upstream": 8080, "allowed": ["lb"]},
|
"api": {"port": 9443, "upstream": 8080, "allowed": ["lb"]},
|
||||||
"broker": {
|
"broker": {
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ def main():
|
|||||||
)
|
)
|
||||||
path = ROOT / "secrets/worker_db_password"
|
path = ROOT / "secrets/worker_db_password"
|
||||||
path.write_text(password)
|
path.write_text(password)
|
||||||
|
bootstrap.write_roles()
|
||||||
seed_path = ROOT / "secrets/bao_seed.json"
|
seed_path = ROOT / "secrets/bao_seed.json"
|
||||||
seed = json.loads(seed_path.read_text())
|
seed = json.loads(seed_path.read_text())
|
||||||
seed["worker"]["DATABASE_URL"] = (
|
seed["worker"]["DATABASE_URL"] = (
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ def test_expired_certificate_rejected(tcp_boundary, tmp_path):
|
|||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
assert exchange(tcp_boundary[0], client("lb")) == b"positive"
|
||||||
cert = tmp_path / "expired.pem"
|
cert = tmp_path / "expired.pem"
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
@@ -153,7 +154,7 @@ def test_expired_certificate_rejected(tcp_boundary, tmp_path):
|
|||||||
"x509",
|
"x509",
|
||||||
"-req",
|
"-req",
|
||||||
"-in",
|
"-in",
|
||||||
str(ROOT / "operator-private/worker.csr"),
|
str(ROOT / "operator-private/lb.csr"),
|
||||||
"-CA",
|
"-CA",
|
||||||
str(ROOT / "operator-private/ca.pem"),
|
str(ROOT / "operator-private/ca.pem"),
|
||||||
"-CAkey",
|
"-CAkey",
|
||||||
@@ -163,7 +164,7 @@ def test_expired_certificate_rejected(tcp_boundary, tmp_path):
|
|||||||
"-days",
|
"-days",
|
||||||
"0",
|
"0",
|
||||||
"-extfile",
|
"-extfile",
|
||||||
str(ROOT / "operator-private/worker.ext"),
|
str(ROOT / "operator-private/lb.ext"),
|
||||||
"-out",
|
"-out",
|
||||||
str(cert),
|
str(cert),
|
||||||
],
|
],
|
||||||
@@ -172,7 +173,7 @@ def test_expired_certificate_rejected(tcp_boundary, tmp_path):
|
|||||||
)
|
)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
ctx = client()
|
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:
|
try:
|
||||||
result = exchange(tcp_boundary[0], ctx)
|
result = exchange(tcp_boundary[0], ctx)
|
||||||
except (OSError, ssl.SSLError):
|
except (OSError, ssl.SSLError):
|
||||||
|
|||||||
Reference in New Issue
Block a user