forked from mtusi2026/mtusi2026lab7
feat(security): add operator rotation and recovery commands
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Operator-only, idempotent SQL roles and scoped S3 accounts."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import ssl
|
||||
import time
|
||||
|
||||
@@ -14,6 +15,12 @@ from scripts.bootstrap_security import OPERATOR, TRUST
|
||||
from scripts.stand import compose
|
||||
|
||||
|
||||
def attach_policy(client, policy, user):
|
||||
attached = json.loads(client.user_info(user)).get("policyName", "") or ""
|
||||
if policy not in attached.split(","):
|
||||
client.attach_policy([policy], user=user)
|
||||
|
||||
|
||||
def postgres(raw):
|
||||
# The bootstrap SQL channel is the server's local Unix socket. No password
|
||||
# or SQL literal is placed in argv; stdin and output are never recorded.
|
||||
@@ -190,13 +197,13 @@ def s3(raw):
|
||||
)
|
||||
credentials = StaticProvider(raw["s3_root_user"], raw["s3_root_password"])
|
||||
admin = MinioAdmin(
|
||||
"localhost:9007",
|
||||
"localhost:" + os.getenv("S3_ADMIN_PORT", "9007"),
|
||||
credentials=credentials,
|
||||
secure=True,
|
||||
http_client=pool,
|
||||
)
|
||||
client = Minio(
|
||||
"localhost:9007",
|
||||
"localhost:" + os.getenv("S3_ADMIN_PORT", "9007"),
|
||||
credentials=credentials,
|
||||
secure=True,
|
||||
http_client=pool,
|
||||
@@ -248,9 +255,7 @@ def s3(raw):
|
||||
policy={"Version": "2012-10-17", "Statement": statements},
|
||||
)
|
||||
admin.user_add(values["S3_ACCESS_KEY"], values["S3_SECRET_KEY"])
|
||||
admin.attach_policy(
|
||||
["messenger-" + role], user=values["S3_ACCESS_KEY"]
|
||||
)
|
||||
attach_policy(admin, "messenger-" + role, values["S3_ACCESS_KEY"])
|
||||
pool.clear()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user