Skip to content
Workload and AI agent identity · Chapter 17 of 20 Day 16: The final case – a leak with several causes

Day 16: The final case – a leak with several causes

Goal: trace a real leak from the warehouse back to its source using the trails from Day 15, back up each cause with a log entry, fix the causes one after the other, verify after each measure and record the result in a report · Duration: about 2 hours (60 minutes of which are the competition) · Prerequisite: Preparation and Day 1–15

Where we start

You need the stored Keycloak events from Day 15, the warehouse service with sid= and jti= in the visitor log, and the lager-schreiber role from Day 11.

# on id1
mkdir -p ~/kurs/16

You restart the warehouse service. It keeps the stock only in memory and starts again at 42 crates afterwards – so you have a clean start for the case:

# on id1
sudo systemctl restart lagerdienst

No output.

# on id1
/opt/keycloak/bin/kcadm.sh get realms/gebaeude --fields eventsEnabled,adminEventsEnabled

Expected:

{
  "eventsEnabled" : true,
  "adminEventsEnabled" : true
}

If the kcadm.sh session has expired (Session has expired), log in again as on Day 4.

Introduction

For fifteen days you built individual building blocks and attacked them one by one: static secrets, Kubernetes badges, federation, SPIFFE, humans, agents, exchange, rights per tool, revocation, audit trail. In real life an incident does not arrive labelled “token lifetime”. It arrives as a sentence: “Crates are missing from the warehouse.” And it rarely has one cause. Usually several bits of carelessness interlock – and whoever fixes the first one and stops does not notice that the leak is still open.

Today you work through such a case from start to finish: from the warehouse manager’s sentence, through the trails in the warehouse and Keycloak, to a report that someone who was not there can read.

Today you will learn:

  • to start an incident with a measurement instead of a guess,
  • to go from the entry in the warehouse via Keycloak to the machine the access came from,
  • to back up each cause with a line from a log,
  • to implement one measure after the other and verify each one with a control measurement,
  • why a new secret does not stop a token that has already been issued,
  • to write a short, solid incident report with a timeline.

Background

The picture for today: the locksmith after the break-in

Someone has broken into the building. Crates are missing from the warehouse, the door is undamaged. A good security officer does not immediately change all the locks. They always proceed the same way:

  1. Assess the damage: What is missing, since when, how much per hour?
  2. Read the visitor logs: Who stood at the warehouse door, with which pass, from where?
  3. Trace the pass back: Who issued it at reception, for whom, with which rights, valid for how long?
  4. Find the gap: How did the unauthorized person get hold of the key?
  5. One measure after the other: change the lock, shrink the key ring, shorten the validity – and after each measure check whether crates are still disappearing.
  6. Report: short, with times and evidence, so that the next shift knows what happened and what is still open.

The catch every security officer experiences at some point: the lock has been changed, and still another crate is missing the next morning. The thief had picked up a day pass at reception – and it is valid until it expires, no matter which lock is on the door.

The terms

Term Meaning in the picture
Incident an event causing damage that has to be investigated and ended the break-in
Trail a log entry with time, identifier and origin entry in the visitor log
Cause a weakness without which the damage would not have happened (in this way) open window, key ring too large
Containment stopping the damage before everything is understood securing the warehouse door
Measure exactly one change changing one lock
Control measurement the same observation as at the start, after every measure counting the crates in the morning
Remaining lifetime time until an already issued token expires the day pass in the thief’s pocket
Incident report symptom, trail, findings, measures, effect, timeline, open items report to the building management

Remember: One measure after the other, and after each one check whether the leak is closed. Otherwise you do not know what worked – and you miss the cause that is still open.

Rules and scoring

  • Time: 60 minutes from the first command in the section “The case”. Set a timer.
  • Allowed: all commands from Preparation and Day 1–15. Not allowed: looking things up in the setup before a trail points to that spot.
  • Do not touch: the abgleich unit on id2. It plays the attacker. In the story they sit on a taken-over account that you do not know about at first. You only stop them during cleanup.
  • Scoring: Each cause found and backed up with a log line earns 3 points, each one fixed with a control measurement 2 more. The report earns up to 5 points. A finding without evidence does not count.
  • At the end, compare yourself with the solution path.

Setup

A colleague has set up new access for the nightly inventory. Type in their steps, but read them like assembly instructions, not like a hint. Which of them is a problem you will prove later.

Where you are: on id1, logged in with kcadm.sh, from step 6 on id2.

Step 1 – A client for the inventory. The colleague creates a confidential client that gets a token without a human (client_credentials, like the assistant on Day 10) – but with a secret instead of a Kubernetes badge.

# on id1
/opt/keycloak/bin/kcadm.sh create clients -r gebaeude -s clientId=inventur -s publicClient=false -s standardFlowEnabled=false -s serviceAccountsEnabled=true -s 'attributes."access.token.lifespan"=900' -i
Option Value Meaning
create clients – create a new client
-s clientId= inventur name of the client
-s publicClient= false confidential client: must identify itself
-s standardFlowEnabled= false no browser login
-s serviceAccountsEnabled= true its own service account, tokens via client_credentials
-s 'attributes."access.token.lifespan"=' 900 tokens are valid for 900 seconds, i.e. 15 minutes
-i – print only the ID of the new client

Without clientAuthenticatorType, Keycloak uses the default client-secret: the client identifies itself with a secret.

Expected (your ID will be different):

bf8d18a4-1a12-4f3f-a704-43a93f16b700

Use your ID in the following commands.

Step 2 – The lager door into the token. As on Day 10, the token needs lager in aud, otherwise the warehouse service will not let it in.

# on id1
/opt/keycloak/bin/kcadm.sh create clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/protocol-mappers/models -r gebaeude -s name=tuer-lager -s protocol=openid-connect -s protocolMapper=oidc-audience-mapper -s 'config."included.custom.audience"=lager' -s 'config."access.token.claim"=true'

You know the options from Day 10: a mapper of type oidc-audience-mapper that writes lager into the access token.

Expected:

Created new model with id '668a9f78-d1c6-46e8-abba-be24f5760788'

Step 3 – The scopes. The colleague attaches both warehouse scopes firmly to the client, as default scopes:

# on id1
/opt/keycloak/bin/kcadm.sh update clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/default-client-scopes/41ee786f-a7c2-40f3-bc99-0eb752ea480a -r gebaeude
# on id1
/opt/keycloak/bin/kcadm.sh update clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/default-client-scopes/15701f7d-b3c6-4bcf-8a06-ea4a411dc384 -r gebaeude
  • 41ee786f-… is lager:lesen, 15701f7d-… is lager:schreiben (you find your IDs with kcadm.sh get client-scopes -r gebaeude --fields id,name, see Day 10).

Neither command prints anything.

Step 4 – The role. lager:schreiben only ends up in the token if the account has the lager-schreiber role (Day 11). In Keycloak, a client’s service account is always called service-account-<clientId>:

# on id1
/opt/keycloak/bin/kcadm.sh add-roles -r gebaeude --uusername service-account-inventur --rolename lager-schreiber
  • --uusername service-account-inventur – the service account of the inventur client,
  • --rolename lager-schreiber – the realm role from Day 11.

No output.

Step 5 – The secret. Keycloak generated a secret when the client was created. The colleague reads it off:

# on id1
/opt/keycloak/bin/kcadm.sh get clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/client-secret -r gebaeude

Expected (your value will be different):

{
  "type" : "secret",
  "value" : "Vqc3q47L13lPKTRNoLptbtLq7zNjgX8tcKzQNCsG0P72RtweNpl6qg4Iss5AxQkDfxggyCquMubl0g0pkKLI9w"
}

This secret has long been invalid in my lab – you will see why in a moment. A secret really never belongs in a book, a wiki page or a ticket; it is printed here only because it no longer opens anything.

Step 6 – The access file on id2. The inventory is supposed to run on id2. The colleague creates a folder:

# on id2
sudo mkdir -p /opt/inventur

And writes the secret into a file:

# on id2
sudo nano /opt/inventur/zugang.env
/opt/inventur/zugang.env new file
INVENTUR_ID=inventur
INVENTUR_GEHEIMNIS=Vqc3q47L13lPKTRNoLptbtLq7zNjgX8tcKzQNCsG0P72RtweNpl6qg4Iss5AxQkDfxggyCquMubl0g0pkKLI9w

Use your value from step 5.

Step 7 – The inventory program.

# on id2
sudo nano /opt/inventur/inventur.py
/opt/inventur/inventur.py new file
"""Inventur: liest jede Nacht den Lagerbestand – mit dem Zugang des Clients inventur."""

import json
import urllib.parse
import urllib.request
from pathlib import Path

AUSSTELLER = "http://172.16.0.126:8080/realms/gebaeude"
LAGER = "http://172.16.0.126:8090"
ZUGANG = Path("/opt/inventur/zugang.env")

werte = dict(zeile.split("=", 1) for zeile in ZUGANG.read_text().split())
rumpf = urllib.parse.urlencode(
    {
        "grant_type": "client_credentials",
        "client_id": werte["INVENTUR_ID"],
        "client_secret": werte["INVENTUR_GEHEIMNIS"],
    }
).encode()
url = AUSSTELLER + "/protocol/openid-connect/token"
with urllib.request.urlopen(url, rumpf, timeout=10) as antwort:
    schein = json.loads(antwort.read())["access_token"]

anfrage = urllib.request.Request(LAGER + "/bestand", headers={"Authorization": "Bearer " + schein})
with urllib.request.urlopen(anfrage, timeout=10) as antwort:
    print("Bestand:", json.loads(antwort.read())["kisten"], "Kisten")

The program reads the access file (line 12), gets a token from Keycloak with client_credentials (lines 13–22) and uses it to query the stock (lines 24–26). It needs no extra packages, only Python’s standard library.

Step 8 – Test run. The colleague tests it:

# on id2
python3 /opt/inventur/inventur.py

Expected:

Bestand: 42 Kisten

It works – the colleague goes home.

Step 9 – The attacker. The next steps re-enact what happened afterwards. On id2 there is another account:

# on id2
sudo useradd -m -s /bin/bash gast
  • -m creates the home directory /home/gast,
  • -s /bin/bash gives the account a shell.

No output. You write the attacker’s program into their home directory:

# on id2
sudo nano /home/gast/abgleich.py
/home/gast/abgleich.py new file
"""Nachstellung des Täters – bucht jede Minute eine Kiste aus."""

import json
import time
import urllib.error
import urllib.parse
import urllib.request

AUSSTELLER = "http://172.16.0.126:8080/realms/gebaeude"
LAGER = "http://172.16.0.126:8090"


def neuer_schein():
    text = open("/opt/inventur/zugang.env").read()
    werte = dict(zeile.split("=", 1) for zeile in text.split())
    rumpf = urllib.parse.urlencode(
        {
            "grant_type": "client_credentials",
            "client_id": werte["INVENTUR_ID"],
            "client_secret": werte["INVENTUR_GEHEIMNIS"],
        }
    ).encode()
    url = AUSSTELLER + "/protocol/openid-connect/token"
    with urllib.request.urlopen(url, rumpf, timeout=10) as antwort:
        return json.loads(antwort.read())["access_token"]


schein = None
while True:
    try:
        if schein is None:
            schein = neuer_schein()
        kopf = {"Authorization": "Bearer " + schein, "Content-Type": "application/json"}
        rumpf = json.dumps({"kisten": 1}).encode()
        anfrage = urllib.request.Request(LAGER + "/ausbuchen", rumpf, kopf)
        with urllib.request.urlopen(anfrage, timeout=10) as antwort:
            print(antwort.status, antwort.read().decode(), flush=True)
    except urllib.error.HTTPError as fehler:
        print(fehler.code, fehler.read().decode(), flush=True)
        schein = None
    except OSError as fehler:
        print("Fehler:", fehler, flush=True)
    time.sleep(60)

The loop runs inside the service; you do not type it in as a command. It does what every thief does with a key they have found: get a token, work with it as long as it lasts, and only fetch a new one after being turned away.

Step 10 – The unit.

# on id2
sudo nano /etc/systemd/system/abgleich.service
/etc/systemd/system/abgleich.service new file
[Unit]
Description=Abgleich (Nachstellung des Täters, Tag 16)

[Service]
ExecStart=/usr/bin/python3 /home/gast/abgleich.py
User=gast
Restart=always

[Install]
WantedBy=multi-user.target
  • User=gast – the program runs with the rights of the gast account, not as root,
  • Restart=always – if it crashes, systemd restarts it.
# on id2
sudo systemctl daemon-reload
# on id2
sudo systemctl start abgleich

Neither command prints anything. From here on you are the security officer. Forget what you just typed.

The case

The message from the warehouse manager: “This morning we had 42 crates. Now there are clearly fewer, and none of us has checked anything out. The number keeps going down.”

Your task: Find all causes, back up each one with a log line, fix them one after the other with a control measurement, and fill in this report:

# on id1
nano ~/kurs/16/bericht.md
~/kurs/16/bericht.md new file
# Bericht: Kisten verschwinden aus dem Lager

## Symptom
- gemeldet:
- gemessen:

## Spur
- Lager:
- Keycloak:

## Befunde und Maßnahmen
| Nr. | Befund (mit Beleg) | Maßnahme | Wirkung (Kontrollmessung) |
|---|---|---|---|
| 1 | | | |

## Ergebnis
- vorher:
- nachher:

## Zeitstrahl

## Geprüft, unauffällig

## Offene Punkte

The observation that everything starts with, and that you use to check every measure, is the warehouse’s visitor log:

# on id1
journalctl -u lagerdienst --since "-15 min" --no-pager
  • -u lagerdienst – only the entries of this service,
  • --since "-15 min" – only the last 15 minutes,
  • --no-pager – print everything at once, without paging.

From here the clock is running. The solution path follows – read it only after the 60 minutes.

Solution path

All times come from my lab run; yours will be different. What matters are the intervals.

Round 1: Assess the damage

Step 1 – The warehouse’s visitor log. Before you change anything, you look at what is happening. You know the warehouse was restarted at 06:10, so you read from then on:

# on id1
journalctl -u lagerdienst --since 06:10 --no-pager

Expected (excerpt – the lines from the test run onwards):

Dec 03 06:11:21 id1 python3[295792]: BESTAND sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:9e55c2c1-3f56-6687-cda0-6cd90a2930e6
Dec 03 06:11:21 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:11:21] "GET /bestand HTTP/1.1" 200 -
Dec 03 06:11:30 id1 python3[295792]: AUSGEBUCHT kisten=1 sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2
Dec 03 06:11:30 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:11:30] "POST /ausbuchen HTTP/1.1" 200 -
Dec 03 06:12:30 id1 python3[295792]: AUSGEBUCHT kisten=1 sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2
Dec 03 06:12:30 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:12:30] "POST /ausbuchen HTTP/1.1" 200 -
Dec 03 06:13:30 id1 python3[295792]: AUSGEBUCHT kisten=1 sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2
Dec 03 06:13:30 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:13:30] "POST /ausbuchen HTTP/1.1" 200 -
Dec 03 06:14:30 id1 python3[295792]: AUSGEBUCHT kisten=1 sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2
Dec 03 06:14:30 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:14:30] "POST /ausbuchen HTTP/1.1" 200 -

What you see, field by field:

Field Value Meaning
Rhythm every minute, second 30 a program, not a human
kisten=1 one crate per call damage: 60 crates per hour if nobody intervenes
azp=inventur client inventur the colleague’s new access
name=service-account-inventur, sid=None service account, no session no human logged in (Day 15)
jti=trrtcc:dd320ed3-… the same for every checkout one single token, presented again and again
172.16.0.228 sender in the access log id2

The first BESTAND entry with a different jti is the colleague’s test run. It read, it did not write.

Remember: Measure first, then change. The warehouse’s visitor log tells you within a minute: which client, which token, from which machine, how fast the damage is growing.

Round 2: Trace the pass back

Step 2 – The events at reception. As on Day 15, you ask Keycloak when the inventur client received tokens. With -q you pass a filter; Keycloak then returns only the matching events:

# on id1
/opt/keycloak/bin/kcadm.sh get events -r gebaeude -q client=inventur
  • get events -r gebaeude – the realm’s stored user events (Day 15),
  • -q client=inventur – only events of this client.

Expected:

[ {
  "id" : "1bd32f7c-de99-4236-abb4-38153723b441",
  "time" : 1796278290413,
  "type" : "CLIENT_LOGIN",
  "realmId" : "d81caa11-8866-4606-bcb2-1f06c54984e4",
  "clientId" : "inventur",
  "userId" : "3e94188b-c870-4f54-a902-19f9d2caaa48",
  "ipAddress" : "172.16.0.228",
  "details" : {
    "token_id" : "trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2",
    "grant_type" : "client_credentials",
    "scope" : "profile lager:schreiben email lager:lesen",
    "client_auth_method" : "client-secret",
    "username" : "service-account-inventur"
  }
}, {
  "id" : "5ea680b2-f3bd-4012-8eb4-478795945872",
  "time" : 1796278280972,
  "type" : "CLIENT_LOGIN",
  "realmId" : "d81caa11-8866-4606-bcb2-1f06c54984e4",
  "clientId" : "inventur",
  "userId" : "3e94188b-c870-4f54-a902-19f9d2caaa48",
  "ipAddress" : "172.16.0.228",
  "details" : {
    "token_id" : "trrtcc:9e55c2c1-3f56-6687-cda0-6cd90a2930e6",
    "grant_type" : "client_credentials",
    "scope" : "profile lager:schreiben email lager:lesen",
    "client_auth_method" : "client-secret",
    "username" : "service-account-inventur"
  }
} ]

The newest event is at the top. Its token_id is exactly the jti from the warehouse. What you see:

Field Value Meaning
type CLIENT_LOGIN token without a human, via client_credentials
ipAddress 172.16.0.228 fetched from id2 – like the test run
client_auth_method client-secret identified with the secret, not with a badge
scope contains lager:schreiben the token may check out goods

And the most striking thing: one token fetch, but one checkout every minute. The token lives long.

Step 3 – When was that? Keycloak counts time in milliseconds since 1970. The first ten digits are the seconds; date turns them into a time of day:

# on id1
date -d @1796278290 +%T
  • -d @1796278290 – this point in time in seconds since 1970 (last three digits dropped),
  • +%T – print only the time of day.

Expected:

06:11:30

The token was fetched at 06:11:30 – in the same second as the first checkout.

Step 4 – How is the client configured? First the basic data. With -q clientId=inventur you find the client by its name:

# on id1
/opt/keycloak/bin/kcadm.sh get clients -r gebaeude -q clientId=inventur --fields id,clientId,clientAuthenticatorType,serviceAccountsEnabled,attributes

Expected:

[ {
  "id" : "bf8d18a4-1a12-4f3f-a704-43a93f16b700",
  "clientId" : "inventur",
  "clientAuthenticatorType" : "client-secret",
  "serviceAccountsEnabled" : true,
  "attributes" : { }
} ]

client-secret confirms what the event says. But attributes is empty – --fields does not show the nested attributes. For the lifetime, you therefore save the whole client to a file:

# on id1
/opt/keycloak/bin/kcadm.sh get clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700 -r gebaeude > ~/kurs/16/inventur-client.json
# on id1
jq '.attributes' ~/kurs/16/inventur-client.json

Expected:

{
  "realm_client": "false",
  "access.token.lifespan": "900",
  "client.secret.creation.time": "1796278225"
}

access.token.lifespan is 900: every token of the client is valid for 15 minutes. So the token from 06:11:30 is valid until 06:26:30. For comparison: since Day 12 the assistant gets tokens for 60 seconds.

Step 5 – Which rights does the client have? The fixed scopes:

# on id1
/opt/keycloak/bin/kcadm.sh get clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/default-client-scopes -r gebaeude --fields name

Expected:

[ {
  "name" : "service_account"
}, {
  "name" : "web-origins"
}, {
  "name" : "acr"
}, {
  "name" : "lager:schreiben"
}, {
  "name" : "profile"
}, {
  "name" : "roles"
}, {
  "name" : "lager:lesen"
}, {
  "name" : "basic"
}, {
  "name" : "email"
} ]

And the roles of the service account:

# on id1
/opt/keycloak/bin/kcadm.sh get-roles -r gebaeude --uusername service-account-inventur --fields name

Expected:

[ {
  "name" : "default-roles-gebaeude"
}, {
  "name" : "lager-schreiber"
} ]

lager:schreiben is a default scope on the client, and the service account has the lager-schreiber role. So every token of this client gets the right to check out goods without anyone asking for it.

Remember: From the warehouse to reception: the jti leads to the CLIENT_LOGIN, the event names the machine, the type of credential and the scopes, and the client settings tell you how long the token is valid.

Round 3: The gap on id2

Step 6 – Does the inventory need write rights at all? You search the inventory program for the places where it sends requests:

# on id2
grep -n urlopen /opt/inventur/inventur.py
  • -n – print line numbers as well.

Expected:

21:with urllib.request.urlopen(url, rumpf, timeout=10) as antwort:
25:with urllib.request.urlopen(anfrage, timeout=10) as antwort:

Two requests: line 21 fetches the token from Keycloak, line 25 reads /bestand. There is no /ausbuchen. The inventory only needs lager:lesen – lager:schreiben is a right that nobody uses except the attacker.

Step 7 – Who can read the secret?

# on id2
ls -l /opt/inventur
  • -l – long format with permissions, owner and size.

Expected:

total 8
-rw-r--r-- 1 root root 980 Dec  3 06:11 inventur.py
-rw-r--r-- 1 root root 127 Dec  3 06:11 zugang.env

-rw-r--r-- on zugang.env: the owner root may read and write, everyone else may read. That is the default for new files – and this is exactly how it was during the test run in step 8 of the setup: the colleague started the program as ubuntu, not as root, and it worked. Every account on id2 can read the secret.

Step 8 – Which accounts exist on id2? getent passwd lists all accounts. With --service files only the local ones from /etc/passwd; the newest are at the end:

# on id2
getent passwd --service files

Expected (excerpt – the last three lines):

nats:x:999:987::/var/lib/nats:/usr/sbin/nologin
iperf3:x:111:113::/nonexistent:/usr/sbin/nologin
gast:x:1001:1001::/home/gast:/bin/bash

gast has a shell and a home directory – an account someone can log in with. Who used it is a question for host forensics, not for you. For the identity side it is enough to know: the secret was open to every account on id2.

Remember: A secret is only as secret as the file it lives in. -rw-r--r-- means: everyone on the machine has the key.

Round 4: Measure 1 – a new secret, kept locked away

Three causes are proven: the readable secret, the excessive rights, the long lifetime. You start with the one through which the attacker gets in.

Step 9 – A new secret. With create on client-secret, Keycloak generates a new secret; the old one is invalid immediately:

# on id1
/opt/keycloak/bin/kcadm.sh create clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/client-secret -r gebaeude

No output. You read the new value as in step 5 of the setup:

# on id1
/opt/keycloak/bin/kcadm.sh get clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/client-secret -r gebaeude

Expected (your value will be different; mine has since been replaced as well):

{
  "type" : "secret",
  "value" : "ETZPeqCmoftTr1GlSKrp3DmLsp8yga5bhW8lUq5X35VNE4jWPWmdz6ELIPi4bEETdcUMwyw92KNnQtO3jH63ZW"
}

Step 10 – A dedicated account for the inventory. So that the file no longer has to be readable by everyone, the inventory gets its own system account:

# on id2
sudo useradd --system --no-create-home --shell /usr/sbin/nologin inventur
Option Value Meaning
--system – system account with a low number, for services rather than humans
--no-create-home – do not create a home directory
--shell /usr/sbin/nologin nobody can log in with this account
inventur – name of the account

No output.

Step 11 – Enter the new secret.

# on id2
sudo nano /opt/inventur/zugang.env
/opt/inventur/zugang.env changes in green
INVENTUR_ID=inventur
INVENTUR_GEHEIMNIS=ETZPeqCmoftTr1GlSKrp3DmLsp8yga5bhW8lUq5X35VNE4jWPWmdz6ELIPi4bEETdcUMwyw92KNnQtO3jH63ZW

Step 12 – The file belongs to the inventory, and only to it.

# on id2
sudo chown inventur:inventur /opt/inventur/zugang.env
  • inventur:inventur – owner and group become the new account.
# on id2
sudo chmod 600 /opt/inventur/zugang.env
  • 600 – the owner may read and write (6), the group (0) and everyone else (0) nothing at all.

Neither command prints anything.

# on id2
ls -l /opt/inventur

Expected:

total 8
-rw-r--r-- 1 root     root     980 Dec  3 06:11 inventur.py
-rw------- 1 inventur inventur 127 Dec  3 06:15 zugang.env

The program may stay readable for everyone; it contains nothing secret. The test as ubuntu:

# on id2
cat /opt/inventur/zugang.env

Expected:

cat: /opt/inventur/zugang.env: Permission denied

Step 13 – The inventory keeps running. From now on you start it as inventur:

# on id2
sudo -u inventur python3 /opt/inventur/inventur.py
  • sudo -u inventur – run the command with the rights of the inventur account.

Expected:

Bestand: 37 Kisten

The inventory works with the new secret. And the stock has dropped by five crates since the restart.

Step 14 – Control measurement. Wait two minutes and read the visitor log from the new secret onwards:

# on id1
journalctl -u lagerdienst --since 06:15 --no-pager

Expected:

Dec 03 06:15:30 id1 python3[295792]: AUSGEBUCHT kisten=1 sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2
Dec 03 06:15:30 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:15:30] "POST /ausbuchen HTTP/1.1" 200 -
Dec 03 06:15:48 id1 python3[295792]: BESTAND sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:36787f44-194d-122f-759b-a662d2cc7ec3
Dec 03 06:15:48 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:15:48] "GET /bestand HTTP/1.1" 200 -
Dec 03 06:16:30 id1 python3[295792]: AUSGEBUCHT kisten=1 sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2
Dec 03 06:16:30 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:16:30] "POST /ausbuchen HTTP/1.1" 200 -
Dec 03 06:17:30 id1 python3[295792]: AUSGEBUCHT kisten=1 sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2
Dec 03 06:17:30 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:17:30] "POST /ausbuchen HTTP/1.1" 200 -

The crates keep disappearing – at 06:16:30 and 06:17:30, after the new secret. And with the same jti trrtcc:dd320ed3-… as since 06:11:30. The BESTAND at 06:15:48 with a new jti is your inventory from step 13.

This is the day pass from the picture: you only need the secret to fetch a new token. The token the attacker already has is checked by the warehouse service offline with Keycloak’s key (Day 14) – a new secret changes nothing about that.

Remember: A new secret locks the door for tomorrow. Anyone who already has a pass today gets in until the pass expires.

Round 5: Measure 2 – cut rights and lifetime

Step 15 – No more write rights. You remove the default scope lager:schreiben from the client:

# on id1
/opt/keycloak/bin/kcadm.sh delete clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/default-client-scopes/15701f7d-b3c6-4bcf-8a06-ea4a411dc384 -r gebaeude

And the role from the service account. remove-roles is the counterpart of add-roles:

# on id1
/opt/keycloak/bin/kcadm.sh remove-roles -r gebaeude --uusername service-account-inventur --rolename lager-schreiber

Neither command prints anything. You remove both so that nothing is left on the client that grants write rights – anyone who checks later finds neither the scope nor the role.

Step 16 – Short tokens. As with the assistant on Day 12:

# on id1
/opt/keycloak/bin/kcadm.sh update clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700 -r gebaeude -s 'attributes."access.token.lifespan"=60'

No output. Checking the roles:

# on id1
/opt/keycloak/bin/kcadm.sh get-roles -r gebaeude --uusername service-account-inventur --fields name

Expected:

[ {
  "name" : "default-roles-gebaeude"
} ]

Step 17 – The inventory keeps running.

# on id2
sudo -u inventur python3 /opt/inventur/inventur.py

Expected:

Bestand: 35 Kisten

What is in its token now? The client’s latest event shows it. -q max=1 limits the list to one entry:

# on id1
/opt/keycloak/bin/kcadm.sh get events -r gebaeude -q client=inventur -q max=1

Expected:

[ {
  "id" : "1b27fc07-ab01-4965-87a0-a5748875e836",
  "time" : 1796278686774,
  "type" : "CLIENT_LOGIN",
  "realmId" : "d81caa11-8866-4606-bcb2-1f06c54984e4",
  "clientId" : "inventur",
  "userId" : "3e94188b-c870-4f54-a902-19f9d2caaa48",
  "ipAddress" : "172.16.0.228",
  "details" : {
    "token_id" : "trrtcc:cf0c6584-e8c5-f6f2-430e-c3b7996b3687",
    "grant_type" : "client_credentials",
    "scope" : "profile email lager:lesen",
    "client_auth_method" : "client-secret",
    "username" : "service-account-inventur"
  }
} ]

scope now only contains lager:lesen. New tokens of the inventory can no longer check out goods.

Step 18 – Control measurement. Wait two minutes again:

# on id1
journalctl -u lagerdienst --since 06:17:40 --no-pager

Expected:

Dec 03 06:18:06 id1 python3[295792]: BESTAND sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:cf0c6584-e8c5-f6f2-430e-c3b7996b3687
Dec 03 06:18:06 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:18:06] "GET /bestand HTTP/1.1" 200 -
Dec 03 06:18:30 id1 python3[295792]: AUSGEBUCHT kisten=1 sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2
Dec 03 06:18:30 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:18:30] "POST /ausbuchen HTTP/1.1" 200 -
Dec 03 06:19:30 id1 python3[295792]: AUSGEBUCHT kisten=1 sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2
Dec 03 06:19:30 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:19:30] "POST /ausbuchen HTTP/1.1" 200 -

Still going. The token from 06:11:30 was issued with lager:schreiben and a 900-second lifetime, and both are in the token, signed. Whatever you change now on the client, scope or role applies to new tokens – the old one carries its rights and its expiry date with it.

Remember: Rights and lifetime are written into the token when it is issued. Changes to the client only affect tokens issued afterwards.

Round 6: The remaining lifetime

What is left? The warehouse service checks tokens offline, without asking Keycloak. It cannot block a single issued token. The attacker’s token expires at 06:26:30. You have two options: wait out the rest, or make sure the warehouse service no longer trusts any token signed with Keycloak’s current key. The second option also hits Anna’s tokens and all others; for eight minutes of remaining lifetime and one crate per minute, you wait. You write that into the report – it is a decision, not a matter of course.

Step 19 – After expiry. Read the visitor log shortly after 06:28:

# on id1
journalctl -u lagerdienst --since 06:25 --no-pager

Expected:

Dec 03 06:25:31 id1 python3[295792]: AUSGEBUCHT kisten=1 sub=3e94188b-c870-4f54-a902-19f9d2caaa48 azp=inventur name=service-account-inventur sid=None jti=trrtcc:dd320ed3-a442-a0ce-8ea3-60d5e17060a2
Dec 03 06:25:31 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:25:31] "POST /ausbuchen HTTP/1.1" 200 -
Dec 03 06:26:31 id1 python3[295792]: 172.16.0.228 - - [03/Dec/2026 06:26:31] "POST /ausbuchen HTTP/1.1" 401 -

At 06:25:31 the last checkout, at 06:26:31 – one second after expiry – the first rejection with 401. After that, nothing from the attacker reaches the warehouse any more.

Step 20 – Do they try at reception? An attacker with an expired token fetches a new one. With type=CLIENT_LOGIN_ERROR you search for failed attempts:

# on id1
/opt/keycloak/bin/kcadm.sh get events -r gebaeude -q client=inventur -q type=CLIENT_LOGIN_ERROR

Expected:

[ ]

No failed attempts. The attacker reads the secret from the file – and gast can no longer open it. They do not even get as far as reception. The test as gast:

# on id2
sudo -u gast cat /opt/inventur/zugang.env

Expected:

cat: /opt/inventur/zugang.env: Permission denied

Step 21 – What if they had copied the old secret? An attacker copies whatever they find. You try the old secret from step 5 of the setup directly against Keycloak:

# on id2
curl -s -d grant_type=client_credentials -d client_id=inventur -d client_secret=Vqc3q47L13lPKTRNoLptbtLq7zNjgX8tcKzQNCsG0P72RtweNpl6qg4Iss5AxQkDfxggyCquMubl0g0pkKLI9w http://172.16.0.126:8080/realms/gebaeude/protocol/openid-connect/token
Option Value Meaning
-s – no progress display
-d grant_type= client_credentials request a token without a human
-d client_id= inventur the client
-d client_secret= your old secret as it was in the first zugang.env
URL the realm’s token endpoint as on Day 9

Expected:

{"error":"unauthorized_client","error_description":"Invalid client or Invalid client credentials"}

And now there is an attempt recorded at reception:

# on id1
/opt/keycloak/bin/kcadm.sh get events -r gebaeude -q client=inventur -q type=CLIENT_LOGIN_ERROR

Expected:

[ {
  "id" : "2a8f4af3-ff34-4107-89f4-506256717821",
  "time" : 1796279376443,
  "type" : "CLIENT_LOGIN_ERROR",
  "realmId" : "d81caa11-8866-4606-bcb2-1f06c54984e4",
  "clientId" : "inventur",
  "ipAddress" : "172.16.0.228",
  "error" : "invalid_client_credentials",
  "details" : {
    "grant_type" : "client_credentials"
  }
} ]

This is why measure 1 was necessary even though it did not stop the ongoing leak: without a new secret, the attacker would simply have fetched a new token after 06:26:30 – with the copied value even after the file had long been locked down. And this event is the trail by which you recognize a new attempt.

Step 22 – The damage.

# on id2
sudo -u inventur python3 /opt/inventur/inventur.py

Expected:

Bestand: 27 Kisten

42 at the start, 27 at the end: 15 crates. Eleven of them after the new secret and eight after the rights were cut – that is the price of a 900-second lifetime.

Remember: A token’s remaining lifetime is the time during which you can no longer do anything. Short tokens are therefore not a nice-to-have but the upper limit for the damage after you intervene.

Round 7: The timeline

A report needs not only the incident but also since when the gap was open. The admin events from Day 15 tell you that.

Step 23 – All changes to the client. With resourcePath you filter by the path of the changed thing; * stands for any characters, so you also find scopes and mappers under the client:

# on id1
/opt/keycloak/bin/kcadm.sh get admin-events -r gebaeude -q 'resourcePath=*bf8d18a4-1a12-4f3f-a704-43a93f16b700*' > ~/kurs/16/admin-events.json

No output. Instead of the full entries, you print only three fields per event on one line:

# on id1
jq -r '.[] | [.time, .operationType, .resourcePath] | @tsv' ~/kurs/16/admin-events.json
  • -r – text without quotation marks,
  • .[] | [.time, .operationType, .resourcePath] – time, type and path for each event,
  • @tsv – as a line with tabs.

Expected:

1796278678446   UPDATE  clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700
1796278668339   DELETE  clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/default-client-scopes/15701f7d-b3c6-4bcf-8a06-ea4a411dc384
1796278528896   ACTION  clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/client-secret
1796278245373   CREATE  clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/default-client-scopes/15701f7d-b3c6-4bcf-8a06-ea4a411dc384
1796278240759   CREATE  clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/default-client-scopes/41ee786f-a7c2-40f3-bc99-0eb752ea480a
1796278236486   CREATE  clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700/protocol-mappers/models/668a9f78-d1c6-46e8-abba-be24f5760788
1796278225323   CREATE  clients/bf8d18a4-1a12-4f3f-a704-43a93f16b700

Read from bottom to top, this is the client’s whole history: created, mapper, two scopes – and at the top your measures: the new secret (ACTION … client-secret), the removed scope (DELETE), the new lifetime (UPDATE). You convert the oldest time:

# on id1
date -d @1796278225 +%T

Expected:

06:10:25

The gap was open from 06:10:25. You find the role assignment the same way under the service account’s path (users/<userId> – the userId is in every CLIENT_LOGIN).

Step 24 – What else was going on? For the report section ## Geprüft, unauffällig (“checked, nothing unusual”) you look at all events of the day. dateFrom filters by date:

# on id1
/opt/keycloak/bin/kcadm.sh get events -r gebaeude -q dateFrom=2026-12-03 > ~/kurs/16/alle-events.json
  • dateFrom=2026-12-03 – events from this day on; use your date.
# on id1
jq -r '.[] | [.type, .clientId, .ipAddress] | @tsv' ~/kurs/16/alle-events.json

Expected:

CLIENT_LOGIN_ERROR  inventur    172.16.0.228
CLIENT_LOGIN    inventur    172.16.0.228
CLIENT_LOGIN    inventur    172.16.0.228
CLIENT_LOGIN    inventur    172.16.0.228
CLIENT_LOGIN    inventur    172.16.0.228
CLIENT_LOGIN    inventur    172.16.0.228

Only inventur, only from id2: your attempt with the old secret, four inventory runs and the attacker’s one fetch. No login by Anna, no exchange via the assistant or the tool desk – the other access paths are not involved in this incident.

Remember: Admin events tell you since when a gap was open. User events tell you who used it – and who did not.

The report

# on id1
nano ~/kurs/16/bericht.md
~/kurs/16/bericht.md changes in green
# Bericht: Kisten verschwinden aus dem Lager

## Symptom
- gemeldet: 42 Kisten am Morgen, dann laufend weniger, niemand hat ausgebucht
- gemessen: ab 06:11:30 jede Minute 1 Kiste (Lager-Besucherbuch), bis 06:25:31

## Spur
- Lager: AUSGEBUCHT azp=inventur name=service-account-inventur sid=None,
  immer dieselbe jti=trrtcc:dd320ed3-…, Absender 172.16.0.228 (id2)
- Keycloak: ein CLIENT_LOGIN 06:11:30 von 172.16.0.228, token_id = diese jti,
  client-secret, scope mit lager:schreiben

## Befunde und Maßnahmen
| Nr. | Befund (mit Beleg) | Maßnahme | Wirkung (Kontrollmessung) |
|---|---|---|---|
| 1 | Geheimnis von inventur in /opt/inventur/zugang.env, -rw-r--r--, für jedes Konto auf id2 lesbar (ls -l) | neues Geheimnis (06:15:28), Datei 600 für Systemkonto inventur | gast: Permission denied; altes Geheimnis: unauthorized_client; Abfluss lief aber weiter (06:16:30, 06:17:30) |
| 2 | inventur liest nur (inventur.py: nur /bestand), hat aber Default-Scope lager:schreiben und Rolle lager-schreiber | Scope und Rolle entfernt (06:17:48, 06:17:53) | neues Token: scope "profile email lager:lesen"; Abfluss lief weiter (06:18:30, 06:19:30) |
| 3 | access.token.lifespan 900: ein Token von 06:11:30 trägt Schreibrecht bis 06:26:30 | lifespan 60 (06:17:58); Restlaufzeit abgewartet | 06:26:31 401 "Signature has expired"; danach keine Ausbuchung, kein neuer Token-Abruf |

## Ergebnis
- vorher: 1 Kiste pro Minute, Verlust 15 Kisten (42 → 27)
- nachher: keine Ausbuchung seit 06:25:31; Inventur läuft mit lager:lesen weiter

## Zeitstrahl
- 06:10:25 Client inventur angelegt (lifespan 900), danach Mapper, Scopes, Rolle
- 06:11:21 Probelauf des Kollegen (BESTAND)
- 06:11:30 Token des Täters geholt, erste Ausbuchung
- 06:15:28 Maßnahme 1: neues Geheimnis, Datei 600
- 06:17:48 Maßnahme 2: Scope und Rolle entfernt; 06:17:58 lifespan 60
- 06:25:31 letzte Ausbuchung
- 06:26:31 erstes 401 im Lager
- danach kein Versuch des Täters am Empfang (Datei nicht mehr lesbar)

## Geprüft, unauffällig
- Keycloak-Ereignisse des Tages: nur Client inventur, nur von id2;
  keine Anmeldung von Menschen, kein Tausch über assistent oder die Werkzeugausgabe

## Offene Punkte
- Wer hat das Konto gast auf id2 benutzt? Übergabe an die Rechner-Forensik
- Geheimnis durch einen Ausweis ersetzen (federated-jwt wie beim Assistenten, Tag 10)
- Lager prüft offline: ein ausgestelltes Token lässt sich nicht einzeln sperren;
  Lebensdauer klein halten, für Schreibrechte ggf. Online-Prüfung erwägen
- Neue Clients nur nach Vier-Augen-Prinzip und über persönliche Admin-Konten

The report fits on one page. Whoever reads it knows what happened, what caused it, what was done, whether it worked and what is still to be done. Every statement has a time or a line that it rests on.

Scoring

Item Backed up by Points
Cause 1: secret readable by everyone ls -l /opt/inventur 3 + 2
Cause 2: write rights without need default scopes, get-roles, inventur.py 3 + 2
Cause 3: lifetime 900 s inventur-client.json, same jti after measure 1 3 + 2
Report with timeline and open items bericht.md up to 5

At most 20 points. From 14 points on, you have solved the case. If you only found cause 3 after the control measurement of measure 1, you did everything right – that is exactly what the control measurement is for.

Cleaning up

The attacker is stopped and their account removed. The inventur client stays, with its new settings.

Before that, take one more look at its log – it confirms the story from the attacker’s point of view:

# on id2
journalctl -u abgleich --no-pager

Expected (excerpt – beginning and end):

Dec 03 06:11:30 id2 systemd[1]: Started abgleich.service - Abgleich (Nachstellung des Täters, Tag 16).
Dec 03 06:11:30 id2 python3[163009]: 200 {"ausgebucht": 1, "kisten": 41}
Dec 03 06:12:30 id2 python3[163009]: 200 {"ausgebucht": 1, "kisten": 40}
Dec 03 06:25:31 id2 python3[163009]: 200 {"ausgebucht": 1, "kisten": 27}
Dec 03 06:26:31 id2 python3[163009]: 401 {"fehler": "Schein ungültig: Signature has expired"}
Dec 03 06:27:31 id2 python3[163009]: Fehler: [Errno 13] Permission denied: '/opt/inventur/zugang.env'
Dec 03 06:28:31 id2 python3[163009]: Fehler: [Errno 13] Permission denied: '/opt/inventur/zugang.env'

After the 401 the attacker wanted to fetch a new token and already failed at the file.

# on id2
sudo systemctl stop abgleich
# on id2
sudo rm /etc/systemd/system/abgleich.service
# on id2
sudo systemctl daemon-reload
# on id2
sudo userdel -r gast
  • -r – also remove the account’s home directory and mail spool.

Expected:

userdel: gast mail spool (/var/mail/gast) not found

The message is harmless: the account never had a mail spool.

Checkpoint

# on id2
systemctl status abgleich --no-pager

Expected:

Unit abgleich.service could not be found.
# on id2
ls -l /opt/inventur

Expected: zugang.env with -rw------- and owner inventur (output as in step 12).

# on id1
/opt/keycloak/bin/kcadm.sh get-roles -r gebaeude --uusername service-account-inventur --fields name

Expected: only default-roles-gebaeude (output as in step 16).

Test yourself

  1. How did you recognize in the warehouse’s visitor log that one single token was used again and again?
  2. Why did the new secret not stop the leak immediately?
  3. Why was it still right to rotate the secret?
  4. You remove the scope and role from the client. Which tokens does that affect, and which not?
  5. How could you have stopped the leak before the token expired, and what would that have cost?
  6. What belongs in an incident report so that someone who was not there understands it?

Answers:

  1. Every checkout had the same jti, and Keycloak showed only one CLIENT_LOGIN with exactly this token_id – one fetch, many checkouts.
  2. You only need the secret to fetch a new token. The warehouse service checks the already issued token offline; it was valid until it expired at 06:26:30.
  3. Otherwise the attacker would simply have fetched a new token after expiry – even with a copied version of the secret. The old secret is now rejected with unauthorized_client.
  4. Only tokens issued afterwards. Rights and expiry time are in the token, signed.
  5. For example by making the warehouse service no longer trust any token signed with Keycloak’s current key. That would have hit all valid tokens, including those of Anna and the assistant. Alternatively an online check or a block list in the warehouse – neither exists there today.
  6. Symptom with measurement, trail, each finding with evidence, each measure with a control measurement, result, timeline with times, what was checked and found unremarkable, open items.

Interview note

“A service account was compromised, you rotated the secret, but the abuse continues. What is going on?” – Good answer: access tokens that have already been issued are self-contained and are usually checked offline by the resource server. Rotation only prevents new tokens; existing ones remain valid until exp. So first determine the remaining lifetime (token lifetime on the client, time of the last fetch from the IdP events), then decide: wait, protect the resource server with a block on azp or jti, or in an emergency rotate the signing key, which hits all tokens. After that, fix the actual causes: replace the secret with a workload identity, cut rights down to what is needed, shorten the lifetime – and verify every measure with the logs.

Enterprise note

  • Runbook before the incident. Who may disable clients, rotate secrets, rotate keys? With which commands? During an incident there is no time to sort that out.
  • No secrets in files where badges are available. id2 is a Kubernetes node. The inventory could have run as a pod with its own ServiceAccount and federated-jwt, like the assistant – then there would be nothing to steal that is valid for longer than an hour.
  • Check rights at creation time. Default scopes with write rights are a warning sign. A four-eyes principle for new clients and regular reports on “which client has which scopes” catch this early.
  • Size the lifetime by the damage. 15 minutes sounds short. At one crate per minute that is 15 crates. For write rights, tokens belong in the range of minutes or less.
  • Report. Depending on the data and the industry, there are reporting obligations with deadlines. The report with its timeline is the basis for that.

Summary

  • An incident starts with a measurement: the warehouse’s visitor log named the client, token, machine and rhythm.
  • The jti led to a single CLIENT_LOGIN from id2 with client-secret and lager:schreiben.
  • Three causes interlocked: a secret readable by everyone, write rights without need, a 15-minute lifetime.
  • The new secret and the reduced rights only affected new tokens. The issued token kept checking out goods until it expired at 06:26:30 – eleven crates after the first measure.
  • Rotating the secret was still necessary: the old one is now rejected, and the file is no longer readable by other accounts.
  • Admin events provided the timeline, user events the “checked, nothing unusual”.
  • The report records symptom, trail, findings, measures, effect, timeline and open items on one page.

With that, you have walked through the whole building once: from static secrets on Day 1 via badges, SPIFFE, humans and agents to an incident that you solve with your own logs. The final case showed why the individual building blocks belong together: a badge instead of a secret, small rights and short tokens would each have reduced the damage on their own – together they would have prevented it.

Commands at a glance

Command What for
journalctl -u <dienst> --since <zeit> --no-pager a service’s visitor log from a given time
kcadm.sh get events -r <realm> -q client=<id> events of a client
kcadm.sh get events … -q type=CLIENT_LOGIN_ERROR failed token fetches
kcadm.sh get events … -q max=1 only the newest event
kcadm.sh get events … -q dateFrom=<datum> events from a given day
kcadm.sh get admin-events … -q 'resourcePath=*<id>*' all changes to one thing
date -d @<sekunden> +%T make Keycloak time readable
kcadm.sh get clients -r <realm> -q clientId=<name> find a client by its name
kcadm.sh create clients/<id>/client-secret generate a new client secret
kcadm.sh remove-roles --uusername <konto> --rolename <rolle> revoke a role
useradd --system --no-create-home --shell /usr/sbin/nologin <konto> system account for a service
chown <konto>:<gruppe> <datei> + chmod 600 <datei> file only for its owner
sudo -u <konto> <befehl> run a command as another account
jq -r '.[] \| [.a, .b] \| @tsv' <datei> fields per entry as one line

Contents

More