8000 Admin v2: Mask client secrets for view-only users by poliglots · Pull Request #52731 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Admin v2: Mask client secrets for view-only users - #52731

Merged
vmuzikar merged 4 commits into
keycloak:mainfrom
poliglots:fix_52197_api_v2_plaintext_client_secret
Sep 25, 2026
Merged

vmuzikar merged 4 commits into
keycloak:mainfrom
poliglots:fix_52197_api_v2_plaintext_client_secret

Conversation

@poliglots
Copy link
Copy Markdown
Contributor

When a user lacks manage permission on a client, strip client secrets from GET /clients/{client} and GET /clients responses to match v1 behavior.

Closes #52197

Copilot AI balanced review requested due to automatic review settings September 14, 2026 10:02
@poliglots
poliglots requested review from a team as code owners September 14, 2026 10:02
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The shared retrieval path can cause PATCH requests by configure-only users to persist the mask as the actual secret.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Masks client secrets in Admin API v2 GET responses for callers without manage permission.

Changes:

  • Applies secret stripping to single-client and list responses.
  • Adds authorization tests for view-only and manage users.
File summaries
File Description
rest/admin-v2/services/src/main/java/org/keycloak/services/client/DefaultClientService.java Masks secrets in retrieved client representations.
rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/client/v2/ClientApiV2AuthorizationTest.java Tests masking and privileged access.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@poliglots
poliglots marked this pull request as draft September 14, 2026 10:12
@poliglots
poliglots force-pushed the fix_52197_api_v2_plaintext_client_secret branch from 5725ee2 to 26b4ffa Compare September 14, 2026 10:33
@poliglots
poliglots requested a balanced review from Copilot September 14, 2026 10:34
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new list tests leave two response-backed streams unclosed.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/client/v2/ClientApiV2AuthorizationTest.java:237

  • This second response-backed stream also needs to be closed with try-with-resources, matching the established usage in this test class and ClientPaginationTest.java:93-96; collecting it with toList() does not close it.
        var manageClients = getClientsApi(manageClientsAdminClient).getClients().toList();
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The generic masker also hides public SAML signing certificates, causing an unrelated v1 compatibility regression.

Review details

Suppressed comments (3)

Previously missed (1) — in code that hasn't changed since the last review.

rest/admin-v2/services/src/main/java/org/keycloak/services/client/DefaultClientService.java:132

  • StripSecretsUtilsV2 also masks SAMLClientRepresentation.signingCertificate (StripSecretsUtilsV2.java:36-39), although this is a public certificate and v1's response masking leaves certificates intact (StripSecretsUtils.java:230-247). Thus a view-only GET now returns ********** for unrelated SAML configuration; use a response-specific masker that redacts only actual client secrets.

This issue also appears on line 183 of the same file.

rest/admin-v2/services/src/main/java/org/keycloak/services/client/DefaultClientService.java:184

  • This also applies the audit-oriented SAML certificate masking to every list item: view-only users lose the public signingCertificate, unlike v1, even though the PR is intended to mask client secrets. Use a response-specific masker that preserves public certificate fields.
                        if (!permissions.clients().canManage(client)) {
                            rep = StripSecretsUtilsV2.stripSecrets(session, rep);

rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/client/v2/ClientApiV2AuthorizationTest.java:239

  • The Stream returned by this REST call is not closed; toList() is terminal but does not invoke close(). Wrap this branch in try-with-resources, as the other getClients() calls in this file do, to release the underlying client response.
        var manageClients = getClientsApi(manageClientsAdminClient).getClients().toList();
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Removing SAML masking breaks an existing admin-event test and changes its established behavior.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +20 to +21
// SAMLClientRepresentation intentionally omitted — it has no secret fields.
// signingCertificate is a public X.509 cert, not a secret.
@poliglots
poliglots force-pushed the fix_52197_api_v2_plaintext_client_secret branch from 0a3d4d4 to b5247be Compare September 15, 2026 08:03
@poliglots
poliglots requested a balanced review from Copilot September 15, 2026 08:06
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

T 8000 he implementation addresses both affected endpoints and includes focused regression coverage.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@poliglots
poliglots marked this pull request as ready for review September 15, 2026 08:09
@poliglots
poliglots force-pushed the fix_52197_api_v2_plaintext_client_secret branch from b5247be to 5b11a87 Compare September 15, 2026 08:36
shawkins added a commit to shawkins/keycloak that referenced this pull request Sep 21, 2026
closes: keycloak#52731

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
poliglots and others added 2 commits September 25, 2026 11:26
When a user lacks manage permission on a client, strip client secrets
from GET /clients/{client} and GET /clients responses to match v1 behavior.

Closes keycloak#52197

Signed-off-by: Shatrughan Rai <polyglot.dev@outlook.com>

# Conflicts:
#	rest/admin-v2/services/src/main/java/org/keycloak/services/client/DefaultClientService.java
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Shatrughan Rai <polyglot.dev@outlook.com>
poliglots and others added 2 commits September 25, 2026 11:26
 fixes an unclosed Stream in the authorization test by wrapping it
 in try-with-resources, matching the pattern used in tests.

 Fixes: keycloak#52197

Signed-off-by: Shatrughan Rai <polyglot.dev@outlook.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Copilot AI review requested due to automatic review settings September 25, 2026 15:40
@shawkins
shawkins force-pushed the fix_52197_api_v2_plaintext_client_secret branch from 5b11a87 to 8bafa6e Compare September 25, 2026 15:40
@shawkins
shawkins requested a review from vmuzikar September 25, 2026 15:41
@shawkins
Copy link
Copy Markdown
Contributor

@poliglots I updated this pr to move the fix to a new central location where the type provider builds clients.

@vmuzikar this should be ready for review

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The centralized permission check correctly covers both affected GET paths with focused tests.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

@vmuzikar vmuzikar left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@vmuzikar
vmuzikar enabled auto-merge (squash) September 25, 2026 16:39
@vmuzikar
vmuzikar merged commit 6688a3d into keycloak:main Sep 25, 2026
158 of 162 checks passed
@poliglots
poliglots deleted the fix_52197_api_v2_plaintext_client_secret branch November 5, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin API v2 returns plaintext client secret to view-clients role holders

5 participants

0