lab7: PKI, mTLS infra, OpenBao non-dev, hardening, lifecycle scripts

This commit is contained in:
2026-11-26 16:47:23 +03:00
parent cda6e27fb8
commit 16accda962
45 changed files with 3593 additions and 660 deletions
+20 -4
View File
@@ -1,7 +1,23 @@
# OpenBao — реализовать конфигурацию и политики
# OpenBao (Lab 7 — Non-Dev Raft, TLS, `auth/cert`)
Добавьте non-dev конфигурацию listener/storage/TLS, API/worker policies, bootstrap и rotation scripts. Credentials и unseal material создаются локально; здесь нет готового root token или private key.
## Конфигурация и файлы
Решение должно показать реальную сервисную аутентификацию и получение нужного secret по ограниченной policy; просто работающий контейнер OpenBao не засчитывается. На 3 статический KV secret допустим. На 4 покажите expiry/renewal/rotation и allow/deny. Путь KV v2 data/metadata и ACL должен соответствовать фактическому mount; не копируйте широкое `path "*"` для приложения.
- `infra/openbao/openbao.hcl`: non-dev конфигурация (`ui = false`, `disable_mlock = true`), интегрированное хранилище `storage "raft"` в `/openbao/file` (`openbao-data`), TLS-слушатель `:8200` (`/run/certs/server.{crt,key}`, `tls_min_version = "tls12"`, `tls_disable_client_certs = false`).
- `infra/openbao/policies/`:
- `api.hcl` (`api-policy`) — только `read` на `secret/data/messenger/api` и `secret/metadata/messenger/api`, `lookup-self`/`renew-self`, явные `deny` на чужие роли, `sys/*` и `auth/cert/*`.
- `worker.hcl` (`worker-policy`) — только `read` на `secret/data/messenger/worker` и `metadata`, явные `deny` на `api`, `migrator`, `operator-admin`, `sys/*`, `auth/cert/*`.
- `migrator.hcl` (`migrator-policy`) — только `read` на `secret/data/messenger/migrator`.
- `operator.hcl` (`operator-policy`) — повседневное управление секретами `messenger/*`, ролями/CRL `auth/cert/*`, выборочным отзывом `auth/token/{accessors,lookup-accessor,revoke-accessor}` и `sys/seal` без root-токена.
Документируйте шаги оператора init/unseal и восстановление после restart. Скрипт не должен печатать tokens/shares или хранить их в Git. См. contracts/trust-matrix.md и REPORT.md.
## Разделение хранения и роли `auth/cert`
- Shamir unseal shares (5 долей, порог 3) и операторский mTLS-сертификат (`messenger-operator-g1`) хранятся строго вне Git в `${LAB7_OPERATOR_DIR:-${XDG_STATE_HOME:-$HOME/.local/state}/mtusi-lab7-operator}` (`0700`/`0600`) и никогда не монтируются в контейнеры.
- Initial root token используется однократно в `scripts/openbao-bootstrap.sh` для включения `kv-v2` (`secret/`), `auth/cert`, загрузки политик, ролей и CRL, после чего немедленно отзывается (`auth/token/revoke-self`) и нигде не сохраняется.
- Сервисные роли `auth/cert/certs/<role>` (`messenger-api`, `messenger-worker`, `messenger-migrator`) используют `token_no_default_policy = true`, ограниченный TTL (`5m`/`30m`, для migrator `2m`/`5m`), проверку `allowed_common_names`, `allowed_dns_sans` и CRL `auth/cert/crls/lab7-ca`.
## Операции оператора
- Первичный bootstrap (идемпотентный): `./scripts/openbao-bootstrap.sh`
- Ручной unseal после рестарта/seal: `./scripts/openbao-unseal.sh` (или `make unseal`)
- Ротация рабочих секретов без пересборки образов: `./scripts/rotate-secret.sh <api-db|api-redis|api-s3|worker-db|worker-s3|migrator-db|api|worker>`
- Отзыв скомпрометированного worker (Track 1): `./scripts/revoke-worker.sh [--no-start]`
+24
View File
@@ -0,0 +1,24 @@
ui = false
disable_mlock = true
api_addr = "https://openbao:8200"
cluster_addr = "https://openbao:8201"
storage "raft" {
path = "/openbao/file"
node_id = "openbao-1"
}
listener "tcp" {
address = "0.0.0.0:8200"
cluster_address = "127.0.0.1:8201"
tls_disable = false
tls_cert_file = "/run/certs/server.crt"
tls_key_file = "/run/certs/server.key"
tls_min_version = "tls12"
tls_disable_client_certs = false
tls_require_and_verify_client_cert = false
}
default_lease_ttl = "10m"
max_lease_ttl = "1h"
+37
View File
@@ -0,0 +1,37 @@
# Least-privilege policy for messenger-api (loaded as "api-policy").
path "secret/data/messenger/api" {
capabilities = ["read"]
}
path "secret/metadata/messenger/api" {
capabilities = ["read"]
}
path "auth/token/lookup-self" {
capabilities = ["read"]
}
path "auth/token/renew-self" {
capabilities = ["update"]
}
# Explicit defense-in-depth denies across other roles and control planes.
path "secret/data/messenger/worker" {
capabilities = ["deny"]
}
path "secret/data/messenger/migrator" {
capabilities = ["deny"]
}
path "secret/data/messenger/operator-admin" {
capabilities = ["deny"]
}
path "sys/*" {
capabilities = ["deny"]
}
path "auth/cert/*" {
capabilities = ["deny"]
}
+36
View File
@@ -0,0 +1,36 @@
# Least-privilege policy for one-shot messenger-migrator (loaded as "migrator-policy").
path "secret/data/messenger/migrator" {
capabilities = ["read"]
}
path "secret/metadata/messenger/migrator" {
capabilities = ["read"]
}
path "auth/token/lookup-self" {
capabilities = ["read"]
}
path "auth/token/renew-self" {
capabilities = ["update"]
}
path "secret/data/messenger/api" {
capabilities = ["deny"]
}
path "secret/data/messenger/worker" {
capabilities = ["deny"]
}
path "secret/data/messenger/operator-admin" {
capabilities = ["deny"]
}
path "sys/*" {
capabilities = ["deny"]
}
path "auth/cert/*" {
capabilities = ["deny"]
}
+63
View File
@@ -0,0 +1,63 @@
# Day-to-day operator policy (loaded as "operator-policy", distinct from root).
# Includes targeted "sudo" ONLY on operator control-plane paths that OpenBao
# marks as sudo-protected (token accessor management, workload policy updates,
# and manual sealing). Raw storage and root generation remain denied.
path "secret/data/messenger/*" {
capabilities = ["create", "read", "update", "delete"]
}
path "secret/metadata/messenger/*" {
capabilities = ["list", "read", "delete"]
}
path "auth/cert/certs/*" {
capabilities = ["create", "read", "update", "delete", "list"]
}
path "auth/cert/crls/*" {
capabilities = ["create", "read", "update", "delete", "list"]
}
path "auth/token/accessors" {
capabilities = ["list", "sudo"]
}
path "auth/token/lookup-accessor" {
capabilities = ["update", "sudo"]
}
path "auth/token/revoke-accessor" {
capabilities = ["update", "sudo"]
}
path "auth/token/lookup-self" {
capabilities = ["read"]
}
path "auth/token/renew-self" {
capabilities = ["update"]
}
path "sys/policies/acl/api-policy" {
capabilities = ["create", "read", "update", "sudo"]
}
path "sys/policies/acl/worker-policy" {
capabilities = ["create", "read", "update", "sudo"]
}
path "sys/policies/acl/migrator-policy" {
capabilities = ["create", "read", "update", "sudo"]
}
path "sys/seal" {
capabilities = ["update", "sudo"]
}
path "sys/health" {
capabilities = ["read"]
}
path "sys/raw/*" {
capabilities = ["deny"]
}
+37
View File
@@ -0,0 +1,37 @@
# Least-privilege policy for messenger-worker (loaded as "worker-policy").
path "secret/data/messenger/worker" {
capabilities = ["read"]
}
path "secret/metadata/messenger/worker" {
capabilities = ["read"]
}
path "auth/token/lookup-self" {
capabilities = ["read"]
}
path "auth/token/renew-self" {
capabilities = ["update"]
}
# Explicit defense-in-depth denies across other roles and control planes.
path "secret/data/messenger/api" {
capabilities = ["deny"]
}
path "secret/data/messenger/migrator" {
capabilities = ["deny"]
}
path "secret/data/messenger/operator-admin" {
capabilities = ["deny"]
}
path "sys/*" {
capabilities = ["deny"]
}
path "auth/cert/*" {
capabilities = ["deny"]
}