Mask vault password in show-config#51013
Conversation
Mark the vault password mapper as sensitive and ignore duplicate SmallRye environment aliases so the password is never shown in show-config output. Closes keycloak#50844 Signed-off-by: Akash Kumar <meakash7902@gmail.com>
There was a problem hiding this comment.
Pull request overview
Masks vault passwords in show-config and removes plaintext duplicates produced by environment-variable normalization.
Changes:
- Marks the vault password mapper as sensitive.
- Suppresses noncanonical
KC_*environment entries. - Adds regression tests for public and mapped vault password properties.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
ShowConfigCommandDistTest.java |
Tests vault password masking and plaintext exclusion. |
VaultPropertyMappers.java |
Marks vault passwords for masking. |
ShowConfig.java |
Filters normalized environment-variable duplicates. |
| PropertyMapper<?> mapper = PropertyMappers.getMapper(property); | ||
|
|
||
| // Ignore SmallRye-normalized duplicates of KC_* variables; KcEnvConfigSource provides the canonical keys. | ||
| if (mapper == null && property.startsWith(MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX) |
There was a problem hiding this comment.
This should be split off as a different issue. We don't generally expect the spi keys to be directly used when there is a first class option. This would also happen with more than just the env config source if the legacy key format is used - e.g. kc.spi-vault-keystore-pass
There was a problem hiding this comment.
This should be split off as a different issue. We don't generally expect the spi keys to be directly used when there is a first class option. This would also happen with more than just the env config source if the legacy key format is used - e.g. kc.spi-vault-keystore-pass
That test looks legit (I checked and it is failing without this), as long as users can set it, we should plan to fix it. In another issue is fine.
In SmallRye Config terms, we could just be using io.smallrye.config.FallbackConfigSourceInterceptor for the legacy key format and then, we could rely on "masked". But I know that Keycloak works differently, I'll not try to understand it more as this part will be handled in another issue.
There was a problem hiding this comment.
as long as users can set it
It's documented that you shouldn't use that and you should see a warning about using a "second-class" option, so it's much less of a concern that masking the proper configuration option for the vault password.
In SmallRye Config terms, we could just be using
io.smallrye.config.FallbackConfigSourceInterceptor
There's two related cases:
-
Our KC_SPI_FOO__BAR__KEY is turned into
kc.spi-foo--bar--keyby the KcEnvConfigSource, but the EnvConfigSource assumes that it's kc.spi.foo."bar".key - which is effectively what the proposed change is trying to filter here. -
What I'm highlighting, which is applicable to any config source, is that we support also kc.spi-foo-bar-key as an legacy alternative to the double dash version.
I don't think we looked at using the FallbackConfigSourceInterceptor for the second case - it's just being handled in the MicroProfileConfigProvider.
There was a problem hiding this comment.
Thanks.
Our KC_SPI_FOO__BAR__KEY is turned into kc.spi-foo--bar--key by the KcEnvConfigSource, but the EnvConfigSource assumes that it's kc.spi.foo."bar".key - which is effectively what the proposed change is trying to filter here.
IIRC SR Config assumes this when it doesn't know there is such a property as kc.spi-foo--bar--key, which is why when you are mapping env vars to such properties you are supposed to also declare them in some dotted config source with lower priority.
I do not say it is a solution, I'll not work on this as we agreed it is a separate issue. I appreciate the context, thanks again.
There was a problem hiding this comment.
which is why when you are mapping env vars to such properties you are supposed to also declare them in some dotted config source with lower priority
Does it need to be lower priority - wouldn't that have to be a .env or in the application.properties?
I thought it was aware of kc.spi-foo--bar--key in the KcEnvConfigSource but does not consider it a match for KC_SPI_FOO__BAR__KEY because of the conversion rule to double quotes being superseding.
In any case, let's remove this change from the PR and move this discussion over to #51113
There was a problem hiding this comment.
Does it need to be lower priority - wouldn't that have to be a .env or in the application.properties?
I don't know, I don't keep up to date knowledge of SR Config internals because it keeps changing like crazy. https://smallrye.io/smallrye-config/Main/config/environment-variables/ doesn't mention priority, it just says a dotted config source. There is "It can be set in a low ordinal source, even without value." but that doesn't mean it can't work with the higher one.
I said lower priority because that is what I did in the past when using K8 extension to specify env vars, env vars to dotted prop names is ambiguous, so when we created it in a dotted format with stale values, it started working as they were overridden by the env vars.
I thought it was aware of kc.spi-foo--bar--key in the KcEnvConfigSource but does not consider it a match for KC_SPI_FOO__BAR__KEY because of the conversion rule to double quotes being superseding.
Sorry for being slow, but I don't understand why kc.spi-foo--bar--key shouldn't be resolved to KC_SPI_FOO__BAR__KEY if the former is specified somewhere. I may just don't know about that rule and it is my bad!
In any case, let's remove this change from the PR and move this discussion over to #51113
Absolutely. I assume it will be clear when I sit down on it, I still didn't debug it, maybe I shouldn't say anything until then.
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
shawkins
left a comment
There was a problem hiding this comment.
LGTM - removed the additional logic and test, so that it can be addressed under the other issue.
Unreported flaky test detectedIf 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.MultipleTabsLoginTest#multipleTabsParallelLoginTestWithAuthSessionExpiredAndRegisterClickKeycloak CI - Forms IT (firefox) |
Closes #50844
Summary
show-configmasks both the public option and its mapped SPI propertyKC_*variables becauseKcEnvConfigSourcealready provides their canonical keyskc.vault-passandkc.spi-vault--keystore--pass, including checks that plaintext secrets never appearTesting
./mvnw -pl quarkus/server,quarkus/dist -am -DskipTests -DskipTestsuite -DskipExamples install./mvnw test -pl quarkus/tests/integration -Dtest=ShowConfigCommandDistTest(9 tests passed)./mvnw -pl quarkus/runtime,quarkus/tests/integration -DskipTests spotless:checkAI assistance
This contribution was developed with assistance from OpenAI Codex agents. I reviewed and understand every change and am responsible for the implementation and for responding to review feedback.