Files
mtusi2026lab7-fork/infra/openbao/agent-api.hcl

82 lines
2.9 KiB
HCL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# lab7: OpenBao Agent для роли `api`. Единственный процесс, у которого есть SecretID.
# Auto-auth AppRole -> короткоживущий токен (TTL 15 мин, max 1 ч, renew агентом) ->
# шаблоны отрисовывают секреты в tmpfs-volume api-secrets (/run/bao), откуда их читает
# приложение (read-only). Токен на диск НЕ пишется (нет sink). Приложение не знает ни
# SecretID, ни токена: «секрета для получения секретов» в образе/приложении нет.
#
# Ротация: KV v2 перечитывается каждые 5 с (static_secret_render_interval); изменённое
# значение перерисовывается в файл, новые соединения БД берут новый пароль (src/db.py).
# OpenBao sealed/недоступен: уже отрисованные файлы остаются, приложение работает со
# старыми значениями; агент повторяет попытки (exit_on_retry_failure = false).
pid_file = "/run/bao/.agent.pid"
vault {
address = "https://openbao:8200"
ca_cert = "/run/secrets/ca_crt"
retry {
num_retries = 12
}
}
auto_auth {
method "approle" {
mount_path = "auth/approle"
config = {
role_id_file_path = "/run/secrets/bao_role_id"
secret_id_file_path = "/run/secrets/bao_secret_id"
remove_secret_id_file_after_reading = false
}
}
}
template_config {
static_secret_render_interval = "5s"
exit_on_retry_failure = false
}
template {
destination = "/run/bao/database_url"
perms = "0400"
error_on_missing_key = true
contents = <<TPL
{{ with secret "kv/data/messenger/api" }}postgresql://messenger_api:{{ .Data.data.db_password }}@postgres:5432/messenger?sslmode=verify-full&sslrootcert=/run/secrets/ca_crt{{ end }}
TPL
}
template {
destination = "/run/bao/cache_url"
perms = "0400"
error_on_missing_key = true
contents = <<TPL
{{ with secret "kv/data/messenger/api" }}rediss://messenger_api:{{ .Data.data.cache_password }}@redis:6379/0{{ end }}
TPL
}
template {
destination = "/run/bao/broker_url"
perms = "0400"
error_on_missing_key = true
contents = <<TPL
{{ with secret "kv/data/messenger/api" }}rediss://api_producer:{{ .Data.data.broker_password }}@broker:6380/0{{ end }}
TPL
}
template {
destination = "/run/bao/s3_access_key_id"
perms = "0400"
error_on_missing_key = true
contents = <<TPL
{{ with secret "kv/data/messenger/api" }}{{ .Data.data.s3_access_key_id }}{{ end }}
TPL
}
template {
destination = "/run/bao/s3_secret_access_key"
perms = "0400"
error_on_missing_key = true
contents = <<TPL
{{ with secret "kv/data/messenger/api" }}{{ .Data.data.s3_secret_access_key }}{{ end }}
TPL
}