8000 Support the password attribute in the SCIM User resource by costa-chown · Pull Request #55681 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Support the password attribute in the SCIM User resource - #55681

Open
costa-chown wants to merge 2 commits into
keycloak:mainfrom
costa-chown:scim-user-password
Open

costa-chown wants to merge 2 commits into
keycloak:mainfrom
costa-chown:scim-user-password

Conversation

@costa-chown
Copy link
Copy Markdown

Closes #55680

Adds the password attribute of the core User schema (RFC 7643, Section 4.1.1) to the SCIM User resource, following the shape @sguilhen outlined in #52957.

  • password is writeOnly and returned: never, and works on POST, PUT and PATCH. The schema endpoint now reports the mutability of each attribute (writeOnly was not representable before, only immutable and readWrite).
  • The value is staged while the user is populated and set once the user profile is persisted, through credentialManager().updateCredential(UserCredentialModel.password(password, false)), as the reset password endpoint of the Admin REST API does: an unconditional overwrite, the current password is not required. Only the password credential is touched.
  • A password that fails the password policy, or a blank password, is rejected with 400 and scimType: invalidValue (new ScimInvalidValueException). The message is the localized policy message, as for invalidSyntax. The transaction is rolled back, so a rejected POST creates no user and a rejected PUT changes nothing.
  • A PUT without password keeps the current password.
  • On POST and PUT, populateModel reads attribute values through JsonUtils.getJsonValue, which trims text and turns blank text into null. A password must be taken as sent, so write-only attributes are read untrimmed. Otherwise " secret " would silently become "secret" on create but not on PATCH, and a blank password would be ignored instead of rejected.
  • changePassword.supported is true in the Service Provider Configuration.
  • Documented in the SCIM chapter of the server admin guide, including the known gap: SCIM has no temporary password, so the UPDATE_PASSWORD required action is never added. Release note in 27.0.0.

Tests

  • UserTest: create with password (not returned on create or GET, valid credential, one password credential and no password user attribute); full replace without password keeps it and with password changes it; PATCH replace; policy violation (length(12)) on create, replace and patch returns invalidValue and leaves the password unchanged; blank password returns invalidValue; surrounding whitespace is kept on create and on PATCH.
  • SchemaTest: the core User schema has 15 attributes; password is writeOnly, returned: never, caseExact.
  • ServiceProviderConfigTest: changePassword is supported.
  • Checked by hand on 26.8.1 with the change applied: a user created through SCIM with a password logs in with it, the password policy of the realm applies, and the password is a credential, not an attribute.

The core User schema gets the password attribute of RFC 7643, Section
4.1.1: writeOnly, returned never, on POST, PUT and PATCH. It is set as the
password credential once the user is persisted, as the reset password
endpoint of the Admin REST API does, so the password policy of the realm
applies. A policy violation or a blank password is rejected with
scimType invalidValue. Write-only values are read as sent on POST and
PUT, not trimmed. The Service Provider Configuration reports
changePassword as supported.

Closes keycloak#55680

Signed-off-by: Konstantin Kauz <konstantin.kauz@opendefense.cloud>
@costa-chown
costa-chown requested a review from a team as a code owner December 1, 2026 05:28
Copilot AI balanced review requested due to automatic review settings December 1, 2026 05:28
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.

🟡 Changes recommended

SCIM PUT/PATCH lets callers with manage permission bypass an explicit reset-password denial, while password removal reports success without deleting the credential.

2 open issues
What changed in this PR

Adds password provisioning to Keycloak’s SCIM User resource, addressing #55680 so clients can set or rotate passwords without a separate Admin REST call.

Changes:

  • Supports write-only passwords through POST, PUT, and PATCH, and advertises password-change support.
  • Preserves password whitespace, applies realm password policies, and returns localized invalidValue errors.
  • Adds regression tests, administration guidance, and release notes.
File Description
scim/​tests/​base/​src/​test/​java/​org/​keycloak/​tests/​scim/​tck/​UserTest.java Tests password writes, policy rejection, response omission, and whitespace preservation.
scim/​tests/​base/​src/​test/​java/​org/​keycloak/​tests/​scim/​tck/​ServiceProviderConfigTest.java Expects password-change support.
scim/​tests/​base/​src/​test/​java/​org/​keycloak/​tests/​scim/​tck/​SchemaTest.java Verifies password schema metadata.
scim/​services/​src/​main/​java/​org/​keycloak/​scim/​services/​Error.java Maps invalid values to localized SCIM errors.
scim/​model/​src/​main/​java/​org/​keycloak/​scim/​model/​user/​UserResourceTypeProvider.java Writes staged passwords after profile persistence.
scim/​model/​src/​main/​java/​org/​keycloak/​scim/​model/​user/​UserModelAttributeRecorder.java Stages passwords separately from user attributes.
scim/​model/​src/​main/​java/​org/​keycloak/​scim/​model/​user/​UserCoreModelSchema.java Defines the write-only password mapping and rejects blank values.
scim/​model/​src/​main/​java/​org/​keycloak/​scim/​model/​schema/​SchemaResourceTypeProvider.java Publishes each attribute’s mutability.
scim/​model/​src/​main/​java/​org/​keycloak/​scim/​model/​config/​ServiceProviderConfigResourceTypeProvider.java Advertises password-change support.
scim/​core/​src/​main/​java/​org/​keycloak/​scim/​resource/​user/​User.java Adds the password field and accessors.
scim/​core/​src/​main/​java/​org/​keycloak/​scim/​resource/​spi/​ScimInvalidValueException.java Introduces an exception for invalid attribute values.
scim/​core/​src/​main/​java/​org/​keycloak/​scim/​resource/​schema/​attribute/​Attribute.java Adds write-only mutability support.
scim/​core/​src/​main/​java/​org/​keycloak/​scim/​resource/​schema/​AbstractModelSchema.java Preserves raw write-only values during population.
docs/​documentation/​server_admin/​topics/​scim/​managing-users.adoc Documents password operations, policy handling, and limitations.
docs/​documentation/​server_admin/​topics/​scim/​accessing-service-config.adoc Updates documented password-change capabilities.
docs/​documentation/​release_notes/​topics/​27_0_0.adoc Announces SCIM password support.

Review effort: Balanced

Setting a password through SCIM now needs the reset-password permission on
the user, as the Admin REST API does; managing the user is not enough. A
PATCH remove of the password is rejected with scimType invalidValue
instead of being ignored, also after an add in the same request. A PATCH
replace still works: its remove is followed by the new password.

Closes keycloak#55680

Signed-off-by: Konstantin Kauz <konstantin.kauz@opendefense.cloud>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 05:42
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 active review issues were identified for the SCIM password-provisioning change.

1 open issue
1 resolved since last review

Review effort: Balanced

@sguilhen
sguilhen requested a review from pedroigor December 4, 2026 14:25
@sguilhen sguilhen 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.

I've tried to review this one thoroughly, checking RFC conformance and permission parity with the Admin REST API. Left some detailed comments inline

  • Permission parity is correct in the direction that matters. canResetPassword falls back to canManage when no reset-password permission is defined, so the new DefaultPermissions branch is exactly what requireResetPassword already does, for plain RBAC, FGAP v1 and FGAP v2 alike. SCIM PUT/PATCH requires MANAGE(user) and isManageable and canResetPassword(user), which is strictly more than the Admin API's requireResetPassword(user) alone. I could not see a case where SCIM is more permissive than the Admin API. Two divergences go the other way, noted inline: the UPDATE_PASSWORD required action is never cleared, and create-with-password is stricter than POST /admin/realms/{realm}/users with credentials.

Blocking from my side: the ReadOnlyException 500, the UPDATE_PASSWORD parity gap, and caseExact. The rest are judgment calls I would like your view on rather than changes I am asking for.

Test gaps: create under FGAP v2 with a reset-password permission defined, a user federated from a read-only provider, UPDATE_PASSWORD handling on PUT/PATCH, and rollback of the sibling attribute on a denied PUT.

try {
// as the admin API does when it resets a password; the password policy of the realm applies
user.credentialManager().updateCredential(UserCredentialModel.password(password, false));
} catch (ModelException me) {
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.

ReadOnlyException extends RuntimeException, not ModelException, so this catch misses it and the request ends as a 500 with a stack trace in the server log.

getModel only requires StorageId.isLocalStorage, which is true for users imported from a federated provider, and LDAPStorageProvider.updateCredential throws ReadOnlyException when editMode is READ_ONLY. The Admin API catches it and returns 400 with "Can't reset password as account is read only".

Separately, ModelIllegalStateException also extends ModelException, so it currently surfaces as invalidValue with the raw message as detail. UserResource.resetPassword logs it and returns 500. Worth narrowing the catch for both.

UserModel user = recorder.getDelegate();

// as the admin API: managing a user does not imply resetting its password
if (!session.getContext().getPermissions().hasPermission(user, AdminPermissionsSchema.USERS_RESOURCE_TYPE, AdminPermissionsSchema.RESET_PASSWORD)) {
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.

Every other check in these providers goes through BaseResourceTypeProvider.hasPermission(model, type, scope), which additionally requires isManageable(model), that is, that the target is not an admin user. This call reaches Permissions directly and skips that guard.

I do not think it is exploitable today: PUT/PATCH already ran the guarded MANAGE check, POST creates a non-admin user, and checkGroupMembershipPermission rejects isAdminGroup, so a user cannot become an admin within the same request. But hasPermission(user, getRealmResourceType(), RESET_PASSWORD) is a one-line change that keeps the guard uniform and uses the resource type the class already defines.

throw handleValidationException(ve);
}

updatePassword(recorder);
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.

Authorization is enforced after the write: on POST the user row already exists from profile.create(false), and on PUT/PATCH profile.update(true) has already run. The 403 then depends entirely on setRollbackOnly in Error.toResponse.

That holds for database state, and the policy-violation tests prove it, but it makes the authorization outcome contingent on transaction handling rather than on a check. Checking the permission when the password is staged, in the model setter, would decide it before any mutation. At minimum, testPasswordDeniedWithoutResetPasswordFGAP should assert that the title sent in the same denied PUT was rolled back; right now it only asserts that no credential exists.

attributes.addAll(Attribute.<UserModel, User>simple("password")
.writeOnly()
.returned(Attribute.RETURNED_NEVER)
.caseExact()
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.

RFC 7643 Section 8.7.1 publishes "caseExact" : false for password. This sets it to true, and SchemaTest asserts true.

It has no functional effect here, since caseExact only drives filter case-folding in ScimJPAPredicateProvider and schema publication, but /Schemas is exactly what clients diff against the spec. I'd suggest dropping .caseExact() and updating the assertion.


UserModel user = recorder.getDelegate();

// as the admin API: managing a user does not imply resetting its password
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.

This is true for the reset password endpoint, but not for create. UsersResource.createUser requires only auth.users().requireManage() and never evaluates reset-password, even when the body carries credentials, so on the POST path this check is stricter than the Admin API rather than equivalent to it.

Under FGAP v2, once any reset-password permission exists the scope is evaluated, so the fallback to MANAGE in FineGrainedAdminPermissionEvaluator is skipped, and a brand-new user matches no resource-scoped permission. A client that can create users with credentials through the Admin API would get a 403 from SCIM. It fails closed, so it is not a security problem, but it is a parity gap, no test covers create under FGAP, and the comment reads as if the two paths match.

.writeOnly()
.returned(Attribute.RETURNED_NEVER)
.caseExact()
.modelAttributeResolver(Attribute::getName)
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.

Also, I think this has a side effect worth deciding on: this makes password resolvable as a filter path. ScimJPAPredicateProvider finds no password field on UserEntity and falls back to an EXISTS over UserAttributeEntity with name = 'password', so filter=password eq "x" always returns an empty page, and filter=password pr matches any user who happens to carry an unrelated user attribute named password.

No credential is exposed, so this is not a leak, but an empty page is a silently wrong answer to a filter RFC 7643 Section 4.1.1 explicitly contemplates ("set, replace, or compare (i.e., filter for equality)"). Rejecting filters on write-only attributes with invalidFilter would be clearer than answering them incorrectly.

throw new IllegalStateException("password can only be set while the user is persisted");
}
if (value.isBlank()) {
throw new ScimInvalidValueException("password must not be blank");
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.

This message, and "password cannot be removed", are raw English strings, while every other SCIM error message is a message bundle key.

user.setPassword(KeycloakModelUtils.generateId());
user.setTitle("Denied");
assertAccessDenied(() -> noAccessClient.users().update(user));
assertTrue(realm.admin().users().get(managedUser.getId()).credentials().isEmpty());
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.

This asserts the credential was not created, but not that the rest of the denied PUT was rolled back. Since the permission check runs after profile.update(true), the title set on line 617 is the interesting assertion here: it is what proves the 403 left nothing behind.

* Records a PATCH remove of the password and drops a password staged before it. A PATCH replace is a remove
* followed by an add, which stages the new password again.
*/
public void removePassword() {
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.

Whether a password remove is rejected depends on where it falls in the operation list, since all operations share one recorder. testRemovePasswordRejected covers add-then-remove, which is rejected. The reverse order, {"op":"remove","path":"password"} followed by {"op":"add","path":"password","value":"..."}, clears the flag again and succeeds, so the explicit remove is silently dropped instead of rejected.

That falls out of replace being remove plus add and I am not asking to change it, but the rule is really "a remove is rejected only when it is the last password operation in the request", which is worth stating in the javadoc here and pinning with a test.


Only the password credential is affected. Other credentials of the user, such as OTP or WebAuthn, are not managed through SCIM.

NOTE: A password set through SCIM is always permanent. SCIM has no equivalent of a temporary password, so the
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 the UPDATE_PASSWORD parity gap is not fixed, this note should also say that an existing Update Password required action is not removed either, unlike the Admin REST API reset password endpoint, so a user with one pending still has to change the password that was just provisioned.

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.

Support the password attribute in the SCIM User resource

3 participants

0