Skip to content

Conversation

@blizzz
Copy link
Member

@blizzz blizzz commented Nov 7, 2025

Summary

As of 155b750 we cache the user id and LDAP DN for a month, because they are highly requested, but rarely change and we have a working repair mechanism.

But if an LDAP user is deleted, the information is still cached. So a user that is being regenerated with the same target user ID will get a _xxxx suffix, when the data is still in local cache.

The error case can be reproduced:

  1. memcache.local is set to ACPu
  2. Log in and out with an LDAP user: 88ce7e0d-cd84-46ab-99c9-d49c1b2aba48
  3. occ user:info 88ce7e0d-cd84-46ab-99c9-d49c1b2aba48 shows info about that user
  4. Locally delete that user: occ ldap:reset-user 88ce7e0d-cd84-46ab-99c9-d49c1b2aba48
  5. Log in with that user again
  6. occ user:info 88ce7e0d-cd84-46ab-99c9-d49c1b2aba48 shows that the user does not exist
  7. When you look into oc_ldap_user_mapping, you will find a mapping with a _1234 suffix.

Checklist

@blizzz blizzz added this to the Nextcloud 33 milestone Nov 7, 2025
@blizzz blizzz requested a review from come-nc November 7, 2025 19:36
@blizzz blizzz requested a review from a team as a code owner November 7, 2025 19:36
@blizzz blizzz added the bug label Nov 7, 2025
@blizzz blizzz requested review from ArtificialOwl and icewind1991 and removed request for a team November 7, 2025 19:36
@blizzz blizzz added the 3. to review Waiting for reviews label Nov 7, 2025
@blizzz blizzz requested a review from yemkareems November 7, 2025 19:36
@blizzz
Copy link
Member Author

blizzz commented Nov 7, 2025

/backport to stable32

@blizzz blizzz force-pushed the fix/noid/ldap-regenerate-deleted-user branch from c9f26d9 to bf0cc66 Compare November 10, 2025 12:54
As of 155b750 we cache the user id and
LDAP DN for a month, because they are highly requested, but rarely change
and we have a working repair mechanism.

But if an LDAP user is deleted, the information is still cached. So a user
that is being regenerated with the same target user ID will get a _xxxx
suffix, when the data is still in local cache.

Signed-off-by: Arthur Schiwon <[email protected]>
@blizzz blizzz force-pushed the fix/noid/ldap-regenerate-deleted-user branch from bf0cc66 to 5ce8e06 Compare November 10, 2025 16:46
Comment on lines +625 to +627
$dude = $this->ncUserManager->get($intName);
$dude->getBackendClassName() === 'LDAP';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$dude = $this->ncUserManager->get($intName);
$dude->getBackendClassName() === 'LDAP';

left-over?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops 🙂 yes

Comment on lines +602 to +605
// DN might be cached if the user was deleted within last month.
// If it was a valid user we would have returned earlier at the
// $mapper->getNameByDN($fdn) call, which does not run against the cache.
|| $this->ncUserManager->get($intName)?->getBackendClassName() === 'LDAP'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand the getNameByDN part of the comment.
I do not see what prevents collisions with this PR.
If I set username to a non-unique LDAP attribute, with this PR I will run into trouble no?

Would be way cleaner to either clear on ignore the cache in this code path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is the problem, it relies on certain behavior inside the Mappings class. More later.

If I set username to a non-unique LDAP attribute, with this PR I will run into trouble no?

No, I don't see why you would.

Would be way cleaner to either clear on ignore the cache in this code path.

I don't want to clear the whole cache, this is pointless for an edge case while the mechanism as a whole is quite effective!

The memcache uses the uid as key (we don't have it) and is not really searchable. So without making the structure bigger and more redundant, which should be avoided, we can make the mapper more complicated:

  • remember all DNs that do not resolve in a name (runtime only)
  • if we encounter a cache hit involving such a DN, reset the cache entry and discard the value

What I don't like about this approach is that cache logic and mechanism are spread along the mapping. But it is better than the current approach, which relies on certain behaviour in different classes (this gives me the stomach aches tbh).

The good thing is that wrong values don't hurt, they'll be repaired (as long as the cached DN is not-existing that is).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I set username to a non-unique LDAP attribute, with this PR I will run into trouble no?

No, I don't see why you would.

To me it looks like this change defeats the collision detection mechanism.
If a user already exists with the same uid, it will happily return it even if it’s not the same one. Or did I miss where there is a check that the existing user and the new one are the same?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that still works:

Screenshot_20251124_190822

Also works through web interface (with memcache in action).

Reason is that mapAndAnnounceIfApplicable() will return false due to database constraints (cf. AbstractMapping::map()).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevertheless, would still tend to move it into the mapping. I don't like the reliance on inner workings of other modules, as stated in #56292 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants