Skip to content

chore(core): Use p12 store directly with keycloak #2622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dmihalcik-virtru
Copy link
Member

@dmihalcik-virtru dmihalcik-virtru commented Aug 8, 2025

Proposed Changes

  • Instead of using the java keystore, use a PKCS#12 formatted private key.
  • See guide here: https://www.keycloak.org/server/enabletls
  • Since Java 9, support for JKS seems to be winding down, with the feature deprecated in favor of other, standard formats
  • Notably, this means one less dep during configuration, bypassing the need to load a (sometimes very specific) JDK

Checklist

  • I have added or updated unit tests
  • I have added or updated integration tests (if appropriate)
  • I have added or updated documentation

Testing Instructions

@dmihalcik-virtru dmihalcik-virtru requested review from a team as code owners August 8, 2025 17:38
@github-actions github-actions bot added comp:ci Github Actions Work comp:sdk A software development kit, including library, for client applications and inter-service communicati size/m labels Aug 8, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @dmihalcik-virtru, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates Keycloak configurations to use PKCS#12 (P12) keystores instead of the older Java Keystore (JKS) format. This change aligns with modern Java practices, as JKS support is being deprecated since Java 9. The modifications involve updating configuration files, build scripts, and test data to reflect this new certificate store format.

Highlights

  • Keycloak Configuration Migration: I've updated the docker-compose.yaml and oauth_test.go files to configure Keycloak to use PKCS#12 (.p12) files for its truststore and HTTPS key store, moving away from the deprecated JKS format.
  • Certificate Generation Script Updates: I've modified the init-temp-keys.cmd and init-temp-keys.sh scripts to directly generate PKCS#12 files using openssl pkcs12 and removed the keytool commands that previously converted P12 to JKS. This simplifies the certificate generation process.
  • Updated Test Certificates: I've refreshed the test certificate and key files (keycloak-ca.pem, keycloak-ca.srl, localhost.crt, localhost.key, sampleuser.crt, sampleuser.key) within the sdk/auth/oauth/testdata directory to reflect the new P12-centric setup.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Old JKS fades, PKCS#12 now takes hold, Keycloak's trust renewed.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a good step towards modernizing the Keycloak configuration by using a PKCS#12 store directly instead of the deprecated JKS format. The changes to the initialization scripts and the main configuration files are mostly correct. However, I've identified a few inconsistencies in docker-compose.yaml and sdk/auth/oauth/oauth_test.go where some outdated or redundant settings for passwords and keystore files remain. Additionally, a critical test data file, testdata/new-ca.p12, appears to be missing from the changes, which would likely cause tests to fail. My review comments provide specific details to help resolve these issues.

"--spi-truststore-file-hostname-verification-policy=ANY",
},
Files: []tc.ContainerFile{
{HostFilePath: "testdata/new-ca.jks", ContainerFilePath: "/truststore/truststore.jks", FileMode: int64(0o777)},
{HostFilePath: "testdata/new-ca.p12", ContainerFilePath: "/truststore/truststore.p12", FileMode: int64(0o777)},
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The test setup now references testdata/new-ca.p12, but this file has not been added to the repository in this pull request. The old testdata/new-ca.jks file seems to be replaced by it. Please generate and add testdata/new-ca.p12 and remove testdata/new-ca.jks from version control.

{HostFilePath: "testdata/localhost.crt", ContainerFilePath: "/etc/x509/tls/localhost.crt", FileMode: int64(0o777)},
{HostFilePath: "testdata/localhost.key", ContainerFilePath: "/etc/x509/tls/localhost.key", FileMode: int64(0o777)},
},
Env: map[string]string{
"KEYCLOAK_ADMIN": "admin",
"KEYCLOAK_ADMIN_PASSWORD": "admin",
"KC_HTTPS_KEY_STORE_PASSWORD": "password",
"KC_HTTPS_KEY_STORE_FILE": "/truststore/truststore.jks",
"KC_HTTPS_KEY_STORE_FILE": "/truststore/truststore.p12",
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This test configuration has some inconsistencies that should be addressed:

  • The -Djavax.net.ssl.trustStorePassword=password on line 548 is incorrect as the new .p12 truststore is passwordless and should be removed.
  • The KC_HTTPS_KEY_STORE_PASSWORD on line 561 should be removed for consistency with docker-compose.yaml and because the p12 file is passwordless.
  • The KC_HTTPS_KEY_STORE_FILE on this line is redundant as KC_HTTPS_CERTIFICATE_FILE and KC_HTTPS_CERTIFICATE_KEY_FILE take precedence. It should also be removed.

Please update the test configuration to be consistent and correct.

image: keycloak/keycloak:25.0
restart: always
command:
- "start-dev"
- "--verbose"
- "-Djavax.net.ssl.trustStorePassword=password"
- "-Djavax.net.ssl.HostnameVerifier=AllowAll"
- "-Djavax.net.ssl.trustStore=/truststore/truststore.jks"
- "--truststore-paths=/truststore/truststore.p12"
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

With the switch to --truststore-paths, the Java system property -Djavax.net.ssl.trustStorePassword=password on line 15 is now incorrect. The new ca.p12 truststore is created with an empty password, so this property should be removed.

@@ -37,8 +37,7 @@
#KC_HOSTNAME_URL: http://localhost:8888/auth
KC_FEATURES: "preview,token-exchange"
KC_HEALTH_ENABLED: "true"
KC_HTTPS_KEY_STORE_PASSWORD: "password"
KC_HTTPS_KEY_STORE_FILE: "/truststore/truststore.jks"
KC_HTTPS_KEY_STORE_FILE: "/truststore/truststore.p12"
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The KC_HTTPS_KEY_STORE_FILE setting is redundant because KC_HTTPS_CERTIFICATE_FILE and KC_HTTPS_CERTIFICATE_KEY_FILE are also configured and take precedence. It's also confusing as it points to the truststore file (ca.p12). To avoid confusion and simplify the configuration, this line should be removed.

Copy link
Contributor

github-actions bot commented Aug 8, 2025

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 181.975985ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 98.820756ms

Standard Benchmark Metrics Skipped or Failed

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 349.562549ms
Throughput 286.07 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 37.010989226s
Average Latency 368.511194ms
Throughput 135.10 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 26.372082735s
Average Latency 262.847169ms
Throughput 189.59 requests/second

Copy link
Contributor

github-actions bot commented Aug 8, 2025

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 182.403369ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 93.636584ms

Standard Benchmark Metrics Skipped or Failed

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 352.473894ms
Throughput 283.71 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 38.477474177s
Average Latency 382.347541ms
Throughput 129.95 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 26.328024863s
Average Latency 262.467938ms
Throughput 189.91 requests/second

Copy link
Contributor

github-actions bot commented Aug 8, 2025

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 169.310184ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 94.094224ms

Standard Benchmark Metrics Skipped or Failed

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 344.816182ms
Throughput 290.01 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 36.414145611s
Average Latency 360.873996ms
Throughput 137.31 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 25.21562429s
Average Latency 250.728789ms
Throughput 198.29 requests/second

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:ci Github Actions Work comp:sdk A software development kit, including library, for client applications and inter-service communicati size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant