8000 Support encrypted PEM TLS certificate key by michalvavrik · Pull Request #51567 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Support encrypted PEM TLS certificate key - #51567

Merged
vmuzikar merged 1 commit into
keycloak:mainfrom
michalvavrik:feature/issues/27437
Aug 14, 2026
Merged

vmuzikar merged 1 commit into
keycloak:mainfrom
michalvavrik:feature/issues/27437

Conversation

@michalvavrik
Copy link
Copy Markdown
Member

@michalvavrik
michalvavrik requested a review from a team as a code owner August 10, 2026 00:08
Copi 8000 lot AI balanced review requested due to automatic review settings August 10, 2026 00:08
@michalvavrik
michalvavrik requested a review from a team as a code owner August 10, 2026 00:08
@michalvavrik michalvavrik changed the title feat(quarkus): support encrypted PME TLS certificate key Support encrypted PEM TLS certificate key Aug 10, 2026
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.

Pull request overview

Adds encrypted PKCS#8 PEM key support by migrating HTTPS configuration to Quarkus TLS Registry.

Changes:

  • Adds HTTP and management PEM key-password options.
  • Migrates TLS mappings, reload, SNI, and store dispatch behavior.
  • Adds integration/unit tests and documentation.

Reviewed changes

Copilot reviewed 21 out of 23 changed files in this pull request and generated 5 comments.

Sh 8000 ow a summary per file
File Description
quarkus/tests/integration/src/test/resources/unencrypted-test.key.pem Adds an unencrypted test key.
quarkus/tests/integration/src/test/resources/encrypted-test.key.pem Adds an encrypted test key.
quarkus/tests/integration/src/test/resources/encrypted-test.crt.pem Adds its matching certificate.
quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/HttpDistTest.java Tests encrypted PEM and TLS reload.
quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/FipsDistTest.java Updates TLS error assertions.
quarkus/tests/integration/src/test-providers/java/org/keycloak/it/resource/realm/TestRealmResource.java Adds a TLS reload test endpoint.
quarkus/runtime/src/test/resources/conf/keycloak.conf Updates the management TLS property.
quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/mappers/TlsStoreDispatchTest.java Tests TLS store dispatch.
quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappersTlsExceptionTest.java Removes obsolete exception-mapping tests.
quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/ManagementConfigurationTest.java Tests management TLS mappings.
quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/configuration/ConfigurationTest.java Tests HTTP TLS Registry mappings.
quarkus/runtime/src/test/java/org/keycloak/quarkus/runtime/cli/PicocliTest.java Tests TLS validation and precedence.
quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/services/KeycloakHttpServerOptionsCustomizer.java Enables SNI on HTTPS options.
quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/KeycloakRecorder.java Uses centralized SNI detection.
quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/KeycloakMain.java Removes transformer reset logic.
quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/ManagementPropertyMappers.java Migrates management TLS mappings.
quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java Implements TLS Registry mapping and validation.
quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/ExecutionExceptionHandler.java Removes TLS exception transformers.
quarkus/config-api/src/main/java/org/keycloak/config/ManagementOptions.java Adds the management PEM password option.
quarkus/config-api/src/main/java/org/keycloak/config/HttpOptions.java Adds the HTTP PEM password option.
docs/guides/server/enabletls.adoc Documents encrypted PEM configuration.
docs/documentation/upgrading/topics/changes/changes-26_8_0.adoc Adds an upgrade note.
docs/documentation/release_notes/topics/26_8_0.adoc Adds a release note.
Suppressed comments (1)

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/ManagementPropertyMappers.java:224

  • The same missing management-side validation affects trust stores: an unrecognized management truststore extension is routed as PKCS12 instead of producing the https-management-trust-store-type configuration error. Validate the management truststore type before this dispatch.
                            .mapFrom(ManagementOptions.HTTPS_MANAGEMENT_TRUST_STORE_FILE, (name, fileValue, context) ->
                                    HttpPropertyMappers.dispatchStoreFile(fileValue, ManagementOptions.HTTPS_MANAGEMENT_TRUST_STORE_TYPE, type, HttpPropertyMappers.StoreRole.TRUST_STORE))

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

Copilot AI review requested due to automatic review settings August 10, 2026 00:12
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.

Pull request overview

Copilot reviewed 21 out of 23 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

docs/guides/server/enabletls.adoc:56

  • This conflicts with the implemented and tested behavior: validateStoreType rejects an unrecognized extension, and HttpDistTest.httpStoreTypeValidation expects not-there.ks to fail. Document that https-key-store-type is required for unrecognized extensions (or change the implementation and tests to use the stated PKCS12 fallback).
If your keystore does not have one of these extensions, it is treated as PKCS12. To override this, set the `https-key-store-type` option.

Copilot AI review requested due to automatic review settings August 10, 2026 00:30
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.

Pull request overview

Copilot reviewed 21 out of 24 changed files in this pull request and generated no new comments.

Suppressed comments (6)

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:316

  • The password dispatch has the same HTTP-only PEM check even when called by ManagementPropertyMappers. A management PEM configuration can therefore retain the inherited/explicit key-store password; base this check on the management certificate option when dispatching the management store.
        if (role == StoreRole.KEY_STORE && getOptionalKcValue(HttpOptions.HTTPS_CERTIFICATE_FILE.getKey()).isPresent()) {
            return null;

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:304

  • This helper is also used for management key stores, but it only checks the HTTP PEM option. When management PEM files and a management (or inherited) key store are both configured, the key-store path is still emitted, defeating the intended PEM precedence and potentially configuring two key-store types; select the corresponding management certificate option for management dispatches.

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

        if (role == StoreRole.KEY_STORE && getOptionalKcValue(HttpOptions.HTTPS_CERTIFICATE_FILE.getKey()).isPresent()) {
            return null;

quarkus/config-api/src/main/java/org/keycloak/config/ManagementOptions.java:123

  • The new management password option is only covered by configuration-mapping tests; the added end-to-end encrypted-PEM test exercises only the main HTTPS listener. Add a management-listener integration test with the encrypted fixture so the separate management TLS bucket's decryption and password inheritance/override behavior is verified.
    public static final Option<String> HTTPS_MANAGEMENT_CERTIFICATE_KEY_FILE_PASSWORD = new OptionBuilder<>("https-management-certificate-key-file-password", String.class)
            .category(OptionCategory.MANAGEMENT)
            .description("The password to decrypt an encrypted private key in PEM format for the management server. If not given, the value is inherited from HTTP options. " + RELEVANT_MSG)
            .build();

docs/guides/server/enabletls.adoc:30

  • This example puts the encryption password in the process arguments, where it may be visible to other users, directly contradicting the security guidance below. Omit -pass so OpenSSL prompts securely, or demonstrate a non-command-line password source.
openssl genpkey -algorithm RSA -out keyfile.pem -aes-256-cbc -pass pass:<password>

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:383

  • Key-store type validation runs before PEM precedence is applied. Consequently, a valid PEM configuration combined with an intentionally ignored key store having an unrecognized extension still fails startup; skip key-store validation whenever the corresponding effective PEM certificate option is present, for both listeners.
        validateStoreType(HttpOptions.HTTPS_KEY_STORE_FILE, HttpOptions.HTTPS_KEY_STORE_TYPE, StoreRole.KEY_STORE);
        validateStoreType(HttpOptions.HTTPS_TRUST_STORE_FILE, HttpOptions.HTTPS_TRUST_STORE_TYPE, StoreRole.TRUST_STORE);
        validateStoreType(ManagementOptions.HTTPS_MANAGEMENT_KEY_STORE_FILE, ManagementOptions.HTTPS_MANAGEMENT_KEY_STORE_TYPE, StoreRole.KEY_STORE);
        validateStoreType(ManagementOptions.HTTPS_MANAGEMENT_TRUST_STORE_FILE, ManagementOptions.HTTPS_MANAGEMENT_TRUST_STORE_TYPE, StoreRole.TRUST_STORE);

docs/documentation/upgrading/topics/changes/changes-26_8_0.adoc:58

  • “Unencrypted PEM keys continue to work without any changes” conflicts with the new validateNoFipsPem() behavior, which now rejects every PEM certificate in both strict and non-strict FIPS modes. Either preserve the prior non-strict behavior or document this breaking restriction and its migration path here.
A new `--https-certificate-key-file-password` option (env: `KC_HTTPS_CERTIFICATE_KEY_FILE_PASSWORD`) has been added to support encrypted PKCS#8 private keys in PEM format. If your PEM private key is encrypted, provide the decryption password using this op
8000
tion. The management interface has a corresponding `--https-management-certificate-key-file-password` option. Unencrypted PEM keys continue to work without any changes.

Copilot AI review requested due to automatic review settings August 10, 2026 00: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.

Pull request overview

Copilot reviewed 21 out of 24 changed files in this pull request and generated no new comments.

Suppressed comments (3)

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:380

  • PEM is meant to take precedence over a simultaneously configured keystore, but this unconditional validation still rejects an ignored keystore with an unknown extension. For example, a valid PEM pair plus --https-key-store-file=server.ks fails before dispatch; skip HTTP keystore type validation when the PEM certificate option is present.
        validateStoreType(HttpOptions.HTTPS_KEY_STORE_FILE, HttpOptions.HTTPS_KEY_STORE_TYPE, StoreRole.KEY_STORE);

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/ManagementPropertyMappers.java:160

  • When HTTP uses a keystore but management supplies its own PEM pair, the effective management keystore still inherits the HTTP file. dispatchStoreFile only checks the HTTP PEM option, so this emits both P12/JKS and PEM paths into the management TLS bucket; suppress the management keystore whenever the effective management PEM certificate is present.
                            .mapFrom(ManagementOptions.HTTPS_MANAGEMENT_KEY_STORE_FILE, (name, fileValue, context) ->
                                    HttpPropertyMappers.dispatchStoreFile(fileValue, ManagementOptions.HTTPS_MANAGEMENT_KEY_STORE_TYPE, type, HttpPropertyMappers.StoreRole.KEY_STORE))

docs/guides/server/enabletls.adoc:30

  • This example exposes the private-key passphrase in the OpenSSL process arguments, contradicting the security guidance below. Omit -pass so OpenSSL prompts securely, or demonstrate a non-command-line password source.
openssl genpkey -algorithm RSA -out keyfile.pem -aes-256-cbc -pass pass:<password>

Copilot AI review requested due to automatic review settings August 10, 2026 10:23
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.

Pull request overview

Copilot reviewed 21 out of 34 changed files in this pull request and generated no new comments.

Suppressed comments (3)

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:384

  • This rejects an unrecognized keystore even when a PEM pair is configured and the dispatch logic intentionally gives PEM precedence. Skip HTTP keystore type validation when the PEM certificate option is present, otherwise a stale --https-key-store-file=server.ks prevents an otherwise valid PEM configuration from starting.
        validateStoreType(HttpOptions.HTTPS_KEY_STORE_FILE, HttpOptions.HTTPS_KEY_STORE_TYPE, StoreRole.KEY_STORE);

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:418

  • For a management-only PEM configuration this error directs the user to the main server's https-key-store-file, which does not replace the rejected management key material. Mention https-management-key-store-file as well so the remediation is valid for the branch added here.
        if (getOptionalKcValue(HttpOptions.HTTPS_CERTIFICATE_FILE.getKey()).isPresent()
                || getOptionalKcValue(ManagementOptions.HTTPS_MANAGEMENT_CERTIFICATE_FILE.getKey()).isPresent()) {
            throw new PropertyException(
                    "PEM certificates are not supported in FIPS mode. Use a BCFKS keystore with the 'https-key-store-file' option instead.");

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:303

  • These HTTP-specific precedence checks are also used by the management dispatchers. When the main interface uses a keystore and management overrides it with a PEM pair, the inherited management keystore is not suppressed, while a main PEM pair incorrectly suppresses an explicit management keystore; pass the relevant certificate option into both dispatch helpers so each interface resolves its own key material.

This issue also appears in the following locations of the same file:

  • line 384
  • line 415
        // PEM takes precedence over keystore when both are configured
        if (role == StoreRole.KEY_STORE && getOptionalKcValue(HttpOptions.HTTPS_CERTIFICATE_FILE.getKey()).isPresent()) {
            return null;

Copilot AI review requested due to automatic review settings August 10, 2026 12:16
Copilot AI review requested due to automatic review settings August 10, 2026 21:45
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.

Pull request overview

Copilot reviewed 20 out of 33 changed files in this pull request and generated 2 comments.

Suppressed comments (1)

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:368

  • Explicit PEM is accepted here, but both key-store dispatch loops skip StoreType.PEM and filterOtherStoreType drops it, so --https-key-store-file=... --https-key-store-type=PEM wires the TLS bucket without any key material. Either reject PEM for KEY_STORE with a clear validation error or preserve a working mapping for this previously accepted type.
                case "PEM" -> StoreType.PEM;

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.

Pull request overview

Copilot reviewed 20 out of 33 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:526

  • This introduces a breaking configuration change: Keycloak 26 documented PEM as a supported https-key-store-file type (docs/documentation/upgrading/topics/changes/changes-26_0_0.adoc:184-188), but this now rejects an explicitly selected PEM type, while extension-only .pem also fails the new detection. Preserve the legacy PEM keystore path, or explicitly cover its removal and migration in the upgrade/release documentation rather than silently dropping it as part of encrypted-key support.
        String explicitType = getOptionalKcValue(storeTypeOption.getKey()).orElse(null);
        if (explicitType != null && "PEM".equalsIgnoreCase(explicitType)) {
            throw new PropertyException("'%s' cannot be set to 'PEM' when '%s' is used. "
                    .formatted(storeTypeOption.getKey(), storeFileOption.getKey())
                    + "Use '--https-certificate-file' and '--https-certificate-key-file' for PEM certificates.");

if (!FipsMode.STRICT.toString().equals(fipsMode)) {
return;
}
if (Configuration.isSet(storeTypeOption)) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think Copilot is wrong because FipsDistTest#testHttpsBcfksKeyStoreInStrictMode tests this and it is passing locally for me. One of mappers sets "BCFKS" for mapFrom(FIPS_MODE) which is why this comment is IMO wrong.

@michalvavrik
Copy link
Copy Markdown
Member Author

Let see if PR CI is passing (except for documentation which is unrelated), if so, this is ready for review. I'll re-check tomorrow.

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.broker.KcOidcBrokerTest#loginWithExistingUserWithBruteForceEnabled

Keycloak CI - Java Distribution IT (windows-latest - temurin - 17)

org.openqa.selenium.TimeoutException: 
Expected condition failed: waiting for value to contain (ignoring case) "sign in to". Current value: "AUTH_RESPONSE" (tried for 5 second(s) with 500 milliseconds interval)
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Windows Server 2025', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.20'
Driver info: org.jboss.arquillian.drone.webdriver.htmlunit.DroneHtmlUnitDriver_ByGraphene
...

Report flaky test

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.

Pull request overview

Copilot reviewed 20 out of 33 changed files in this pull request and generated no new comments.

Suppressed comments (4)

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/ManagementPropertyMappers.java:210

  • The management path has the same partial-store issue: an explicit management PEM pair suppresses the inherited/explicit alternative store path, but an OTHER type is still emitted. Gate this type on the resolved management PEM certificate so PEM precedence does not leave key-store.other configured without a path.
                        .mapFrom(ManagementOptions.HTTPS_MANAGEMENT_KEY_STORE_TYPE, (name, value, context) ->
                                HttpPropertyMappers.filterOtherStoreType(value, ManagementOptions.HTTPS_MANAGEMENT_KEY_STORE_FILE))
                        .to(MGMT_TLS_PREFIX + "key-store.other.type")

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:245

  • When PEM is selected, the store-path dispatch correctly suppresses the alternative keystore, but this mapper still emits key-store.other.type for an explicitly typed BCFKS/other store. That leaves a partial other keystore beside the active PEM configuration and can make the TLS registry validate a store with no path; suppress the type whenever the PEM certificate option takes precedence.
                        .mapFrom(HttpOptions.HTTPS_KEY_STORE_TYPE, (name, value, ctx) ->
                                filterOtherStoreType(value, HttpOptions.HTTPS_KEY_STORE_FILE))
                        .to(TLS_PREFIX + "key-store.other.type")

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/ManagementPropertyMappers.java:137

  • The new management password is covered only by configuration-mapping tests, while the end-to-end encrypted-key test exercises the main HTTPS server only. Add a management HTTPS integration test with an encrypted PKCS#8 key so the separate management TLS bucket and actual decryption path are verified.

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

                fromOption(ManagementOptions.HTTPS_MANAGEMENT_CERTIFICATE_KEY_FILE_PASSWORD)
                        .isEnabled(ManagementPropertyMappers::isInheritedScheme, HTTP_MANAGEMENT_SCHEME_IS_INHERITED)
                        .mapFrom(HttpOptions.HTTPS_CERTIFICATE_KEY_FILE_PASSWORD, ManagementPropertyMappers::suppressInheritedPemWhenKeystoreSet)
                        .to(MGMT_TLS_PREFIX + "key-store.pem.default.password")
                        .paramLabel("password")

quarkus/tests/integration/src/test/resources/unencrypted-test.key.pem:1

  • This new private-key fixture is never referenced; the integration test copies only encrypted-test.key.pem and encrypted-test.crt.pem. Remove this unused key from the PR rather than carrying unexercised key material.

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.federation.ldap.UserFederationLdapConnectionTest#

Keycloak CI - Base IT (5)

org.opentest4j.MultipleFailuresError: 
Multiple Failures (2 failures)
	java.lang.RuntimeException: java.lang.IllegalStateException: Keycloak unexpectedly died :(
	java.lang.NullPointerException: Cannot invoke "org.keycloak.testsuite.arquillian.TestContext.getAppServerInfo()" because "this.testContext" is null
	Suppressed: java.lang.RuntimeException: java.lang.IllegalStateException: Keycloak unexpectedly died :(
...

Report flaky test

org.keycloak.testsuite.federation.ldap.LDAPUserLoginTest#loginLDAPUserAuthenticationNoneEncryptionStartTLS

Keycloak CI - Java Distribution IT (windows-latest - temurin - 17)

org.openqa.selenium.TimeoutException: 
java.net.SocketTimeoutException: Read timed out
Build info: version: '4.28.1', revision: '73f5ad48a2'
System info: os.name: 'Windows Server 2025', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.20'
Driver info: driver.version: HtmlUnitDriver
...

Report flaky test

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please 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.

Pull request overview

Copilot reviewed 122 out of 135 changed files in this pull request and generated 1 comment.

Suppressed comments (3)

common/src/main/java/org/keycloak/common/util/PathMatcher.java:363

  • Percent-decoded dot segments and matrix delimiters are introduced only after URI.normalize() and matrix stripping have already run. Inputs such as /api/foo/%2e%2e/admin or /api/admin%3Bx=1 can therefore remain non-canonical and fall through to a permissive wildcard resource instead of matching /api/admin; decode and then repeat all structural normalization before matching.
            result = new URI(result).normalize().getPath();

tests/base/src/test/java/org/keycloak/tests/oauth/DirectGrantInputValidationTest.java:47

  • This boundary test has the same observable result as the over-length case—both assert only 400 invalid_grant—so it still passes if a 255-character username is incorrectly rejected by the new guard. Use an existing 255-character user or assert an observable path that distinguishes length validation from normal user-not-found handling.
    themes/src/main/resources/theme/keycloak.v2/login/login-idp-link-confirm.ftl:1
  • This new login-theme template is unrelated to the stated encrypted-PEM TLS change, as are the authorization, SCIM, LDAP, organization, workflow, and UI changes included in this PR. Split these unrelated changes into their corresponding PRs so this issue can be reviewed and released as a focused TLS fix.

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.

8

Pull request overview

Copilot reviewed 19 out of 32 changed files in this pull request and generated 10 comments.

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.

Pull request overview

Copilot reviewed 19 out of 32 changed files in this pull request and generated no new comments.

Suppressed comments (2)

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:533

  • This validation is also called for HTTPS_MANAGEMENT_KEY_STORE_*, but its remediation only names the main HTTP PEM options. A management keystore configured as PEM therefore receives instructions that would configure the wrong listener; include the management PEM option equivalents.
        String explicitType = getOptionalKcValue(storeTypeOption.getKey()).orElse(null);
        if (explicitType != null && "PEM".equalsIgnoreCase(explicitType)) {
            throw new PropertyException("'%s' cannot be set to 'PEM' when '%s' is used. "
                    .formatted(storeTypeOption.getKey(), storeFileOption.getKey())
                    + "Use '--https-certificate-file' and '--https-certificate-key-file' for PEM certificates.");

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:505

  • For a management-only PEM configuration, this error directs the operator to https-key-store-file, which configures the main HTTPS listener rather than the failing management listener. Mention https-management-key-store-file as the management equivalent so the remediation is valid for both branches of this condition.

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

        if (getOptionalKcValue(HttpOptions.HTTPS_CERTIFICATE_FILE.getKey()).isPresent()
                || getOptionalKcValue(ManagementOptions.HTTPS_MANAGEMENT_CERTIFICATE_FILE.getKey()).isPresent()) {
            throw new PropertyException(
                    "PEM certificates are not supported in FIPS mode. Use a BCFKS keystore with the 'https-key-store-file' option instead.");

@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.forms.BruteForceTest#testExceedMaxTemporaryLockouts

Keycloak CI - Base IT (5)

org.opentest4j.AssertionFailedError: Expected error event ==> expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
...

Report flaky test

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.

Pull request overview

Copilot reviewed 19 out of 32 changed files in this pull request and generated no new comments.

Suppressed comments (1)

docs/guides/server/enabletls.adoc:30

  • This example exposes the private-key passphrase in shell history and the process argument list, contradicting the guidance below to avoid command-line passwords. Let OpenSSL prompt for the passphrase instead.
openssl genpkey -algorithm RSA -out keyfile.pem -aes-256-cbc -pass pass:<password>

@michalvavrik
Copy link
Copy Markdown
Member Author

Copilot seems to be happy for the moment being.

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

Just a couple of minor comments.

Comment thread docs/guides/server/enabletls.adoc Resolved
@@ -146,7 +146,7 @@ public void rejectNonNormalizedPathFilter(RuntimeValue<Router> runtimeValue) {

public void misdirectedRequestFilter(RuntimeValue<Router> runtimeValue) {
// not checking for http/2 enablement - it is enabled by default and not exposed as a supported configuration option
if (!Configuration.isTrue(HttpPropertyMappers.QUARKUS_HTTPS_SNI) || !HttpPropertyMappers.isHttpsEnabled() || Configuration.getConfigValue(ProxyOptions.PROXY_HEADERS).getValue() != null) {
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.

Configuration.isTrue(HttpPropertyMappers.QUARKUS_HTTPS_SNI) was initially part of this check because our sni option was going to be hidden, not synthetic. It's fine to remove it and we can revisit this if / when we want to give users control over whether SNI is enabled. Or if the mapping to QUARKUS_HTTPS_SNI is added back, then I'd also restore this check.

}

private static boolean isSniEnabled() {
return HttpPropertyMappers.isHttpsEnabled()
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.

Wouldn't it be clearer to just leave the mapping to QUARKUS_HTTPS_SNI and check Configuration.isTrue(HttpPropertyMappers.QUARKUS_HTTPS_SNI) here? Or does leaving that mapping in place cause buggy behavior?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wouldn't it be clearer to just leave the mapping to QUARKUS_HTTPS_SNI and check Configuration.isTrue(HttpPropertyMappers.QUARKUS_HTTPS_SNI) here? Or does leaving that mapping in place cause buggy behavior?

quarkus.http.ssl.sni is completely ignored when using TLS registry. It is set in https://github.com/quarkusio/quarkus/blob/fdf46612bd476f148e3c27a8fcc5c69c1c3519ba/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/options/HttpServerOptionsUtils.java#L622 and its invocations are never reached when using TLS registry.

I think you mean like "set it but don't expect Quarkus to do anything". It sounds more confusing to me, but there are other ways to do it, e.g. I could introduce some internal configuration property of something.

Personally I'd keep it as is and when Clement is back by the end of the month, I'll push for changes upstream. Or did you mean it differently? I don't really mind setting that property if you feel strongly about this.

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.

quarkus.http.ssl.sni is completely ignored when using TLS registry

Sure, but aren't you now referencing quarkus.tls."keycloak-https-server".key-store.sni as the HttpPropertyMappers.QUARKUS_HTTPS_SNI key?

Or did you mean it differently? I don't really mind setting that property if you feel strongly about this.

I just had the impression from the workaround that we would be eventually setting quarkus.tls."keycloak-https-server".key-store.sni, so it seemed cleaner to just do that now then later remove the customizer without any other changes.

If you'd rather leave it as is, that's fine too.

@michalvavrik michalvavrik Aug 11, 2026 •
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, but aren't you now referencing quarkus.tls."keycloak-https-server".key-store.sni as the HttpPropertyMappers.QUARKUS_HTTPS_SNI key?

Ah sorry, I don't remember by heart what these constants meant. I cannot set quarkus.tls."keycloak-https-server".key-store.sni because there is a validation in Quarkus TLS registry extension that keystore has more than 1 alias and application startup fails.

I just had the impression from the workaround that we would be eventually setting quarkus.tls."keycloak-https-server".key-store.sni, so it seemed cleaner to just do that now then later remove the customizer without any other changes.

Once upstream relaxes validation (or provides another way to work around this) I think we will be setting this property and then, we can apply your suggestion.

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.

Sounds good.

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.

Pull request overview

Copilot reviewed 19 out of 32 changed files in this pull request and generated no new comments.

Suppressed comments (3)

quarkus/tests/integration/src/test-providers/java/org/keycloak/it/resource/realm/TestRealmResource.java:133

  • The TLS bucket name is hard-coded here while the production code defines it as a constant (e.g., HttpPropertyMappers.TLS_BUCKET). To reduce drift risk, reference the shared constant (or a single shared test constant) instead of duplicating the string literal.
            String tlsBucket = "keycloak-https-server";
            var registry = CDI.current().select(TlsConfigurationRegistry.class).get();
            TlsConfiguration config = registry.get(tlsBucket).orElseThrow();

quarkus/tests/integration/src/test-providers/java/org/keycloak/it/resource/realm/TestRealmResource.java:144

  • The endpoint manually builds JSON strings and injects e.getMessage() without escaping. This can produce invalid JSON and can reflect arbitrary content into the response. Prefer returning a structured object (e.g., a Map serialized via existing JSON utilities) and avoid echoing raw exception messages; if you must return an error detail, sanitize/escape it first.
            return Response.ok("{\"reloaded\":" + reloaded + "}", MediaType.APPLICATION_JSON).build();
        } catch (Exception e) {
            logger.error("TLS reload failed", e);
            return Response.serverError().entity("{\"error\":\"" + e.getMessage() + "\"}").build();
        }

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:528

  • For StoreType.OTHER (e.g., when the extension clearly indicates BCFKS), the exception message says the type cannot be determined, which is misleading—the code did determine it's an unsupported/"other" type without an explicit --*-type. Consider adjusting the second error to explicitly state that the store appears to be an unsupported/BCFKS type and requires setting --<store-type-option>=BCFKS (or the appropriate type) when using that extension.
    private static void validateStoreType(Option<File> storeFileOption, Option<String> storeTypeOption, StoreRole role) {
        String filePath = getOptionalKcValue(storeFileOption.getKey()).orElse(null);
        if (filePath == null) {
            return;
        }
        String explicitType = getOptionalKcValue(storeTypeOption.getKey()).orElse(null);
        StoreType detected = detectStoreType(explicitType, filePath, role);
        if (detected == null) {
            throw new PropertyException("Unable to determine '%s' automatically. Adjust the file extension or specify the property."
                    .formatted(storeTypeOption.getKey()));
        }
        if (detected == StoreType.OTHER && explicitType == null) {
            throw new PropertyException("Unable to determine '%s' automatically. Adjust the file extension or specify the property."
                    .formatted(storeTypeOption.getKey()));
        }
    }

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.

Pull request overview

Copilot reviewed 19 out of 32 changed files in this pull request and generated no new comments.

Suppressed comments (6)

quarkus/config-api/src/main/java/org/keycloak/config/HttpOptions.java:95

  • The newly added password option is not marked as masked. This can lead to accidental exposure (e.g., in config dumps/help rendering/logging paths that honor option metadata). Mark this option as masked (consistent with other *-password options) so it is redacted wherever supported.
    public static final Option<String> HTTPS_CERTIFICATE_KEY_FILE_PASSWORD = new OptionBuilder<>("https-certificate-key-file-password", String.class)
            .category(OptionCategory.HTTP)
            .description("The password to decrypt an encrypted private key in PEM format (encrypted PKCS#8).")
            .build();

quarkus/config-api/src/main/java/org/keycloak/config/ManagementOptions.java:123

  • Same as the HTTP variant: the newly added management password option should be marked as masked to avoid accidental exposure via any tooling that prints option values/metadata.
    public static final Option<String> HTTPS_MANAGEMENT_CERTIFICATE_KEY_FILE_PASSWORD = new OptionBuilder<>("https-management-certificate-key-file-password", String.class)
            .category(OptionCategory.MANAGEMENT)
            .description("The password to decrypt an encrypted private key in PEM format for the management server. If not given, the value is inherited from HTTP options. " + RELEVANT_MSG)
            .build();

quarkus/tests/integration/src/test-providers/java/org/keycloak/it/resource/realm/TestRealmResource.java:145

  • The error response builds JSON via string concatenation without escaping e.getMessage(), which can produce invalid JSON (quotes/newlines) and potentially leak raw exception text into a JSON context. Also, the server error response doesn't set Content-Type: application/json. Prefer serializing a structured object/map via the existing JsonSerialization utility (already used in this class) and explicitly set the JSON media type for error responses.
    @Path("tls-reload")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response triggerTlsReload() {
        try {
            String tlsBucket = "keycloak-https-server";
            var registry = CDI.current().select(TlsConfigurationRegistry.class).get();
            TlsConfiguration config = registry.get(tlsBucket).orElseThrow();
            boolean reloaded = config.reload();
            if (reloaded) {
                CDI.current().getBeanManager().getEvent()
                        .select(CertificateUpdatedEvent.class)
                        .fire(new CertificateUpdatedEvent(tlsBucket, config));
            }
            return Response.ok("{\"reloaded\":" + reloaded + "}", MediaType.APPLICATION_JSON).build();
        } catch (Exception e) {
            logger.error("TLS reload failed", e);
            return Response.serverError().entity("{\"error\":\"" + e.getMessage() + "\"}").build();
        }
    }

quarkus/tests/integration/src/test-providers/java/org/keycloak/it/resource/realm/TestRealmResource.java:131

  • The TLS bucket name is duplicated as a string literal. This couples the test endpoint to the runtime bucket naming and makes refactors error-prone. Consider centralizing the bucket identifier (e.g., by referencing a shared constant, or defining a single test constant mirroring HttpPropertyMappers.TLS_BUCKET) to avoid drift.
            String tlsBucket = "keycloak-https-server";

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/HttpPropertyMappers.java:463

  • The role parameter is unused in validateFipsStoreFormat, which makes the API misleading and suggests incomplete logic or leftover refactoring. Either remove the parameter or use it to clarify behavior (e.g., enforce format rules only for key stores, if that's the intent).
    private static void validateFipsStoreFormat(Option<File> storeFileOption, Option<String> storeTypeOption, StoreRole role) {
        String fipsMode = getOptionalKcValue(SecurityOptions.FIPS_MODE.getKey()).orElse(null);
        if (!FipsMode.STRICT.toString().equals(fipsMode)) {
            return;
        }
        if (Configuration.isSet(storeTypeOption)) {
            return;
        }

docs/guides/server/enabletls.adoc:37

  • This OpenSSL example will typically prompt for the output passphrase interactively because it doesn't specify -passout. If the intent is a copy/pasteable non-interactive example (especially for automation), consider adding an explicit -passout argument (and -passin when applicable).
----
openssl pkcs8 -topk8 -in unencrypted.pem -out encrypted.pem -v2 aes-256-cbc
----

closes: keycloak#27437

Signed-off-by: Michal Vavřík <dev@michalvavrik.net>
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.

Pull request overview

Copilot reviewed 19 out of 32 changed files in this pull request and generated no new comments.

Suppressed comments (3)

quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/services/KeycloakHttpServerOptionsCustomizer.java:14

  • This new runtime class is missing the standard project license/header comment block present in other Java sources in this PR. Add the repository’s usual copyright + Apache License header to keep licensing consistent.
package org.keycloak.quarkus.runtime.services;

import jakarta.inject.Singleton;

import org.keycloak.config.ProxyOptions;
import org.keycloak.quarkus.runtime.configuration.Configuration;
import org.keycloak.quarkus.runtime.configuration.mappers.HttpPropertyMappers;

import io.quarkus.vertx.http.HttpServerOptionsCustomizer;
import io.vertx.core.http.HttpServerOptions;

// Workaround for https://github.com/quarkusio/quarkus/issues/55943
// Once fixed, remove this class and use the key-store.sni config property via HttpPropertyMappers instead.
@Singleton

quarkus/tests/integration/src/test-providers/java/org/keycloak/it/resource/realm/TestRealmResource.java:146

  • The error response concatenates e.getMessage() into a JSON string without escaping, which can produce invalid JSON and can reflect arbitrary content back to the caller. Prefer returning a typed DTO (like ReloadDto) or using existing JSON serialization utilities, and avoid exposing raw exception messages (return a generic message and keep details in logs). Also set the response media type explicitly for the error case.
    @Path("tls-reload")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response triggerTlsReload() {
        try {
            var registry = CDI.current().select(TlsConfigurationRegistry.class).get();
            TlsConfiguration config = registry.get(HttpPropertyMappers.TLS_BUCKET).orElseThrow();
            boolean reloaded = config.reload();
            if (reloaded) {
                CDI.current().getBeanManager().getEvent()
                        .select(CertificateUpdatedEvent.class)
                        .fire(new CertificateUpdatedEvent(HttpPropertyMappers.TLS_BUCKET, config));
            }
            record ReloadDto(boolean reloaded) {}
            return Response.ok(new ReloadDto(reloaded), MediaType.APPLICATION_JSON).build();
        } catch (Exception e) {
            logger.error("TLS reload failed", e);
            return Response.serverError().entity("{\"error\":\"" + e.getMessage() + "\"}").build();
        }
    }

docs/guides/server/enabletls.adoc:25

  • Using <password> inside the command example can be interpreted as placeholder markup and also looks like guidance to pass a literal password on the CLI (even though the text later discourages that). Consider switching the example to an environment-variable form (e.g., --https-certificate-key-file-password=$PASSWORD) or to a clearly non-literal placeholder that doesn’t use angle brackets.
If your PEM private key is encrypted (PKCS#8 encrypted format), provide the decryption password using the `https-certificate-key-file-password` option:

<@kc.start parameters="--https-certificate-file=/path/to/certfile.pem --https-certificate-key-file=/path/to/encrypted-keyfile.pem --https-certificate-key-file-password=<password>"/>

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

With the confirmation of the validations and explanation of the sni handling, this looks good to me.

It's great to finally be aligned with the tls registry - after looking more at the system truststore, we could consider future integration that allows users can create named tls configurations for use in various contexts.

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

Thanks @michalvavrik. High level this looks good to me, however I didn't looked into this deeply, so relying on @shawkins' review here.

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.

Accept encrypted PEM TLS certificate key

4 participants

0