Tag 6: Identität, Gruppen und Audit
Ziel: Mehrere Logins einer Person zuordnen, Rechte über Gruppen vergeben und jeden Zugriff im Audit-Log nachweisen · Dauer: ca. 90 min · Voraussetzung: Tag 3
Briefing
- Entity = eine Person oder ein Service. Alias = deren Login in einer Auth-Methode.
- Policies an Entity oder Gruppe landen als
identity_policiesin jedem Token – egal über welche Methode eingeloggt. - Interne Gruppen sammeln Entities und vergeben gemeinsame Policies.
- Audit-Devices protokollieren jede Anfrage und Antwort. Secrets erscheinen nur als HMAC.
- In OpenBao 2.7 werden Audit-Devices deklarativ in der Server-Konfiguration angelegt, nicht per API.
Entity "thomas" (policy webshop-read)
├─ Alias userpass/thomas
├─ Alias approle/<role_id>
└─ Mitglied in Gruppe "platform-team" (policy ops-admin)
Drill 1: Dev-Server mit Audit-Konfiguration
mkdir -p ~/bao-lab/tag06 && cd ~/bao-lab/tag06
cat > audit.hcl <<EOF
audit "file" "file" {
description = "Lab-Audit-Log"
options {
file_path = "$HOME/bao-lab/tag06/audit.log"
}
}
EOF
cat audit.hclWarum unquotiertes EOF? $HOME muss beim
Schreiben ersetzt werden – OpenBao expandiert weder ~ noch
Variablen.
Terminal 1:
bao server -dev -dev-root-token-id=root -config=$HOME/bao-lab/tag06/audit.hclTerminal 2:
cd ~/bao-lab/tag06
export BAO_ADDR=http://127.0.0.1:8200 BAO_TOKEN=root
bao audit list -detailedErwartet (gekürzt):
Path Type Description Replication Options
---- ---- ----------- ----------- -------
file/ file Lab-Audit-Log replicated file_path=.../tag06/audit.log
Im Log von Terminal 1:
[INFO] core: enabled audit backend: path=file/ type=file
Fortschritt speichern? Kostenlos registrieren
Drill 2: Der API-Weg ist gesperrt
bao audit enable file file_path=/tmp/audit.log
bao audit disable fileErwartet (gekürzt):
Error enabling audit device: Error making API request.
...
* cannot enable audit device via API; use declarative, config-based audit device
management instead
...
* cannot disable configuration-managed audit device
Warum? Wer per API ein Audit-Device auf einen beliebigen Pfad legen kann, kann Dateien auf dem Server schreiben. Deshalb ist es in OpenBao (getestet mit 2.7.1) Sache der Konfiguration.
Achtung: Die Konfigurationsoption
unsafe_allow_api_audit_creation = trueschaltet den alten Weg wieder frei. Nur für Migrationen, nie dauerhaft.
Fortschritt speichern? Kostenlos registrieren
Drill 3: Logins vorbereiten
bao auth enable userpass
bao auth enable approle
# Lab-Passwort
bao write auth/userpass/users/thomas password=lab-pw-thomas token_policies=default
bao write auth/approle/role/webshop token_policies=default
bao policy write webshop-read - <<'EOF'
path "secret/data/webshop/*" {
capabilities = ["read"]
}
EOF
bao policy write ops-admin - <<'EOF'
path "sys/mounts" {
capabilities = ["read"]
}
EOF
bao kv put -mount=secret webshop/config db_host=db.webshop.labErwartet (gekürzt):
Success! Enabled userpass auth method at: userpass/
Success! Enabled approle auth method at: approle/
Success! Data written to: auth/userpass/users/thomas
Success! Data written to: auth/approle/role/webshop
Success! Uploaded policy: webshop-read
Success! Uploaded policy: ops-admin
Fortschritt speichern? Kostenlos registrieren
Drill 4: Entity und zwei Aliases
Szenario: Thomas meldet sich interaktiv per userpass an, seine CI-Skripte per AppRole. Beides soll eine Identität sein.
bao write identity/entity name=thomas policies=webshop-read metadata=team=platform
ENT=$(bao read -field=id identity/entity/name/thomas)
UP=$(bao auth list -format=json | jq -r '."userpass/".accessor')
AR=$(bao auth list -format=json | jq -r '."approle/".accessor')
RID=$(bao read -field=role_id auth/approle/role/webshop/role-id)
echo "$ENT $UP $AR $RID"
bao write identity/entity-alias name=thomas canonical_id="$ENT" mount_accessor="$UP"
bao write identity/entity-alias name="$RID" canonical_id="$ENT" mount_accessor="$AR"Erwartet (gekürzt):
Key Value
--- -----
aliases <nil>
id 83a2bcc0-6365-3193-f308-6b054a2e0503
name thomas
83a2bcc0-... auth_userpass_64fa3a5d auth_approle_51344df3 78e42b65-f57d-...
Key Value
--- -----
canonical_id 83a2bcc0-6365-3193-f308-6b054a2e0503
id 21370341-2799-0971-7c74-e749258e862a
...
Warum role_id? Der Alias-Name muss dem entsprechen, was
die Auth-Methode als Namen liefert: bei userpass der Username, bei
AppRole die role_id.
Fortschritt speichern? Kostenlos registrieren
Drill 5: Gleiche Identität, egal welcher Login
T1=$(bao login -method=userpass -no-store -field=token \
username=thomas password=lab-pw-thomas)
SID=$(bao write -f -field=secret_id auth/approle/role/webshop/secret-id)
T2=$(bao write -field=token auth/approle/login role_id="$RID" secret_id="$SID")
for T in $T1 $T2; do
BAO_TOKEN=$T bao token lookup -format=json \
| jq -c '.data | {entity_id, policies, identity_policies}'
done
BAO_TOKEN=$T2 bao kv get -mount=secret -field=db_host webshop/config; echoErwartet (gekürzt):
The token was not stored in token helper. Set the BAO_TOKEN environment
variable or pass the token below with each request to Vault.
{"entity_id":"83a2bcc0-...","policies":["default"],"identity_policies":["webshop-read"]}
{"entity_id":"83a2bcc0-...","policies":["default"],"identity_policies":["webshop-read"]}
db.webshop.lab
Warum? Die Auth-Methoden vergeben nur default;
webshop-read kommt über die Entity.
Fortschritt speichern? Kostenlos registrieren
Drill 6: Interne Gruppe
BAO_TOKEN=$T1 bao read sys/mounts
bao write identity/group name=platform-team type=internal \
policies=ops-admin member_entity_ids="$ENT" metadata=owner=platform
bao read identity/group/name/platform-team | grep -E '^name|^type|policies|member_entity'Erwartet (gekürzt):
Code: 403. Errors:
...
* permission denied
Key Value
--- -----
id 0acaef95-10e4-aca9-4349-36ce412ed2c8
name platform-team
member_entity_ids [83a2bcc0-6365-3193-f308-6b054a2e0503]
name platform-team
policies [ops-admin]
type internal
Dasselbe Token erneut:
BAO_TOKEN=$T1 bao token lookup -format=json | jq -c .data.identity_policies
BAO_TOKEN=$T1 bao read sys/mounts >/dev/null && echo "sys/mounts OK"Erwartet:
["webshop-read","ops-admin"]
sys/mounts OK
Warum ohne neuen Login? Identity-Policies werden bei jeder Anfrage neu ausgewertet – bestehende Tokens erhalten Gruppenrechte sofort (und verlieren sie ebenso sofort).
Fortschritt speichern? Kostenlos registrieren
Drill 7: identity lookup
Wer steckt hinter einem Login?
bao write identity/lookup/entity alias_name=thomas alias_mount_accessor="$UP" \
| grep -E '^name|^policies|group_ids'
bao read -format=json identity/entity/name/thomas \
| jq '.data | {name, group_ids, aliases: [.aliases[] | {name, mount_type}]}'Erwartet (gekürzt):
direct_group_ids [0acaef95-10e4-aca9-4349-36ce412ed2c8]
group_ids [0acaef95-10e4-aca9-4349-36ce412ed2c8]
inherited_group_ids []
name thomas
policies [webshop-read]
{
"name": "thomas",
"group_ids": [
"0acaef95-10e4-aca9-4349-36ce412ed2c8"
],
"aliases": [
{ "name": "thomas", "mount_type": "userpass" },
{ "name": "78e42b65-f57d-d9b6-dfe6-ec20cb9d5335", "mount_type": "approle" }
]
}
Fortschritt speichern? Kostenlos registrieren
Drill 8: Audit-Log mit jq lesen
Jede Anfrage erzeugt zwei Zeilen: request und
response.
bao kv put -mount=secret webshop/api key=lab-api-key-123 >/dev/null
tail -n 2 audit.log | jq -c '{type, path: .request.path, op: .request.operation}'
tail -n 1 audit.log | jq '{type, auth: {display_name: .auth.display_name,
client_token: .auth.client_token}, data: .request.data.data}'Erwartet (gekürzt):
{"type":"request","path":"secret/data/webshop/api","op":"create"}
{"type":"response","path":"secret/data/webshop/api","op":"create"}
{
"type": "response",
"auth": {
"display_name": "token",
"client_token": "hmac-sha256:2616579cf63515c302eb664526795d32910c1fed98eaa49cba..."
},
"data": {
"key": "hmac-sha256:95016fd2c3da41aa946b8c7143377cc9ab02a3d2022a3ff80958e966..."
}
}
Warum HMAC? Token, Passwörter und Secret-Werte stehen nie im Klartext im Log – trotzdem kannst du sie wiedererkennen (Drill 9).
Nützliche Abfragen:
# alle verweigerten Zugriffe
jq -r 'select(.type=="response" and .error != null)
| [.time, .request.path, .error] | @tsv' audit.log
# was hat Thomas getan (alle Logins)
jq -r --arg e "$ENT" 'select(.type=="response" and .auth.entity_id==$e)
| [.time, .auth.display_name, .request.path] | @tsv' audit.log | tail -4
# auch das Login-Passwort ist gehasht
jq -c 'select(.type=="request" and .request.path=="auth/userpass/login/thomas")
| .request.data' audit.log | head -1Erwartet (gekürzt):
2026-10-08T07:00:05.939609Z sys/mounts 1 error occurred:\n\t* permission denied\n\n
2026-10-08T06:59:52.367472Z approle secret/data/webshop/config
2026-10-08T06:59:58.996794Z userpass-thomas auth/userpass/login/thomas
2026-10-08T06:59:59.060252Z userpass-thomas auth/token/lookup-self
2026-10-08T06:59:59.123846Z userpass-thomas sys/mounts
{"password":"hmac-sha256:70ec037387f5b2277121afdc43be9dae2de58eb83eed149a9d2e5..."}
Fortschritt speichern? Kostenlos registrieren
Drill 9: audit-hash – Secret im Log wiederfinden
Frage aus der Forensik: „Wurde der API-Key
lab-api-key-123 geschrieben oder gelesen?”
H=$(bao write -field=hash sys/audit-hash/file input=lab-api-key-123)
echo "$H"
grep -c "$H" audit.logErwartet:
hmac-sha256:95016fd2c3da41aa946b8c7143377cc9ab02a3d2022a3ff80958e96640b50639
4
Warum 4? Request und Response von kv put – plus Request
und Response des audit-hash-Aufrufs selbst, denn auch
dessen input wird gehasht protokolliert.
Warum pro Device? Jedes Audit-Device hat einen eigenen HMAC-Salt,
daher der Device-Pfad (file) im Endpunkt.
Fortschritt speichern? Kostenlos registrieren
Drill 10: Zweites Device per SIGHUP
cat >> audit.hcl <<'EOF'
audit "file" "stdout" {
options {
file_path = "stdout"
hmac_accessor = "false"
}
}
EOF
kill -HUP "$(pgrep -f 'bao server -dev')"
sleep 1
bao audit listErwartet:
Path Type Description
---- ---- -----------
file/ file Lab-Audit-Log
stdout/ file n/a
Terminal 1 zeigt ab jetzt jede Anfrage als JSON. Das
Token-accessor-Feld steht dort wegen
hmac_accessor=false im Klartext.
Achtung: Ist kein Audit-Device schreibbar, verweigert OpenBao alle Anfragen. Mindestens zwei Devices auf unterschiedlichen Zielen betreiben.
Fortschritt speichern? Kostenlos registrieren
Kontrollpunkt
#!/usr/bin/env bash
check() { if eval "$2" >/dev/null 2>&1; then echo "✔ $1"; else echo "✘ $1"; fi; }
ENT=$(bao read -field=id identity/entity/name/thomas 2>/dev/null)
check "Entity thomas existiert" "[ -n '$ENT' ]"
check "Entity hat 2 Aliases" \
"bao read -format=json identity/entity/name/thomas \
| jq -e '.data.aliases|length == 2'"
check "Gruppe platform-team enthält thomas" \
"bao read -format=json identity/group/name/platform-team | jq -e --arg e '$ENT' \
'.data.member_entity_ids|index(\$e)'"
check "Audit-Device file aktiv" "bao audit list | grep -q '^file/'"
check "Audit-Log enthält Einträge" "[ -s ~/bao-lab/tag06/audit.log ]"Challenge
Lege den Benutzer anna (userpass) mit eigener Entity an,
nimm sie in platform-team auf und finde anschließend im
Audit-Log alle Pfade, die Anna aufgerufen hat.
Hinweis: member_entity_ids ersetzt die
Liste – beide IDs angeben.
Lösung
bao write auth/userpass/users/anna password=lab-pw-anna token_policies=default
bao write identity/entity name=anna
ANNA=$(bao read -field=id identity/entity/name/anna)
bao write identity/entity-alias name=anna canonical_id="$ANNA" mount_accessor="$UP"
bao write identity/group/name/platform-team member_entity_ids="$ENT,$ANNA"
TA=$(bao login -method=userpass -no-store -field=token username=anna password=lab-pw-anna)
BAO_TOKEN=$TA bao read sys/mounts >/dev/null && echo "anna: sys/mounts OK"
jq -r --arg e "$ANNA" 'select(.type=="request" and .auth.entity_id==$e)
| .request.path' audit.log | sort -uErwartet (gekürzt, kann abweichen):
anna: sys/mounts OK
sys/mounts
Fortschritt speichern? Kostenlos registrieren
Enterprise-Notiz
- Entities nicht von Hand pflegen: OIDC/LDAP-Logins legen Entities automatisch an; externe Gruppen spiegeln IdP-Gruppen (Tag 13).
- Audit-Devices gehören in die versionierte Server-Konfiguration; Änderungen per SIGHUP oder Rolling Restart (Tag 12).
- Audit-Log zentral sammeln (Fluent Bit/Vector → SIEM), Logrotation mit SIGHUP, Plattenfüllstand überwachen.
- Zweites Device (z. B.
socketodersyslog) als Ausfallreserve – sonst blockiert ein volles Volume den ganzen Cluster. - Audit-Log ist sensibel: HMAC schützt nur Werte, nicht Pfade, Metadaten oder Entity-IDs.