fix(pentest): delete test users only in the target's identity provider (#999) #1002

Merged
sharang merged 2 commits from fix/pentest-cleanup-target-idp into main 2026-11-14 10:43:00 +00:00
Owner

Closes #999. Supersedes #17.

The cleanup of an auto-register pentest session deleted the test user in our own Keycloak realm, through the agent's master-realm admin login (KEYCLOAK_ADMIN_*). It did so whenever the agent had KEYCLOAK_URL, whatever identity provider the target used, and Custom/unknown fell back to it too. It never ran only because the username was never recorded.

Change

  • Session-scoped access only. New config.auth.cleanup (TestUserCleanup, tagged by provider):

    • keycloak: base URL, realm, client id/secret. It uses a client-credentials token from that realm, not master.
    • auth0: domain, client id/secret.
    • okta: domain, API token.

    Secrets are sealed with the other session credentials (Credentials lists them) and redacted from API responses. The URL passes NetGuard::check_url when the session is created, and requests go through the guarded client. KEYCLOAK_ADMIN_USERNAME/_PASSWORD are removed from the agent config.

  • Found by the session's own address. The test user is looked up by base+{session_id}@domain. It is deleted only when exactly one account carries exactly that address (case-insensitive); the provider's search result alone is not trusted. The prompt now gives the LLM that exact address instead of a {session_id} placeholder.

  • Recorded. The planned test user is now written to the stored session (before, it existed only in memory, so test_user.cleaned_up landed on an empty record). A user that cannot be deleted gets left_behind with the reason. It is announced in the session stream and named in the report ("Test User … Left behind … delete it by hand").

  • Firebase and Custom are no longer cleaned up. The variants stay, so older records still read.

Not in this PR: the wizard still has only the "delete test user" checkbox. Without access given through the API, the user is reported as left behind. Wizard fields for the provider access come later.

Tests:

  • A fake Keycloak checks that the token is requested from the given realm with client credentials, and that only the account with the session's address is deleted.
  • Several matching accounts → nothing deleted. A search that only resembles the address → nothing deleted.
  • No access given → nothing asked. An already-deleted user is not asked for again. A missing secret or address leaves the user behind.
  • planned_test_user, the report row, sealing/redaction of the new secret, and serde for older records.

Run: cargo test -p compliance-core, cargo test -p compliance-agent --lib pentest (81 passed), clippy (CI flags) for core and agent, a dashboard check.

CI will also need #1001 (quinn-udp advisory, which fails cargo audit on every PR right now).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9

Closes #999. Supersedes #17. The cleanup of an auto-register pentest session deleted the test user in **our own** Keycloak realm, through the agent's master-realm admin login (`KEYCLOAK_ADMIN_*`). It did so whenever the agent had `KEYCLOAK_URL`, whatever identity provider the target used, and `Custom`/unknown fell back to it too. It never ran only because the username was never recorded. **Change** - **Session-scoped access only.** New `config.auth.cleanup` (`TestUserCleanup`, tagged by `provider`): - `keycloak`: base URL, realm, client id/secret. It uses a client-credentials token from that realm, not master. - `auth0`: domain, client id/secret. - `okta`: domain, API token. Secrets are sealed with the other session credentials (`Credentials` lists them) and redacted from API responses. The URL passes `NetGuard::check_url` when the session is created, and requests go through the guarded client. `KEYCLOAK_ADMIN_USERNAME`/`_PASSWORD` are removed from the agent config. - **Found by the session's own address.** The test user is looked up by `base+{session_id}@domain`. It is deleted only when exactly one account carries exactly that address (case-insensitive); the provider's search result alone is not trusted. The prompt now gives the LLM that exact address instead of a `{session_id}` placeholder. - **Recorded.** The planned test user is now written to the stored session (before, it existed only in memory, so `test_user.cleaned_up` landed on an empty record). A user that cannot be deleted gets `left_behind` with the reason. It is announced in the session stream and named in the report ("Test User … Left behind … delete it by hand"). - **Firebase and Custom** are no longer cleaned up. The variants stay, so older records still read. **Not in this PR:** the wizard still has only the "delete test user" checkbox. Without access given through the API, the user is reported as left behind. Wizard fields for the provider access come later. **Tests:** - A fake Keycloak checks that the token is requested from the given realm with client credentials, and that only the account with the session's address is deleted. - Several matching accounts → nothing deleted. A search that only resembles the address → nothing deleted. - No access given → nothing asked. An already-deleted user is not asked for again. A missing secret or address leaves the user behind. - `planned_test_user`, the report row, sealing/redaction of the new secret, and serde for older records. Run: `cargo test -p compliance-core`, `cargo test -p compliance-agent --lib pentest` (81 passed), clippy (CI flags) for core and agent, a dashboard check. CI will also need #1001 (`quinn-udp` advisory, which fails `cargo audit` on every PR right now). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
sharang added 1 commit 2026-11-14 10:04:32 +00:00
fix(pentest): delete test users only in the target's identity provider (#999)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m25s
CI / Check (pull_request) Failing after 9m37s
0dd43be480
The cleanup of an auto-register session deleted the test user in
Prüfwerk's own Keycloak realm, through the agent's master-realm admin
login, whatever identity provider the target used. It never ran only
because the username was never recorded.

- Cleanup acts only on admin access given for the session
  (`config.auth.cleanup`: Keycloak realm client, Auth0 M2M app, Okta
  token), sealed like the other session credentials and checked by the
  net guard; the agent's KEYCLOAK_ADMIN_* settings are gone.
- The user is found by the session's own plus-addressed e-mail and
  deleted only when exactly one account carries exactly that address.
  The prompt now gives the LLM that exact address.
- The test user is written to the stored session; a user that cannot
  be deleted is recorded as left behind and named in the report.
- Firebase and Custom are not cleaned up (supersedes #17).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
sharang added 1 commit 2026-11-14 10:22:14 +00:00
Merge branch 'main' into fix/pentest-cleanup-target-idp
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m18s
CI / Check (pull_request) Successful in 20m20s
2af1073a5d
sharang merged commit fad023e734 into main 2026-11-14 10:43:00 +00:00
sharang deleted branch fix/pentest-cleanup-target-idp 2026-11-14 10:43:00 +00:00
Sign in to join this conversation.