Refuse authentication service takeover of unrelated accounts - #27380
Open
dennisoelkers wants to merge 3 commits into
Open
dennisoelkers wants to merge 3 commits into
dennisoelkers wants to merge 3 commits into
Conversation
ProvisionerService looks an existing user up with
userService.loadByAuthServiceUidOrUsername(uid, username)
which matches on the authentication service UID *or* the username, and
then updates that account: it sets external to true, overwrites the
authentication service id and uid, the name and the email, and keeps the
roles and permissions that are already on it.
A username match alone says nothing about the account belonging to the
identity being provisioned. An external identity whose username happened
to equal a local account therefore inherited that account's roles - up to
the Admin role - on its first login, and the original user was locked out
because the internal backend refuses password logins for external users.
This applies to every backend: LDAP, Active Directory, OIDC, OAuth, SAML
and cloud Okta. The built-in root user was already safe because saving it
throws, but Mongo-backed administrators were not.
Provisioning now accepts an existing account only when the authentication
service UID matches, which is the same identity under a possibly new
username, or when the account is already external and managed by this
very authentication service, which covers a UID change. Anything else
fails with a message naming the conflict.
Deployments that rely on the old behaviour to migrate local accounts onto
an authentication service can set the new
allow_auth_service_account_takeover option, which defaults to false and
logs a warning whenever it lets a takeover through.
Also replaces orElse(createUser(...)) with orElseGet, which was building
a throwaway user on every provisioning run even when one was found.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Motivation and Context
ProvisionerServicelooks an existing user up withwhich matches on the authentication service UID or the username, and then updates that account: it sets external to true, overwrites the authentication service id and uid, the name and the email, and keeps the roles and permissions that are already on it.
A username match alone says nothing about the account belonging to the identity being provisioned. An external identity whose username happened to equal a local account therefore inherited that account's roles - up to the Admin role - on its first login, and the original user was locked out because the internal backend refuses password logins for external users. This applies to every backend: LDAP, Active Directory, OIDC, OAuth, SAML and cloud Okta. The built-in root user was already safe because saving it throws, but Mongo-backed administrators were not.
Provisioning now accepts an existing account only when the authentication service UID matches, which is the same identity under a possibly new username, or when the account is already external and managed by this very authentication service, which covers a UID change. Anything else fails with a message naming the conflict.
Deployments that rely on the old behaviour to migrate local accounts onto an authentication service can set the new allow_auth_service_account_takeover option, which defaults to false and logs a warning whenever it lets a takeover through.
Also replaces
orElse(createUser(...))withorElseGet, which was building a throwaway user on every provisioning run even when one was found.How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: