系统学习 演练学习路径:35 个 lab 的难度排序、4 周基础计划与复盘方法

搭建 OpenBao 密钥管理

适用场景

需要 Vault 兼容的密钥管理,但希望使用开源治理的替代方案。OpenBao 是 Vault 的社区分支,保留 KV、PKI、Transit、Kubernetes 认证等能力。

前置条件

步骤

  1. 安装 OpenBao:
helm repo add openbao https://openbao.github.io/openbao-helm/
helm install openbao openbao/openbao \
  --namespace openbao --create-namespace \
  --set server.ha.enabled=true \
  --set server.ha.raft.enabled=true \
  --set server.dataStorage.size=20Gi
kubectl -n openbao get pods
  1. 初始化并解封:
kubectl -n openbao exec -it openbao-0 -- bao operator init
kubectl -n openbao exec -it openbao-0 -- bao operator unseal <KEY_1>
kubectl -n openbao exec -it openbao-0 -- bao operator unseal <KEY_2>
kubectl -n openbao exec -it openbao-0 -- bao operator unseal <KEY_3>
  1. 登录并启用 KV:
kubectl -n openbao exec -it openbao-0 -- bao login <ROOT_TOKEN>
kubectl -n openbao exec -it openbao-0 -- bao secrets enable -path=secret kv-v2
kubectl -n openbao exec -it openbao-0 -- bao kv put secret/demo/db username=app password='***'
  1. 配置 Kubernetes 认证:
bao auth enable kubernetes
bao write auth/kubernetes/config kubernetes_host="https://kubernetes.default.svc"
bao write auth/kubernetes/role/demo \
  bound_service_account_names=demo \
  bound_service_account_namespaces=demo \
  policies=demo-read ttl=1h
  1. 配置审计和快照:
bao audit enable file file_path=/openbao/logs/audit.log
bao operator raft snapshot save /openbao/backup/openbao.snap

验证

回滚

常见坑

相关命令

参考链接

读完自测

合上页面,先回答,再展开对照。

  1. 读取 KV v2 时路径缺少 data/ 会怎样?
  2. 单节点且没有自动解封,重启后会有什么后果?
  3. 为什么不要轻易执行 bao operator seal?
答案
  1. 读不到数据:KV v2 的数据路径带 data/ 段,少写会访问到错误的路径而取不到值。挂载时启用了 kv-v2,读取就应使用带 data/ 的完整路径。
  2. 服务拿不到密钥。
  3. 会中断动态凭据:封存后 OpenBao 停止服务,所有依赖它的密钥读取和动态凭据续期都会中断,正在使用凭据的应用可能立即失败。确需封存前要确认没有在线依赖,并准备好解封密钥。
微信小程序码:扫码打开命令速查小程序

小程序版

微信扫码,随时查命令