feat(security): add scoped identities, TLS boundaries and OpenBao bootstrap
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
"""Explicit local operator bootstrap; an ordinary API restart needs no unseal."""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
from scripts.bao_operator import Operator
|
||||
from scripts.bootstrap_security import OPERATOR, generate
|
||||
from scripts.prepare_dependencies import main as dependencies
|
||||
from scripts.prepare_dependencies import postgres
|
||||
from scripts.stand import ROOT, command, compose, ready
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--build", action="store_true")
|
||||
args = parser.parse_args()
|
||||
generate()
|
||||
os.environ.setdefault("VCS_REF", command(["git", "rev-parse", "HEAD"]))
|
||||
if args.build:
|
||||
subprocess.run(
|
||||
["docker", "compose", "build", "api", "s3"], cwd=ROOT, check=True
|
||||
)
|
||||
compose("run", "--rm", "--no-deps", "identity-init")
|
||||
compose(
|
||||
"up", "-d", "--no-deps", "openbao", "postgres", "cache", "broker", "s3"
|
||||
)
|
||||
operator = Operator()
|
||||
try:
|
||||
for attempt in range(90):
|
||||
try:
|
||||
operator.call("GET", "sys/init")
|
||||
break
|
||||
except Exception:
|
||||
if attempt == 89:
|
||||
raise RuntimeError(
|
||||
"OpenBao TLS startup unavailable"
|
||||
) from None
|
||||
time.sleep(1)
|
||||
operator.init()
|
||||
operator.unseal()
|
||||
operator.configure()
|
||||
finally:
|
||||
operator.close()
|
||||
agents = [
|
||||
"identity-" + r
|
||||
for r in [
|
||||
"openbao",
|
||||
"api",
|
||||
"worker",
|
||||
"relay",
|
||||
"observer",
|
||||
"reconciler",
|
||||
"postgres",
|
||||
"cache",
|
||||
"broker",
|
||||
"s3",
|
||||
"otel",
|
||||
"prometheus",
|
||||
"loki",
|
||||
"tempo",
|
||||
"grafana",
|
||||
]
|
||||
]
|
||||
compose("up", "-d", "--no-deps", *agents)
|
||||
compose("up", "-d", "--no-deps", "postgres-tls")
|
||||
compose(
|
||||
"--profile", "maintenance", "up", "-d", "--no-deps", "identity-migrate"
|
||||
)
|
||||
try:
|
||||
compose(
|
||||
"--profile", "maintenance", "run", "--rm", "--no-deps", "migrate"
|
||||
)
|
||||
finally:
|
||||
compose("--profile", "maintenance", "stop", "identity-migrate")
|
||||
postgres(json.loads((OPERATOR / "service-secrets.json").read_text()))
|
||||
compose("up", "-d", "--no-deps", "telemetry-init")
|
||||
compose("wait", "telemetry-init")
|
||||
backends = ["otel", "prometheus", "loki", "tempo", "grafana", "lb"]
|
||||
compose("up", "-d", "--no-deps", *backends)
|
||||
gates = [
|
||||
r + "-tls"
|
||||
for r in [
|
||||
"postgres",
|
||||
"s3",
|
||||
"cache",
|
||||
"broker",
|
||||
"otel",
|
||||
"prometheus",
|
||||
"loki",
|
||||
"tempo",
|
||||
"grafana",
|
||||
"lb",
|
||||
]
|
||||
]
|
||||
compose("up", "-d", "--no-deps", *gates, "identity-lb")
|
||||
dependencies()
|
||||
compose(
|
||||
"up",
|
||||
"-d",
|
||||
"--no-deps",
|
||||
"api",
|
||||
"relay",
|
||||
"worker",
|
||||
"observer",
|
||||
"reconciler",
|
||||
)
|
||||
ready(timeout=120)
|
||||
print("Secure stand ready at https://localhost:8443; values remain local")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user