8000 Fix of getting client keystore without private pem. by lhanusov · Pull Request #54006 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Fix of getting client keystore without private pem. - #54006

Merged
mposolda merged 1 commit into
keycloak:mainfrom
lhanusov:fix/clientcert-perm
Oct 20, 2026
Merged

mposolda merged 1 commit into
keycloak:mainfrom
lhanusov:fix/clientcert-perm

Conversation

@lhanusov
@lhanusov lhanusov commented Oct 15, 2026 •
Copy link
Copy Markdown
Contributor

Closes #49240

Co-authored: Claude noreply@anthropic.com

@lhanusov
8000 lhanusov requested a review from a team as a code owner October 15, 2026 09:35
Copilot AI balanced review requested due to automatic review settings October 15, 2026 09:35
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

The focused authorization change aligns with the sibling endpoint, with consistent test expectations and upgrade guidance.

0 open findings

What changed in this PR

Restricts client keystore downloads to callers with configure permission, preventing view-only administrators from accessing private keys.

Changes:

  • Replaces the download endpoint’s view permission check with configure permission.
  • Updates permission-test expectations.
  • Documents the access change and required permissions.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​admin/​PermissionsTest.java Updates keystore download permission expectations.
services/​src/​main/​java/​org/​keycloak/​services/​resources/​admin/​ClientAttributeCertificateResource.java Requires configure permission for downloads.
docs/​documentation/​upgrading/​topics/​changes/​changes-27_0_0.adoc Explains the restriction and upgrade impact.

🧠 Review effort: Balanced


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

Copilot AI balanced review requested due to automatic review settings October 15, 2026 09:47
@lhanusov
lhanusov force-pushed the fix/clientcert-perm branch from 82c8177 to c198b26 Compare October 15, 2026 09:47
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

The authorization change is narrow and covered by the updated permission test; the remaining documentation correction is nonblocking.

1 open finding

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 15, 2026 09:54
@lhanusov
lhanusov force-pushed the fix/clientcert-perm branch from c198b26 to 5acf066 Compare October 15, 2026 09:54
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

The focused authorization change has matching test and documentation updates, with no unresolved findings.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@mposolda mposolda self-assigned this Oct 15, 2026
pskopek
pskopek previously approved these changes Oct 15, 2026
@pskopek pskopek 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.

All looks good. Thanks @lhanusov .

@mposolda mposolda 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.

@lhanusov Thanks, added inline comment about possibly change approach regarding this

@Operation( summary = "Get a keystore file for the client, containing the public certificate", deprecated = true)
public byte[] getKeystore(@Parameter(description = "Keystore configuration as JSON") final KeyStoreConfig config) {
auth.clients().requireView(client);
auth.clients().requireConfigure(client);
@mposolda mposolda Oct 15, 2026 •
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.

If we do this change, we are effectively requiring that seeing "publicKey" and "certificate" of client requires "manage client" permission. But in that case, we would need to change all other places where those are accessed . Otherwise, we will likely receive bunch of follow-up CVEs like You changed getKeystore to require "configure-client" permissions, however data can be accessed by endpoint XY just with "view-clients" permissions :-)

This might be rather complicated and error-prone... As AFAIK for example normal "client GET" endpoint will include those attributes by default...

TBH I am not seeing a problem to return just "publicKey" and "certificate" with only view-clients permissions. The GH report mentioned that the problem is rather the fact that getKeystore might return privateKey information. Could we rather keep requireView for this endpoint, but just make sure that privateKey information is never returned from the getKeystore?

So I wonder if the method getKeystore could be slightly simplified? It seems that CertificateInfoHelper.getCertificateFromClient seems to never return private-key inside the representation? If it is the case, maybe the method can omit privatePem variable and related conditions and call to getKeystore might be instead just something like getKeystore(config, null, certPem) ?

IMO in this case, it will not be needed to make any upgrading note at all and maybe not even changes to PermissionsTest ? Also I am not sure if we can test this as the behavior is probably unchanged (I recall there was a related fix by @jimmychakkalakal which may already fixed this and filtered privateKey).

In summary: I see the scope of the PR (and fix) is just a small refactoring of that method getKeystore to simplify it and harden it to make sure that it can never return privateKey . WDYT?

Copilot AI balanced review requested due to automatic review settings October 16, 2026 09:37
@lhanusov
lhanusov force-pushed the fix/clientcert-perm branch from 5acf066 to 6bc0c0a Compare October 16, 2026 09:37
@lhanusov lhanusov changed the title Downloading a client keystore requires configure permission Fix of getting client keystore without private pem. Oct 16, 2026
Signed-off-by: Lukas Hanusovsky <lhanusov@redhat.com>
@lhanusov
lhanusov force-pushed the fix/clientcert-perm branch from 6bc0c0a to 3288c5d Compare October 16, 2026 09:38
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

The focused change preserves the helper’s existing certificate-only behavior and matches existing test assertions.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 16, 2026 09:39
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

No blocking issues remain, and existing tests cover certificate-only downloads without a key password.

0 open findings

🧠 Review effort: Balanced

@mposolda
mposolda merged commit 39e1854 into keycloak:main Oct 20, 2026
97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restrict client private key access to require configure/manage permission

4 participants

0