From 68f14d6563e774cc9f9dfb2405924b02a290e17f Mon Sep 17 00:00:00 2001 From: EgorAnti Date: Fri, 27 Nov 2026 09:26:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B8=D0=B7=D0=BE=D0=BB=D1=8F=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D1=81=D0=B5=D0=BA=D1=80=D0=B5=D1=82=D0=BE=D0=B2=20OpenBao?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + REPORT.md | 1 + contracts/trust-matrix.md | 2 +- evidence/openbao-runtime-boundaries.txt | 15 ++++ scripts/test-openbao-runtime-boundaries.ps1 | 81 +++++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 evidence/openbao-runtime-boundaries.txt create mode 100644 scripts/test-openbao-runtime-boundaries.ps1 diff --git a/README.md b/README.md index 9afddbf..3e1947f 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ credential values: .\scripts\test-internal-tls.ps1 docker compose --env-file .env --profile verification run --rm private-bucket-check .\scripts\test-openbao-policies.ps1 +.\scripts\test-openbao-runtime-boundaries.ps1 ``` diff --git a/REPORT.md b/REPORT.md index 2a69cc0..8ea0ede 100644 --- a/REPORT.md +++ b/REPORT.md @@ -21,6 +21,7 @@ TODO: схема процессов/хранилищ, источник исти | LB → каждая API-реплика | `scripts/test-mtls.ps1`, `TrustedClientCertificateFilterTest` | PASS: обе реплики отдельно отклоняют no-cert, foreign CA и доверенный cert с чужим URI SAN; LB identity принята; API port не опубликован | `compose.yaml`, runtime test, unit test | | Внутренние TLS-связи и service ACL | `scripts/test-internal-tls.ps1`; `docker compose --env-file .env --profile verification run --rm private-bucket-check` | PASS: PostgreSQL, MinIO, OpenBao, Redis, RabbitMQ, Collector, Loki, Tempo и Prometheus проверяют service CA и hostname; mTLS endpoints отвергают no-cert; PostgreSQL/Redis/RabbitMQ и MinIO API/worker identities разделены, запрещённые DDL/keys/commands/prefixes denied | `evidence/internal-tls.txt`, `contracts/trust-matrix.md` | | OpenBao AppRole и policies | `scripts/test-openbao-policies.ps1` | PASS: API и worker читают только свой KV path; чужой path и запись policy отклонены | `evidence/openbao-policies.txt`, `contracts/trust-matrix.md` | +| OpenBao runtime boundaries | `scripts/test-openbao-runtime-boundaries.ps1` | PASS: server mode + persistent Raft volume; отдельные AppRole/bootstrap/rendered volumes; API/worker получают только allowlisted keys через read-only file и не имеют root token/unseal material | `evidence/openbao-runtime-boundaries.txt`, `contracts/trust-matrix.md` | | Compose hardening | `scripts/check-compose-hardening.ps1` | PASS: только три loopback HTTPS-порта; limits/capability/read-only policy проверены | `compose.yaml`, самопроверка скрипта | | Certificates/secrets lifecycle | `scripts/check-security-lifecycle.ps1` | PASS: 20 cert/key bundles валидны; expiry, SAN, пары ключей, Git ignore и возраст SecretID проверены | `evidence/security-lifecycle.txt` | | Публичный smoke | `scripts/verify-https-resilience.ps1` | PASS: полный API-сценарий, включая ACL и вложения, выполнен через HTTPS с проверкой CA и hostname | `evidence/verify-https-resilience.txt` | diff --git a/contracts/trust-matrix.md b/contracts/trust-matrix.md index 36960b0..a2591c8 100644 --- a/contracts/trust-matrix.md +++ b/contracts/trust-matrix.md @@ -27,7 +27,7 @@ | Grafana → backends | HTTPS/mTLS service endpoints | Service CA verify-full; datasource CA/cert/key injected at runtime from files | Отдельный cert SAN `spiffe://hla-lab7/grafana`; Prometheus exact SAN allowlist | Leaf 30 d, not stored in provisioning Git | No cert/foreign CA denied; query allowed | **PASS для transport/identity; backend fine-grained query ACL ограничен single-tenant режимом** | | API Agent → OpenBao | `https://openbao:8200` | TLS verify; service CA + SAN `DNS:openbao` | AppRole `messenger-api`: read только собственного KV data/metadata; нет sys/auth/root/worker | Renewable token 15 min, max 1 h; re-auth; SecretID 24 h | `test-openbao-policies.ps1`: own path allowed; чужой path/policy write denied | **PASS (runtime test на initialized стенде)** | | Worker Agent → OpenBao | `https://openbao:8200` | TLS verify | AppRole `messenger-worker`: read только собственного KV data/metadata | Независимые token, RoleID и SecretID с теми же TTL | Own path allowed; API path/policy write denied | **PASS (runtime test на initialized стенде)** | -| Agent → API/worker runtime file | Отдельные named volumes | Локальный file handoff; volume не общий между ролями | Agent рендерит allowlisted keys; app mount read-only; неожиданный key отклоняется entrypoint | Render interval 5 min; приложение перечитывает при restart | Нет файла → controlled startup failure после 120 s; чужой volume не mounted | **PASS** | +| Agent → API/worker runtime file | Отдельные named volumes | Локальный file handoff; bootstrap и rendered volumes не общие между ролями | Agent рендерит только 5 allowlisted credential keys; app mount read-only; root/unseal/BAO token отсутствуют | Render interval 5 min; приложение перечитывает при restart | `test-openbao-runtime-boundaries.ps1`: общий volume, writable mount, operator env/material или неожиданный key → FAIL | **PASS** | | Operator → OpenBao | `https://localhost:8200`, только loopback | TLS + service CA, SAN `localhost` | Init/unseal/root только bootstrap/recovery; file audit включён | 3 shares, threshold 2; shares/root offline; root env удаляется после bootstrap | AppRole не может init/unseal/write policy; извне хоста порт не опубликован | **PASS по конфигурации; init/unseal остаётся ручной операцией** | | Operator → Grafana | `https://localhost:3000` | TLS verify, service CA, SAN localhost, loopback only | Named admin; anonymous/signup disabled | Local generated password/rotation | Anonymous/app credential denied | **PASS** | | Operator → MinIO admin | Не публикуется; bootstrap внутри сети | TLS verify | Root/operator отдельно; API/worker его не получают | Rotate after bootstrap/exposure | API/worker `mc admin info` denied | **PARTIAL:** port закрыт/policy test есть; HTTP и root env у init | diff --git a/evidence/openbao-runtime-boundaries.txt b/evidence/openbao-runtime-boundaries.txt new file mode 100644 index 0000000..afe216d --- /dev/null +++ b/evidence/openbao-runtime-boundaries.txt @@ -0,0 +1,15 @@ +# OpenBao runtime boundary verification + +Date: 2026-11-27 +Stand: local Docker Desktop, compose project hla-lab7, OpenBao initialized and unsealed + +Command: + powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\test-openbao-runtime-boundaries.ps1 + +Observed output: + OpenBao policy checks passed: own path allowed; foreign path and policy changes denied. + PASS: OpenBao uses persistent raft storage outside dev mode; API/worker use separate AppRoles, scoped policies and read-only rendered files; operator material is absent. + +Scope: server mode, initialized/unsealed Raft state, writable named volume at `/openbao/file`, separate AppRole bootstrap and rendered volumes, read-only application mounts, exact allowlisted runtime key names, and absence of root/unseal material from workload environments and project secrets. + +No root token, unseal key, SecretID, service token or secret value is included. diff --git a/scripts/test-openbao-runtime-boundaries.ps1 b/scripts/test-openbao-runtime-boundaries.ps1 new file mode 100644 index 0000000..1f44721 --- /dev/null +++ b/scripts/test-openbao-runtime-boundaries.ps1 @@ -0,0 +1,81 @@ +[CmdletBinding()] +param([string]$EnvFile = '.env') + +$ErrorActionPreference = 'Stop' +$projectRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path +Set-Location $projectRoot + +function Inspect-One([string]$Service) { + $ids = @(& docker compose --env-file $EnvFile ps -q $Service) + if($ids.Count -ne 1){ throw "Expected one running $Service container, found $($ids.Count)" } + return ((& docker inspect $ids[0] | Out-String) | ConvertFrom-Json)[0] +} + +function Environment-Names($Inspection) { + return @($Inspection.Config.Env | ForEach-Object { ($_ -split '=',2)[0] }) +} + +function Assert-NoOperatorMaterial($Inspection,[string]$Service) { + $forbidden = @('BAO_TOKEN','VAULT_TOKEN','OPENBAO_ROOT_TOKEN','ROOT_TOKEN','UNSEAL_KEY','UNSEAL_KEYS') + $present = @(Environment-Names $Inspection | Where-Object { $forbidden -contains $_ }) + if($present.Count -gt 0){ throw "$Service contains operator-only environment variables: $($present -join ', ')" } +} + +function Assert-RuntimeKeys([string]$ContainerId,[string]$Role) { + $expected = @('DATABASE_PASSWORD','RABBITMQ_PASSWORD','REDIS_PASSWORD','S3_ACCESS_KEY_ID','S3_SECRET_ACCESS_KEY') | Sort-Object + $actual = @(& docker exec $ContainerId sh -c "cut -d= -f1 /run/openbao/runtime.env" 2>$null | Where-Object { $_ } | Sort-Object) + if($LASTEXITCODE -ne 0){ throw "$Role cannot read its rendered runtime secret file" } + if(($actual -join ',') -ne ($expected -join ',')){ + throw "$Role runtime secret file contains unexpected key names" + } +} + +$status = ((& docker compose --env-file $EnvFile exec -T openbao bao status -format=json | Out-String) | ConvertFrom-Json) +if(-not $status.initialized -or $status.sealed){ throw 'OpenBao must be initialized and unsealed for this test' } +if($status.storage_type -ne 'raft'){ throw "OpenBao storage is $($status.storage_type), expected raft" } + +$openbao = Inspect-One 'openbao' +$commandLine = (@($openbao.Config.Entrypoint) + @($openbao.Config.Cmd)) -join ' ' +if($commandLine -match '(^|\s)(dev|server\s+-dev)(\s|$)') { throw 'OpenBao is running in dev mode' } +$storageMount = @($openbao.Mounts | Where-Object { $_.Destination -eq '/openbao/file' }) +if($storageMount.Count -ne 1 -or $storageMount[0].Type -ne 'volume' -or -not $storageMount[0].RW){ + throw 'OpenBao raft storage is not backed by one writable named volume at /openbao/file' +} +Assert-NoOperatorMaterial $openbao 'openbao' + +$agents = @{} +foreach($role in 'api','worker'){ + $agent = Inspect-One "openbao-agent-$role" + Assert-NoOperatorMaterial $agent "openbao-agent-$role" + $bootstrap = @($agent.Mounts | Where-Object { $_.Destination -eq '/run/bootstrap' }) + $rendered = @($agent.Mounts | Where-Object { $_.Destination -eq '/run/rendered' }) + if($bootstrap.Count -ne 1 -or $bootstrap[0].RW){ throw "$role agent bootstrap mount is missing or writable" } + if($rendered.Count -ne 1 -or $rendered[0].Type -ne 'volume'){ throw "$role agent has no dedicated rendered volume" } + $agents[$role] = @{ bootstrap = $bootstrap[0].Source; rendered = $rendered[0].Name } +} +if($agents.api.bootstrap -eq $agents.worker.bootstrap -or $agents.api.rendered -eq $agents.worker.rendered){ + throw 'API and worker OpenBao agents share bootstrap or rendered-secret storage' +} + +foreach($service in 'api','worker'){ + $ids = @(& docker compose --env-file $EnvFile ps -q $service) + if($ids.Count -lt 1){ throw "No running $service container" } + foreach($id in $ids){ + $inspection = ((& docker inspect $id | Out-String) | ConvertFrom-Json)[0] + Assert-NoOperatorMaterial $inspection $service + $runtime = @($inspection.Mounts | Where-Object { $_.Destination -eq '/run/openbao' }) + if($runtime.Count -ne 1 -or $runtime[0].RW){ throw "$service runtime secret mount is missing or writable" } + if(@($inspection.Mounts | Where-Object { $_.Destination -in '/run/bootstrap','/openbao/file' }).Count -gt 0){ + throw "$service can access AppRole bootstrap or OpenBao raft storage" + } + Assert-RuntimeKeys $id $service + } +} + +$operatorArtifacts = @(Get-ChildItem -LiteralPath (Join-Path $projectRoot 'secrets') -Recurse -File -ErrorAction SilentlyContinue | + Where-Object { $_.Name -match '(?i)(root.*token|unseal)' }) +if($operatorArtifacts.Count -gt 0){ throw 'Root token or unseal material exists inside the project secrets tree' } + +& "$PSScriptRoot\test-openbao-policies.ps1" -EnvFile $EnvFile + +Write-Host 'PASS: OpenBao uses persistent raft storage outside dev mode; API/worker use separate AppRoles, scoped policies and read-only rendered files; operator material is absent.'