-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(LDAP): unblock a cached id from a deleted user or group #56292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
blizzz
wants to merge
1
commit into
master
Choose a base branch
from
fix/noid/ldap-regenerate-deleted-user
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -57,6 +57,7 @@ public function __construct( | |||||
| private Helper $helper, | ||||||
| private IConfig $config, | ||||||
| private IUserManager $ncUserManager, | ||||||
| private IGroupManager $ncGroupManager, | ||||||
| private LoggerInterface $logger, | ||||||
| private IAppConfig $appConfig, | ||||||
| private IEventDispatcher $dispatcher, | ||||||
|
|
@@ -595,18 +596,35 @@ public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped | |||||
| $originalTTL = $this->connection->ldapCacheTTL; | ||||||
| $this->connection->setConfiguration(['ldapCacheTTL' => 0]); | ||||||
| if ($intName !== '' | ||||||
| && (($isUser && !$this->ncUserManager->userExists($intName)) | ||||||
| || (!$isUser && !Server::get(IGroupManager::class)->groupExists($intName)) | ||||||
| && (($isUser | ||||||
| && ( | ||||||
| !$this->ncUserManager->userExists($intName) | ||||||
| // 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' | ||||||
| )) | ||||||
| || (!$isUser | ||||||
| && ( | ||||||
| // DN might be cached if the group was deleted within last month. | ||||||
| // If it was a valid group we would have returned earlier at the | ||||||
| // $mapper->getNameByDN($fdn) call, which does not run against the cache. | ||||||
| !$this->ncGroupManager->groupExists($intName) | ||||||
| || in_array('LDAP', $this->ncGroupManager->get($intName)?->getBackendNames() ?? [], true) | ||||||
| )) | ||||||
| ) | ||||||
| ) { | ||||||
| $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]); | ||||||
| $newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser); | ||||||
| if ($newlyMapped) { | ||||||
| $this->logger->debug('Mapped {fdn} as {name}', ['fdn' => $fdn,'name' => $intName]); | ||||||
| $this->logger->debug('Mapped {fdn} as {name}', ['fdn' => $fdn, 'name' => $intName]); | ||||||
| return $intName; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| $dude = $this->ncUserManager->get($intName); | ||||||
| $dude->getBackendClassName() === 'LDAP'; | ||||||
|
|
||||||
|
Comment on lines
+625
to
+627
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
left-over?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops 🙂 yes |
||||||
| $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]); | ||||||
| $altName = $this->createAltInternalOwnCloudName($intName, $isUser); | ||||||
| if (is_string($altName)) { | ||||||
|
|
@@ -830,7 +848,7 @@ private function _createAltInternalOwnCloudNameForGroups(string $name) { | |||||
| // Check to be really sure it is unique | ||||||
| // while loop is just a precaution. If a name is not generated within | ||||||
| // 20 attempts, something else is very wrong. Avoids infinite loop. | ||||||
| if (!Server::get(IGroupManager::class)->groupExists($altName)) { | ||||||
| if (!$this->ncGroupManager->groupExists($altName)) { | ||||||
| return $altName; | ||||||
| } | ||||||
| $altName = $name . '_' . ($lastNo + $attempts); | ||||||
|
|
||||||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
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
getNameByDNpart 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.
There was a problem hiding this comment.
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.
No, I don't see why you would.
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:
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that still works:
Also works through web interface (with memcache in action).
Reason is that
mapAndAnnounceIfApplicable()will return false due to database constraints (cf. AbstractMapping::map()).There was a problem hiding this comment.
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).