ЛР 7: Безопасность, mTLS и OpenBao
Skeleton contracts / contracts (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Provision separate MinIO application users and bucket-scoped policies."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
|
||||
MC = "/usr/local/bin/mc"
|
||||
CONFIG = Path("/tmp/mc")
|
||||
|
||||
|
||||
def mc(*args, check=True):
|
||||
result = subprocess.run(
|
||||
[MC, "--config-dir", str(CONFIG), *args],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
if check and result.returncode:
|
||||
detail = result.stderr.strip()
|
||||
raise RuntimeError(
|
||||
"MinIO application identity provisioning failed"
|
||||
+ (": " + detail if detail else "")
|
||||
) from None
|
||||
return result.returncode == 0
|
||||
|
||||
|
||||
def main():
|
||||
ca_file = Path(os.environ["INTERNAL_CA_CERT"])
|
||||
ca_directory = CONFIG / "certs" / "CAs"
|
||||
ca_directory.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(ca_file, ca_directory / "internal-ca.crt")
|
||||
mc(
|
||||
"alias", "set", "local", os.environ["S3_ENDPOINT"],
|
||||
os.environ["MINIO_ROOT_USER"], os.environ["MINIO_ROOT_PASSWORD"],
|
||||
)
|
||||
|
||||
for prefix in ("API", "WORKER"):
|
||||
user = os.environ["S3_" + prefix + "_ACCESS_KEY"]
|
||||
password = os.environ["S3_" + prefix + "_SECRET_KEY"]
|
||||
if not mc("admin", "user", "info", "local", user, check=False):
|
||||
mc("admin", "user", "add", "local", user, password)
|
||||
mc("admin", "policy", "attach", "local", "readwrite", "--user", user)
|
||||
print("PASS: separate MinIO application users and readwrite policies provisioned")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user