#57656·rancher

[BUG] An auth provider refresh can undo changes made to a user while it runs

Author: pmatseykanetsCreated Sep 30, 2026Updated Sep 30, 2026
Labelskind/bugarea/authenticationteam/collieQA/SM

Problem

An auth provider refresh can overwrite changes made to the user while the refresh is running.

For example, SCIM removes a user from a group during a refresh. The refresh then writes the old group list back, and the user keeps the group's bindings until the IdP sends another change for that group. SCIM attribute changes made in the same window are lost too, and so are changes from a login.

The window lasts as long as the refresh. It calls the IdP and can take seconds.

In code:

  • The user attribute controller in pkg/controllers/management/auth reads the UserAttribute, runs the provider refresh on a copy, then updates the object.
  • If the update conflicts, it reads the object again, copies the refresh's GroupPrincipals and ExtraByProvider over it, and tries once more. Anything changed in between is replaced.
  • It doesn't refresh again on purpose. A refresh is expensive and repeated refreshes caused problems before. A second IdP call would also make another conflict more likely.

Solution

On conflict, apply only what the refresh changed, and leave the rest as the other writer left it.

The controller still has the copy it read before the refresh, so it can compare the result against it:

  • For each provider and extra key, a value the refresh changed replaces the current value.
  • For each provider, a group list the refresh changed replaces the current list.
  • An entry the refresh added counts as a change, even an empty one.
  • Anything the refresh didn't change keeps its current value.
  • NeedsRefresh and LastRefresh are copied as they are today.

Keep the single extra attempt. Don't refresh again or call the IdP again. If the attempt fails, return the original error so the object is queued again.

Acceptance

When a refresh's update conflicts, a group removal and an attribute change made in between both survive. The extras and groups the refresh itself changed are still applied, including an entry it added empty. The IdP is called once, and a second conflict returns the original error, as today.

The existing conflict test keeps passing, and new tests cover these cases.

Out of scope

If the refresh and SCIM both change one provider's group list during the same refresh, the refresh's list wins. Both lists come from the same IdP, and SCIM's next change to the group fixes it. Retrying the update more than once isn't part of this change.