Redact operational info from server info - #51190
Conversation
There was a problem hiding this comment.
Pull request overview
Redacts sensitive database connection details from server info unless the caller can manage the master realm.
Changes:
- Filters database URL and username from provider operational information.
- Centralizes operational-information key constants.
- Adds permission-focused integration coverage.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
ServerInfoPermissionsTest.java |
Tests database detail visibility by permission level. |
ServerInfoAdminResource.java |
Applies permission-based redaction. |
ServerInfoAwareProviderFactory.java |
Defines shared database key constants. |
QuarkusJpaConnectionProviderFactory.java |
Uses shared constants. |
DefaultJpaConnectionProviderFactory.java |
Uses shared constants. |
9174f08 to
50dc575
Compare
|
Added couple of reviewers, anyone of them that happens to have a time will do. Thanks |
|
PR CI failures seem unrelated, I found already reported issue: #51191. |
50dc575 to
f64954d
Compare
| @Extension(name = KeycloakOpenAPI.Profiles.ADMIN , value = "") | ||
| public class ServerInfoAdminResource { | ||
|
|
||
| private static final Set<String> SENSITIVE_OPERATIONAL_INFO_KEYS = Set.of(OPERATIONAL_INFO_DATABASE_URL, OPERATIONAL_INFO_DATABASE_USER); |
There was a problem hiding this comment.
I'd like to see this rather driven by the ServerInfoAwareProviderFactory than hardcoded here. This would make it more explicit, and also would work better for extensions.
There was a problem hiding this comment.
We could add a new method to ServerInfoAwareProviderFactory, something like getOperationalInfoSensitiveKeys.
There was a problem hiding this comment.
Or, maybe even introduce a breaking change and make it secure by default by having "allowlist" instead of "denylist": getOperationalInfoNonSensitiveKeys.
There was a problem hiding this comment.
Or, maybe even introduce a breaking change and make it secure by default by having "allowlist" instead of "denylist":
getOperationalInfoNonSensitiveKeys.
I inspected all keys I could find before opening this PR, this is edge case, I don't think it is necessary. I'll provide getOperationalInfoSensitiveKeys as suggested. If you prefer the breaking change, np, just let me know.
There was a problem hiding this comment.
TBH I can't link suggested names to the description, e.g. getOperationalInfoNonSensitiveKeys doesn't seem like breaking change. I'll just do something and you can simply comment again when you see it.
There was a problem hiding this comment.
Done. Check and just comment on the current code if you want it written differently. Thanks
f64954d to
0328bfb
Compare
0328bfb to
a3df209
Compare
| default Map<String, String> getNonSensitiveOperationalInfo() { | ||
| return getOperationalInfo(); |
There was a problem hiding this comment.
I don't understand this comment, there is no provider that I can see which returns them. I already had this on REST-layer and it was requested that I don't do it there. If some provider needs adjustments, I am sure maintainers of that provider will act...
There was a problem hiding this comment.
But nice to know that Copilot agrees with me in regards of the REST layer :-)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
server-spi-private/src/main/java/org/keycloak/provider/ServerInfoAwareProviderFactory.java:45
- This default is fail-open: factories that already implement this SPI (including custom JPA providers) but do not override the new method return their full map, so
databaseUrlanddatabaseUserremain exposed to delegated admins. Filter the known sensitive keys in the default (or centrally in the REST resource) so the authorization boundary does not depend on every provider opting in.
default Map<String, String> getNonSensitiveOperationalInfo() {
return getOperationalInfo();
}
a3df209 to
f0fb804
Compare
|
Just wanted to double check - is there a case to be made that non-master admins should not be able to see any operational info? None of this information is realm specific and leaks configuration details they may otherwise not know or need to know. Some of it should now also be available via metrics also. And does this issue / PR need to be linked under #48961 ? |
Thanks @shawkins. Maybe this is more question for others. I thought about this before but how can I tell without intention being written down somewhere. Existing code counts on non-admin (e.g. master) realm admins to see it. You can see cpu info / memory info / system info are not shown to them, just system info version. At the very least it would be a breaking change?
I agree, none of this is realm-specific.
Whatever works for you. My intention was to fix the weakness (the linked issue), which is a subset of that enhancement request. |
ahus1
left a comment
There was a problem hiding this comment.
Hello @michalvavrik - thank you for the PR.
While I see that the PR follows the original issue by the letter when it made showing this information conditionally (if I understand this correctly).
I suppose this code could be simplified by just removing those two items completely, all the time, for everyone. It would make this a lot simpler; and might even need fewer tests for that.
BTW, removing this information is not a breaking change. If you want to be extra safe, one could add it to the notable changes; but I'm ok to skip that part.
I'm adding this as a comment, and not "requesting changes", as this is the area of the cloud native team.
I am fine with this proposal and if that is consensus among other reviewers as well, I am happy to follow it.
@ahus1 if non-master admin saw this information and now they don't, based on what information do we know no user needs it? Can you provide some information that I don't have or maybe clarify your thoughts? It feels natural to me to follow the principle of least privilege and try to avoid issuing master-admin when possible. |
closes: keycloak#51139 Signed-off-by: Michal Vavřík <dev@michalvavrik.net>
f0fb804 to
33d9dd0
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
tests/base/src/test/java/org/keycloak/tests/admin/ServerInfoPermissionsTest.java:94
- The PR title and #51139 scope redaction to callers without server-level permissions, but these assertions require the fields to be absent for
master-adminand a master-realmmanage-realmadministrator, while never exercising the reported delegatedVIEW_REALMcaller. This codifies the source-level removal for all administrators and unnecessarily drops existing operational details from authorized server admins; preserve them for authorized callers and test redaction with the delegated role instead.
// databaseUrl and databaseUser are never exposed in server info
assertDatabaseConnectionInfoNotExposed(clients.get("master-admin").serverInfo().getInfo());
assertDatabaseConnectionInfoNotExposed(clients.get("master-admin-" + AdminRoles.MANAGE_REALM).serverInfo().getInfo());
|
I pushed suggested changes. Frankly, I am not convinced, but it probably doesn't matter, in the end whatever addresses this weakness will work as long as reviewers believe it is correct. Little recap:
if someone has another suggestion, please shout |
Uh oh!
There was an error while loading. Please reload this page.