forked from mtusi2026/mtusi2026lab7
fix(security): enforce S3 boundaries and configure persistent audit
This commit is contained in:
+2
-1
@@ -16,7 +16,8 @@ ARG VCS_REF=unknown
|
||||
LABEL org.opencontainers.image.revision=$VCS_REF
|
||||
WORKDIR /app
|
||||
ENV PATH="/app/.venv/bin:$PATH" PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 APP_HOST=0.0.0.0 APP_PORT=8080
|
||||
RUN groupadd --gid 10001 app && useradd --uid 10001 --gid app --no-create-home app
|
||||
RUN groupadd --gid 10001 app && useradd --uid 10001 --gid app --no-create-home app \
|
||||
&& python -m pip uninstall -y pip
|
||||
COPY --from=builder /app/.venv /app/.venv
|
||||
COPY --from=gateway /out/tls-gateway /usr/local/bin/tls-gateway
|
||||
COPY src /app/src
|
||||
|
||||
@@ -552,6 +552,7 @@ services:
|
||||
- ALL
|
||||
cap_add:
|
||||
- CHOWN
|
||||
- FOWNER
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
cpus: 0.1
|
||||
@@ -1441,6 +1442,7 @@ services:
|
||||
- ALL
|
||||
cap_add:
|
||||
- CHOWN
|
||||
- FOWNER
|
||||
- DAC_OVERRIDE
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
|
||||
@@ -29,7 +29,7 @@ Native listener каждого сервиса доступен только на
|
||||
|
||||
`make up` выполняет явные шаги оператора. Root CA private key находится в `operator/` (0700, файлы 0600) и не монтируется в контейнеры. Root CA — 365 дней; intermediate — 30 дней, его ключ создаётся внутри OpenBao. Bootstrap cert сервиса — 30 минут, доступен только собственному agent; рабочий ключ сохраняется в собственном named volume (0700/0600). Обычный рестарт API использует продолжавший работать отдельный agent.
|
||||
|
||||
OpenBao работает с persistent file storage, вне dev-mode. Init создаёт 3 shares, threshold 2; файлы остаются у оператора, не монтируются в Bao/apps. В учебном стенде один оператор хранит все три защищённых файла; разделение между независимыми держателями не моделируется. Первичный root token используется только для установки auth/policies/PKI/KV/audit, затем отзывается и удаляется. У оператора cert-auth с отдельной policy и коротким token.
|
||||
OpenBao работает с persistent single-node Raft storage, вне dev-mode. Init создаёт 3 shares, threshold 2; файлы остаются у оператора, не монтируются в Bao/apps. В учебном стенде один оператор хранит все три защищённых файла; разделение между независимыми держателями не моделируется. Первичный root token используется только для установки auth/policies/PKI/KV/audit, затем отзывается и удаляется. У оператора cert-auth с отдельной policy и коротким token.
|
||||
|
||||
Каждая роль получает только собственные KV и PKI разрешения. Agent опрашивает Bao каждые 15 с, обновляет leaf до истечения, сохраняет пары через атомарную смену каталога; snapshot secrets имеет конечный срок. После expiry запросы/новые подключения завершаются контролируемым отказом. Длительная остановка/seal Bao требует явного operator recovery; статического бессрочного секрета для автоматического обхода нет.
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,124 @@
|
||||
{
|
||||
"complete": false,
|
||||
"tls": [
|
||||
{
|
||||
"host": "api",
|
||||
"port": 8443,
|
||||
"address": "172.23.0.33",
|
||||
"authorized": true,
|
||||
"no_certificate_denied": true,
|
||||
"foreign_ca_denied": true,
|
||||
"trusted_wrong_identity_denied": true
|
||||
},
|
||||
{
|
||||
"host": "api",
|
||||
"port": 8443,
|
||||
"address": "172.23.0.34",
|
||||
"authorized": true,
|
||||
"no_certificate_denied": true,
|
||||
"foreign_ca_denied": true,
|
||||
"trusted_wrong_identity_denied": true
|
||||
},
|
||||
{
|
||||
"host": "otel",
|
||||
"port": 4438,
|
||||
"address": null,
|
||||
"authorized": true,
|
||||
"no_certificate_denied": true,
|
||||
"foreign_ca_denied": true,
|
||||
"trusted_wrong_identity_denied": true
|
||||
},
|
||||
{
|
||||
"host": "broker",
|
||||
"port": 6380,
|
||||
"address": null,
|
||||
"authorized": true,
|
||||
"no_certificate_denied": true,
|
||||
"foreign_ca_denied": true,
|
||||
"trusted_wrong_identity_denied": true
|
||||
}
|
||||
],
|
||||
"bypass": [
|
||||
{
|
||||
"host": "api",
|
||||
"port": 8080,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "postgres",
|
||||
"port": 5432,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "broker",
|
||||
"port": 6379,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "cache",
|
||||
"port": 6379,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "s3",
|
||||
"port": 9000,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "otel",
|
||||
"port": 4318,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "otel",
|
||||
"port": 8889,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "prometheus",
|
||||
"port": 9090,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "loki",
|
||||
"port": 3100,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "tempo",
|
||||
"port": 3200,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "grafana",
|
||||
"port": 3000,
|
||||
"closed": true
|
||||
},
|
||||
{
|
||||
"host": "lb",
|
||||
"port": 8404,
|
||||
"closed": true
|
||||
}
|
||||
],
|
||||
"database": {
|
||||
"user_passwords_denied": true,
|
||||
"session_hashes_denied": true,
|
||||
"create_role_denied": true
|
||||
},
|
||||
"tls_server_ca_denied": true,
|
||||
"tls_server_hostname_denied": true,
|
||||
"broker_admin_denied": true,
|
||||
"openbao": {
|
||||
"service_policies": [
|
||||
"messenger-worker"
|
||||
],
|
||||
"token_ttl_seconds": 120,
|
||||
"foreign_secret_denied": true,
|
||||
"policy_write_denied": true,
|
||||
"foreign_pki_role_denied": true
|
||||
},
|
||||
"probe_exit_code": 1,
|
||||
"failure": " Container mtusi-lab7-maslov-operator-probe-run-716f354bbf1d Creating \n Container mtusi-lab7-maslov-operator-probe-run-716f354bbf1d Created \nTraceback (most recent call last):\n File \"<frozen runpy>\", line 203, in _run_module_as_main\n File \"<frozen runpy>\", line 88, in _run_code\n File \"/app/src/security_probe.py\", line 341, in <module>\n main()\n ~~~~^^\n File \"/app/src/security_probe.py\", line 321, in main\n \"worker_list_all_buckets_denied\": s3_denied(\n ~~~~~~~~~^\n lambda: clients[\"worker\"].list_buckets()\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n ),\n ^\n File \"/app/src/security_probe.py\", line 300, in s3_denied\n raise AssertionError(\"S3 operation unexpectedly allowed\")\nAssertionError: S3 operation unexpectedly allowed\n\n",
|
||||
"date": "2026-11-20T16:33:54.187475+00:00",
|
||||
"source_commit": "d6957b2f79ce0fb861c4b4e8bb67f1dc82ffade4"
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
disable_mlock = true
|
||||
ui = false
|
||||
api_addr = "https://openbao:8200"
|
||||
storage "file" { path = "/data/storage" }
|
||||
cluster_addr = "https://openbao:8201"
|
||||
storage "raft" {
|
||||
path = "/data/storage"
|
||||
node_id = "messenger-local"
|
||||
}
|
||||
listener "tcp" {
|
||||
address = "0.0.0.0:8200"
|
||||
tls_min_version = "tls13"
|
||||
@@ -12,3 +15,12 @@ listener "tcp" {
|
||||
tls_auto_reload = true
|
||||
tls_auto_reload_interval = "5s"
|
||||
}
|
||||
|
||||
audit "file" "file" {
|
||||
description = "Persistent service identity audit"
|
||||
options {
|
||||
file_path = "/data/audit/audit.log"
|
||||
mode = "0600"
|
||||
log_raw = "false"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ LABEL org.opencontainers.image.revision=9e49d5e7a648f00e26f2246f4dc28e6b07f8c84a
|
||||
COPY --from=minio-build /out/minio /usr/local/bin/minio
|
||||
COPY --from=minio-build /source/LICENSE /licenses/minio.LICENSE
|
||||
COPY --chmod=755 infra/s3-entrypoint.sh /usr/local/bin/s3-entrypoint
|
||||
RUN mkdir /data && chown 10001:10001 /data
|
||||
RUN python -m pip uninstall -y pip && mkdir /data && chown 10001:10001 /data
|
||||
USER 10001:10001
|
||||
ENTRYPOINT ["/usr/local/bin/s3-entrypoint"]
|
||||
EXPOSE 9000
|
||||
|
||||
@@ -389,7 +389,13 @@ func runHTTP(c Config, b Boundary) error {
|
||||
}
|
||||
}
|
||||
if !allowed {
|
||||
http.Error(w, "Operation denied", 403)
|
||||
if c.Role == "s3" {
|
||||
w.Header().Set("Content-Type", "application/xml")
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
io.WriteString(w, "<Error><Code>AccessDenied</Code><Message>Operation denied</Message><RequestId>tls-boundary</RequestId><HostId>local</HostId></Error>")
|
||||
} else {
|
||||
http.Error(w, "Operation denied", http.StatusForbidden)
|
||||
}
|
||||
return
|
||||
}
|
||||
r.Header.Del("X-Forwarded-Client-Cert")
|
||||
|
||||
+12
-3
@@ -17,13 +17,22 @@
|
||||
"protocol": "http",
|
||||
"allow": {
|
||||
"spiffe://messenger/api": [
|
||||
"* /"
|
||||
"GET /messenger/objects/",
|
||||
"HEAD /messenger/objects/",
|
||||
"PUT /messenger/objects/staging/",
|
||||
"GET /minio/health/"
|
||||
],
|
||||
"spiffe://messenger/worker": [
|
||||
"* /"
|
||||
"GET /messenger/objects/",
|
||||
"HEAD /messenger/objects/",
|
||||
"PUT /messenger/objects/",
|
||||
"GET /minio/health/"
|
||||
],
|
||||
"spiffe://messenger/reconciler": [
|
||||
"* /"
|
||||
"GET /messenger",
|
||||
"HEAD /messenger/objects/",
|
||||
"DELETE /messenger/objects/",
|
||||
"GET /minio/health/"
|
||||
],
|
||||
"spiffe://messenger/operator": [
|
||||
"* /"
|
||||
|
||||
+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,
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ def verify(stream, *, declared):
|
||||
with DECODE_SLOT:
|
||||
try:
|
||||
stream.seek(0)
|
||||
with Image.open(stream) as image:
|
||||
with Image.open(stream, formats=["PNG", "JPEG"]) as image:
|
||||
actual = {"PNG": "image/png", "JPEG": "image/jpeg"}.get(
|
||||
image.format
|
||||
)
|
||||
@@ -50,7 +50,7 @@ def verify(stream, *, declared):
|
||||
image.verify()
|
||||
# JPEG verify alone does not decode entropy data.
|
||||
stream.seek(0)
|
||||
with Image.open(stream) as image:
|
||||
with Image.open(stream, formats=["PNG", "JPEG"]) as image:
|
||||
image.load()
|
||||
except Image.DecompressionBombError:
|
||||
raise DomainError(
|
||||
|
||||
Reference in New Issue
Block a user