forked from mtusi2026/mtusi2026lab7
fix(security): enforce S3 boundaries and configure persistent audit
This commit is contained in:
+19
-21
@@ -72,16 +72,25 @@ class Operator:
|
||||
|
||||
def unseal(self):
|
||||
state = self.call("GET", "sys/seal-status")
|
||||
if not state["sealed"]:
|
||||
return
|
||||
for index in [1, 2]:
|
||||
share = json.loads(
|
||||
(OPERATOR / ("unseal-" + str(index) + ".json")).read_text()
|
||||
)
|
||||
state = self.call("POST", "sys/unseal", {"key": share["key"]})
|
||||
if not state["sealed"]:
|
||||
if state["sealed"]:
|
||||
for index in [1, 2]:
|
||||
share = json.loads(
|
||||
(OPERATOR / ("unseal-" + str(index) + ".json")).read_text()
|
||||
)
|
||||
state = self.call("POST", "sys/unseal", {"key": share["key"]})
|
||||
if not state["sealed"]:
|
||||
break
|
||||
else:
|
||||
raise RuntimeError("Unseal threshold not reached")
|
||||
# Unsealed Raft still needs to elect the active node and load mounts
|
||||
# and declarative audit devices. Do not retry bootstrap mutations.
|
||||
deadline = time.monotonic() + 60
|
||||
while time.monotonic() < deadline:
|
||||
response = self.http.get("sys/health")
|
||||
if response.status_code == 200:
|
||||
return
|
||||
raise RuntimeError("Unseal threshold not reached")
|
||||
time.sleep(0.5)
|
||||
raise TimeoutError("Unsealed OpenBao did not become active")
|
||||
|
||||
def authenticate(self):
|
||||
cached = OPERATOR / "operator-token.json"
|
||||
@@ -264,18 +273,7 @@ class Operator:
|
||||
)
|
||||
audit = root("GET", "sys/audit")
|
||||
audit = audit.get("data", audit)
|
||||
if "file/" not in audit:
|
||||
root(
|
||||
"PUT",
|
||||
"sys/audit/file",
|
||||
{
|
||||
"type": "file",
|
||||
"options": {
|
||||
"file_path": "/data/audit/audit.log",
|
||||
"mode": "0600",
|
||||
},
|
||||
},
|
||||
)
|
||||
assert "file/" in audit, "Declarative persistent audit must be enabled"
|
||||
created = root(
|
||||
"POST",
|
||||
"auth/token/create-orphan",
|
||||
|
||||
@@ -85,7 +85,7 @@ def admin():
|
||||
return (
|
||||
raw,
|
||||
MinioAdmin(
|
||||
"localhost:" + os.getenv("S3_ADMIN_PORT", "9007"),
|
||||
endpoint="localhost:" + os.getenv("S3_ADMIN_PORT", "9007"),
|
||||
credentials=StaticProvider(
|
||||
raw["s3_root_user"], raw["s3_root_password"]
|
||||
),
|
||||
|
||||
@@ -197,7 +197,7 @@ def s3(raw):
|
||||
)
|
||||
credentials = StaticProvider(raw["s3_root_user"], raw["s3_root_password"])
|
||||
admin = MinioAdmin(
|
||||
"localhost:" + os.getenv("S3_ADMIN_PORT", "9007"),
|
||||
endpoint="localhost:" + os.getenv("S3_ADMIN_PORT", "9007"),
|
||||
credentials=credentials,
|
||||
secure=True,
|
||||
http_client=pool,
|
||||
|
||||
Reference in New Issue
Block a user