接入 OpenBao 受鉴权监控并修复快照续期 (#162)
Co-authored-by: panxiao81 <[email protected]>
This commit was merged in pull request #162.
This commit is contained in:
@@ -47,3 +47,6 @@ openbao_transit_mount_path: "transit/"
|
||||
openbao_manage_firewall: false
|
||||
openbao_allowed_cidrs:
|
||||
- "100.64.0.0/10"
|
||||
|
||||
# 30 秒采集间隔下保留五分钟,指标端点继续要求鉴权。
|
||||
openbao_prometheus_retention_time: "5m"
|
||||
|
||||
@@ -25,3 +25,9 @@ seal "transit" {
|
||||
mount_path = "{{ openbao_transit_mount_path }}"
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
# 显式固定 Prometheus 行为;应用此配置会经 handler 重启,须人工解封。
|
||||
telemetry {
|
||||
prometheus_retention_time = "{{ openbao_prometheus_retention_time }}"
|
||||
disable_hostname = true
|
||||
}
|
||||
|
||||
@@ -96,3 +96,6 @@ openbao_snapshot_oncalendar: "*-*-* 02:00:00"
|
||||
# 3. terraform apply # mounts, roles, policies
|
||||
# 4. ansible-playbook bootstrap-openbao.yml # CA material, OIDC secret, snapshots
|
||||
openbao_config_managed_by_terraform: true
|
||||
|
||||
# 仅在维护窗口显式启用,用于替换已失效的快照 token;不读取/打印 token。
|
||||
openbao_snapshot_rotate_token: false
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
path: /etc/openbao/snapshot.token
|
||||
register: snap_tok_stat
|
||||
|
||||
- name: Create a periodic snapshot token (once)
|
||||
- name: Create or explicitly rotate the periodic snapshot token
|
||||
ansible.builtin.command: "bao token create -policy=snapshot -period=768h -orphan -field=token"
|
||||
environment: "{{ openbao_cli_env }}"
|
||||
register: snap_tok_new
|
||||
when: not snap_tok_stat.stat.exists
|
||||
when: (not snap_tok_stat.stat.exists) or (openbao_snapshot_rotate_token | bool)
|
||||
changed_when: snap_tok_new.rc == 0
|
||||
no_log: true
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
when: not snap_tok_stat.stat.exists
|
||||
when: (not snap_tok_stat.stat.exists) or (openbao_snapshot_rotate_token | bool)
|
||||
no_log: true
|
||||
|
||||
- name: Ensure the snapshot output directory exists
|
||||
|
||||
@@ -3,18 +3,25 @@
|
||||
# Take a Raft snapshot and prune old ones. Ship {{ openbao_snapshot_dir }} off-box
|
||||
# separately (rsync/restic/scp) — a snapshot on the same host is not a backup.
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
|
||||
export BAO_ADDR="{{ openbao_addr }}"
|
||||
export BAO_CACERT="{{ openbao_tls_dir }}/cert.pem"
|
||||
BAO_TOKEN="$(cat /etc/openbao/snapshot.token)"
|
||||
export BAO_TOKEN
|
||||
|
||||
# periodic token 不会自动续期;在每日快照前续期,避免 768h 后永久失败。
|
||||
bao token renew >/dev/null
|
||||
|
||||
dir="{{ openbao_snapshot_dir }}"
|
||||
stamp="$(date +%Y%m%d-%H%M%S)"
|
||||
out="${dir}/openbao-${stamp}.snap"
|
||||
|
||||
bao operator raft snapshot save "${out}"
|
||||
chmod 600 "${out}"
|
||||
partial="${out}.partial"
|
||||
trap 'rm -f -- "$partial"' EXIT
|
||||
bao operator raft snapshot save "${partial}"
|
||||
chmod 600 "${partial}"
|
||||
mv -- "${partial}" "${out}"
|
||||
|
||||
# Retention: keep the newest {{ openbao_snapshot_keep }}.
|
||||
ls -1t "${dir}"/openbao-*.snap 2>/dev/null | tail -n +{{ openbao_snapshot_keep + 1 }} | xargs -r rm -f
|
||||
|
||||
Reference in New Issue
Block a user