core icon indicating copy to clipboard operation
core copied to clipboard

LDAP User Clean up

Open bboule opened this issue 13 years ago • 29 comments

When deleting a user in LDAP there is data left behind in the ownCloud database (i.e. shares to and from the deleted user and group memberships etc. Is there a way to clean this up to prevent database bloat (ie API calls that can be made). Or is it safe to clean this up manually perhaps via a script?

Thanks!!

bboule avatar Mar 06 '13 03:03 bboule

What you can do is to add a PHP script which is called when an LDAP server has been removed. There you pass the corresponding UUID. The script then

  1. gets the internal name for this user
  2. throws the hooks pre_deleteUser hook
  3. cleans the line in oc_ldap_user_mapping with the corresponding UUID and username
  4. throws the post_deleteUser hooks You also need to hope that all apps (like Sharing of Bookmarks) will clean their stuff of this user (the hooks are for this). I do not know whether they are doing, but really every app that stores the usename somewhere would need to do it.

blizzz avatar Mar 06 '13 07:03 blizzz

What the LDAP backend could do is to regularly fetch all available users and act when users vanish. But it is pretty error prone, could blow up on configuration error or when users are disabled for ownCloud on LDAP side but not deleted.

blizzz avatar Mar 06 '13 08:03 blizzz

Thanks @blizzz @MTRichards looks like a feature request for user removal cleanup automation?

bboule avatar Mar 06 '13 14:03 bboule

Yes. Sees to be a feature request and not really a bug.

karlitschek avatar Apr 12 '13 10:04 karlitschek

Hey guys, I will remove the Engineering tag from this and reassign to @MTRichards for future consideration and set expectations accordingly...

bboule avatar Apr 12 '13 12:04 bboule

Thanks @bboule, this is something we have been looking into for some time - it is why most LDAP / AD installations have one time use usernames that are unique and can never be reused. However, the need to clean up remains on the backlog.

MTRichards avatar Apr 12 '13 13:04 MTRichards

So what about this here? I set the milestone to »Maybe someday«.

jancborchardt avatar Aug 07 '13 18:08 jancborchardt

Need too... Maybe dev by me...

epinet avatar Oct 16 '13 12:10 epinet

I would need to know when this issue will be solved due to an actual incident. Is there a fix to come with 6.0.2 e.g.?

dietmaroc avatar Feb 13 '14 17:02 dietmaroc

I would need to know when this issue will be solved due to an actual incident. Is there a fix to come with 6.0.2 e.g.?

As pointed out by @karlitschek this is not a bug but a feature to be implemented one day. https://github.com/owncloud/core/issues/2121#issuecomment-16286422

From my understanding there is no target milestone for delivering this.

@dietmaroc How does the incident looks like you are facing? Maybe manual clean up will help?

DeepDiver1975 avatar Feb 13 '14 22:02 DeepDiver1975

Additionally to @DeepDiver1975 s statement, please let my point out that for this brief "clean up idea" there are no details specified on what is expected. I gave two alternative ideas above with a manual approach and an error prone automatic approach. I was more elaborate on the latter in another context. We could also implement a command line tool that looks for unexisting users and offers to delete them. But this is already about implementations. Please state the user story here.

blizzz avatar Feb 14 '14 07:02 blizzz

What happens when you have a large amount of users that are just for a few months in a project or students that finished their period in the school/university. What happens when you have a large amount of "volatile" user? They should not keep the private data after. A manual way to erase it will take the administrators a long time to manually (if they remember all the users). Additionally there is Calendar, bookmarks, news, etc. form each user who is not relevant for others and only makes the DB bigger. I mean, cleaning the DB is part of maintaining the information useful.

cdamken avatar Jun 13 '14 09:06 cdamken

Here too, we have customers using an AD in the background. They expect the user-data being deleted when they move a user out of their OC-group. As they pay per user on a monthly fee, this isn´t a feature this is needed in business. In my opinion this is a bug and not a feature request. It´s a bug that user that no longer use the system are still present. Wenn a user is removed his data should also be removed. Digging in the database and on the filesystem isn`t the right way to go.

merylen avatar Jul 16 '14 18:07 merylen

I'll get to it mid/end of August

blizzz avatar Jul 17 '14 08:07 blizzz

:+1:

cdamken avatar Jul 28 '14 14:07 cdamken

I've hit this issue too. We are an enterprise customer we we're looking to use the provisioning api to make a call to oc to clean up when we delete a user from ad. But user_ldap always returns false when trying to delete a user.

My solution is to test the request uri in user_ldap and if the action was triggered by the provisioning api, to return true. The normal process will proceed, hooks get fired, home directory gets deleted. That is the home directory gets deleted if the user still exists in the directory or their attributes are cached.

So you'd want to make the api call before deleting the user from the directory. But even if you don't you still will have a clean database and a directory to rm -R manually. Still much better than the current situation of home directories that never get deleted and a database full of records that will never be accessed again.

For those who don't have access to the provisioning api, perhaps a command line script is the best solution with a similar test in user_ldap to test if the trigger is that script and return true if it is. The script could also handle instances where the user has already been deleted from the directory by being able to take a home folder name as a command line option and remove it at the end of the process if it still exists. We use upn for home folder but uuid for internal name so separating them in such a command line script into to options (with home folder assumed to match internal name if not specified otherwise) would suit just about every scenario I can think of.

scolebrook avatar Jul 29 '14 18:07 scolebrook

But user_ldap always returns false when trying to delete a user.

Since do not write to LDAP false is always returned.

At least post delete hooks will be fired once we will detect deleted users (and groups) in LDAP.

blizzz avatar Aug 04 '14 11:08 blizzz

@blizzz but those hooks don't actually result in anything other than the opportunity to apps to clean themselves up. The database is still full of records pointing to non-existent users and the directory on the file system still needs to be removed. For a corporate deployment which is where an ldap backend is going to be used the most, ignoring the problem is not a solution. The current solution for corporate customers, predominantly the ones with paid enterprise licenses, is to do this work by hand or in some external script.

This method really should be returning true IMO with a simple note in the documentation stating that the user in the directory is not deleted, just the users data in OC, and that the user must still be removed from the backend directory. Anyone without the mental capability to understand such a separate should probably not be at the controls of an OC deployment.

scolebrook avatar Aug 04 '14 13:08 scolebrook

@blizzz but those hooks don't actually result in anything other than the opportunity to apps to clean themselves up.

Exactly. That's why we will need to have a look at the apps as well and add it if required. However, that mechanism should also effect that the user files are deleted.

This method really should be returning true IMO with a simple note in the documentation stating that the user in the directory is not deleted, just the users data in OC, and that the user must still be removed from the backend directory.

Which I find misleading, because the main task is to in fact delete the user. Simply returning true does feel wrong. The clean and working solution is to detect deleted users and fire up the hooks.

blizzz avatar Aug 04 '14 17:08 blizzz

Have a look at the flow in OC_User::deleteUser (/lib/private/user.php). It gets a OC\User\User object (/lib/private/user/user.php) and sends it a delete message. This is where hooks get fired and the backends do their thing. In the case of an ldap user the return value will be false. When execution returns to deleteUser that result is tested and because it's false, nothing is done. But deleteUser still returns true oddly enough simply because it found a user, even though it did nothing but fire hooks.

It is in this block that gets skipped that the home directory gets removed as well as other clean up tasks. So relying on hooks will mean moving everything out of this block of code and into handlers in various places. And at that point, the return value from the backend is immaterial. The only purpose it serves is to determine whether this little block of clean up code gets run or not.

So if we're going to use hooks to make sure the clean up code gets run every single time, then rather than testing the return value, wouldn't it simply be better to move the clean up code out of the if block and get rid of the test?

This will have the same effect as returning true. And it will affect all backends equally.

There has to be a specific reason why this code was put here separate to the hooks. I have only been using owncloud for a few months so I don't know the history. But perhaps that decision should be looked at and see if the reasons for it are still valid. If they are, then moving this code to hooks or out of the if block is not a solution.

scolebrook avatar Aug 04 '14 17:08 scolebrook