Change uidNumber and gidNumber for billions of files
Hello Everyone, We are planning to migrate from LDAP to AD, and one of the best solution was to change the uidNumber and gidNumber to what SSSD or Centrify would resolve. May I know, if anyone has come across a tool/tools that can change the uidNumbers and gidNumbers of billions of files efficiently and in a reliable manner? We could spend some time to write a custom script, but wanted to know if a tool already exists. Please do let me know, if any one else has come across a similar situation, and the steps/tools used to resolve the same. Regards, Lohit
You will need to do this with chown from the c library functions (could do this from perl or python). If you try to change this from a shell script you will hit the Linux command which will have a lot more overhead. I had a customer attempt this using the shell and it ended up taking forever due to a brain damaged NIS service :-). Jim On Monday, June 8, 2020, 2:01:39 PM EDT, Lohit Valleru <valleru@cbio.mskcc.org> wrote: #yiv6988452566 body{font-family:Helvetica, Arial;font-size:13px;}Hello Everyone, We are planning to migrate from LDAP to AD, and one of the best solution was to change the uidNumber and gidNumber to what SSSD or Centrify would resolve. May I know, if anyone has come across a tool/tools that can change the uidNumbers and gidNumbers of billions of files efficiently and in a reliable manner?We could spend some time to write a custom script, but wanted to know if a tool already exists. Please do let me know, if any one else has come across a similar situation, and the steps/tools used to resolve the same. Regards,Lohit_______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss
Hi Lohit (hey Jim & Christof), Whilst you _could_ trawl your entire filesystem, flip uids and work out how to successfully replace ACL ids without actually pushing ACLs (which could break defined inheritance options somewhere in your file tree if you had not first audited your filesystem) the systems head in me says: "We are planning to migrate from LDAP to AD, and one of the best solution was to change the uidNumber and gidNumber to what SSSD or Centrify would resolve." Here's the problem: to what SSSD or Centrify would resolve I've done this a few times in the past in a previous life. In many respects it is easier (and faster!) to remap the AD side to the uids already on the filesystem. E.G. if user foo is id 1234, ensure user foo is 1234 in AD when you move your LDAP world over. Windows ldifde utility can import an ldif from openldap to take the config across. Automation or inline munging can be achieved with powershell or python. I presume there is a large technical blocker which is why you are looking at remapping the filesystem? Best, Jez On 09/06/2020 03:52, Christof Schmitt wrote:
If there are ACLs, then you also need to update all ACLs (gpfs_getacl(), update uids and gids in all entries, gpfs_putacl()), in addition to the chown() call. Regards, Christof Schmitt || IBM || Spectrum Scale Development || Tucson, AZ christof.schmitt@us.ibm.com || +1-520-799-2469 (T/L: 321-2469)
----- Original message ----- From: Jim Doherty <jjdoherty@yahoo.com> Sent by: gpfsug-discuss-bounces@spectrumscale.org To: gpfsug main discussion list <gpfsug-discuss@spectrumscale.org> Cc: Subject: [EXTERNAL] Re: [gpfsug-discuss] Change uidNumber and gidNumber for billions of files Date: Mon, Jun 8, 2020 5:57 PM You will need to do this with chown from the c library functions (could do this from perl or python). If you try to change this from a shell script you will hit the Linux command which will have a lot more overhead. I had a customer attempt this using the shell and it ended up taking forever due to a brain damaged NIS service :-). Jim On Monday, June 8, 2020, 2:01:39 PM EDT, Lohit Valleru <valleru@cbio.mskcc.org> wrote: Hello Everyone, We are planning to migrate from LDAP to AD, and one of the best solution was to change the uidNumber and gidNumber to what SSSD or Centrify would resolve. May I know, if anyone has come across a tool/tools that can change the uidNumbers and gidNumbers of billions of files efficiently and in a reliable manner? We could spend some time to write a custom script, but wanted to know if a tool already exists. Please do let me know, if any one else has come across a similar situation, and the steps/tools used to resolve the same. Regards, Lohit _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss
_______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss
-- *Jez Tucker* VP Research and Development | Pixit Media e: jtucker@pixitmedia.com <mailto:jtucker@pixitmedia.com> Visit www.pixitmedia.com <https://www.pixitmedia.com> -- <https://twitter.com/PixitMedia> <https://www.linkedin.com/company/pixitmedia> <https://www.pixitmedia.com/> This email is confidential in that it is intended for the exclusive attention of the addressee(s) indicated. If you are not the intended recipient, this email should not be read or disclosed to any other person. Please notify the sender immediately and delete this email from your computer system. Any opinions expressed are not necessarily those of the company from which this email was sent and, whilst to the best of our knowledge no viruses or defects exist, no responsibility can be accepted for any loss or damage arising from its receipt or subsequent use of this email.
I presume there is a large technical blocker which is why you are looking at remapping the filesystem?
Like anytime there is a corporate AD with mandated attributes? 😊 Though isn’t there an AD thing now for doing schema view type things now which allow you to inherit certain attributes and overwrite others? Simon
On 08/06/2020 18:44, Lohit Valleru wrote:
Hello Everyone,
We are planning to migrate from LDAP to AD, and one of the best solution was to change the uidNumber and gidNumber to what SSSD or Centrify would resolve.
May I know, if anyone has come across a tool/tools that can change the uidNumbers and gidNumbers of billions of files efficiently and in a reliable manner?
Not to my knowledge.
We could spend some time to write a custom script, but wanted to know if a tool already exists.
If you can be sure that all files under a specific directory belong to a specific user and you have no ACL's then a whole bunch of "chown -R" would be reasonable. That is you have a lot of user home directories for example. What I do in these scenarios is use a small sqlite database, say in this scenario which has the directory that I want to chown on, the target UID and GID and a status field. Initially I set the status field to -1 which indicates they have not been processed. The script sets the status field to -2 when it starts processing an entry and on completion sets the status field to the exit code of the command you are running. This way when the script is finished you can see any directory hierarchies that had a problem and if it dies early you can see where it got up to (that -2). You can also do things like set all none zero status codes back to -1 and run again with a simple SQL update on the database from the sqlite CLI. If you don't need to modify ACL's but have mixed ownership under directory hierarchies then a script is reasonable but not a shell script. The overhead of execing chown billions of times on individual files will be astronomical. You need something like Perl or Python and make use of the builtin chown facilities of the language to avoid all those exec's. That said I suspect you will see a significant speed up from using C. If you have ACL's to contend with then I would definitely spend some time and write some C code using the GPFS library. It will be a *LOT* faster than any script ever will be. Dealing with mmpgetacl and mmputacl in any script is horrendous and you will have billions of exec's of each command. As I understand it GPFS stores each ACL once and each file then points to the ACL. Theoretically it would be possible to just modify the stored ACL's for a very speedy update of all the ACL's on the files/directories. However I would imagine you need to engage IBM and bend over while they empty your wallet for that option :-) The biggest issue to take care of IMHO is do any of the input UID/GID numbers exist in the output set??? If so life just got a lot harder as you don't get a second chance to run the script/program if there is a problem. In this case I would be very tempted to remove such clashes prior to the main change. You might be able to do that incrementally before the main switch and update your LDAP in to match. Finally be aware that if you are using TSM for backup you will probably need to back every file up again after the change of ownership as far as I am aware. JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG
Jonathan brings up a good point that you’ll only get one shot at this — if you’re using the file system as your record of who owns what. You might want to use the policy engine to record the existing file names and ownership (and then provide updates using the same policy engine for the things that changed after the last time you ran it). At that point, you’ve got the list of who should own what from before you started. You could even do some things to see how complex your problem is, like "how many directories have files owned by more than one UID?” With respect to that, it is surprising how easy the sqlite C API is to use (though I would still recommend Perl or Python), and equally surprising how *bad* the JOIN performance is. If you go with sqlite, denormalize *everything* as it’s collected. If that is too dirty for you, then just use MariaDB or something else. -- Stephen
On Jun 9, 2020, at 7:20 AM, Jonathan Buzzard <jonathan.buzzard@strath.ac.uk> wrote:
On 08/06/2020 18:44, Lohit Valleru wrote:
Hello Everyone, We are planning to migrate from LDAP to AD, and one of the best solution was to change the uidNumber and gidNumber to what SSSD or Centrify would resolve. May I know, if anyone has come across a tool/tools that can change the uidNumbers and gidNumbers of billions of files efficiently and in a reliable manner?
Not to my knowledge.
We could spend some time to write a custom script, but wanted to know if a tool already exists.
If you can be sure that all files under a specific directory belong to a specific user and you have no ACL's then a whole bunch of "chown -R" would be reasonable. That is you have a lot of user home directories for example.
What I do in these scenarios is use a small sqlite database, say in this scenario which has the directory that I want to chown on, the target UID and GID and a status field. Initially I set the status field to -1 which indicates they have not been processed. The script sets the status field to -2 when it starts processing an entry and on completion sets the status field to the exit code of the command you are running. This way when the script is finished you can see any directory hierarchies that had a problem and if it dies early you can see where it got up to (that -2).
You can also do things like set all none zero status codes back to -1 and run again with a simple SQL update on the database from the sqlite CLI.
If you don't need to modify ACL's but have mixed ownership under directory hierarchies then a script is reasonable but not a shell script. The overhead of execing chown billions of times on individual files will be astronomical. You need something like Perl or Python and make use of the builtin chown facilities of the language to avoid all those exec's. That said I suspect you will see a significant speed up from using C.
If you have ACL's to contend with then I would definitely spend some time and write some C code using the GPFS library. It will be a *LOT* faster than any script ever will be. Dealing with mmpgetacl and mmputacl in any script is horrendous and you will have billions of exec's of each command.
As I understand it GPFS stores each ACL once and each file then points to the ACL. Theoretically it would be possible to just modify the stored ACL's for a very speedy update of all the ACL's on the files/directories. However I would imagine you need to engage IBM and bend over while they empty your wallet for that option :-)
The biggest issue to take care of IMHO is do any of the input UID/GID numbers exist in the output set??? If so life just got a lot harder as you don't get a second chance to run the script/program if there is a problem.
In this case I would be very tempted to remove such clashes prior to the main change. You might be able to do that incrementally before the main switch and update your LDAP in to match.
Finally be aware that if you are using TSM for backup you will probably need to back every file up again after the change of ownership as far as I am aware.
JAB.
-- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss
On 09/06/2020 14:07, Stephen Ulmer wrote:
Jonathan brings up a good point that you’ll only get one shot at this — if you’re using the file system as your record of who owns what.
Not strictly true if my existing UID's are in the range 10000-19999 and my target UID's are in the range 50000-99999 for example then I get an infinite number of shots at it. It is only if the target and source ranges have any overlap that there is a problem and that should be easy to work out in advance. If it where me and there was overlap between input and output states I would go via an intermediate state where there is no overlap. Linux has had 32bit UID's since a very long time now (we are talking kernel versions <1.0 from memory) so none overlapping mappings are perfectly possible to arrange.
With respect to that, it is surprising how easy the sqlite C API is to use (though I would still recommend Perl or Python), and equally surprising how *bad* the JOIN performance is. If you go with sqlite, denormalize *everything* as it’s collected. If that is too dirty for you, then just use MariaDB or something else.
I actually thinking on it more thought a generic C random UID/GID to UID/GID mapping program is a really simple piece of code and should be nearly as fast as chown -R. It will be very slightly slower as you have to look the mapping up for each file. Read the mappings in from a CSV file into memory and just use nftw/lchown calls to walk the file system and change the UID/GID as necessary. If you are willing to sacrifice some error checking on the input mapping file (not unreasonable to assume it is good) and have some hard coded site settings (avoiding processing command line arguments) then 200 lines of C tops should do it. Depending on how big your input UID/GID ranges are you could even use array indexing for the mapping. For example on our system the UID's start at just over 5000 and end just below 6000 with quite a lot of holes. Just allocate an array of 6000 int's which is only ~24KB and off you go with something like new_uid = uid_mapping[uid]; Nice super speedy lookup of mappings. If you need to manipulate ACL's then C is the only way to go anyway. JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG
On 09/06/2020 14:57, Jonathan Buzzard wrote: [SNIP]
I actually thinking on it more thought a generic C random UID/GID to UID/GID mapping program is a really simple piece of code and should be nearly as fast as chown -R. It will be very slightly slower as you have to look the mapping up for each file. Read the mappings in from a CSV file into memory and just use nftw/lchown calls to walk the file system and change the UID/GID as necessary.
Because I was curious I thought I would have a go this evening coding something up in C. It's standing at 213 lines of code put there is some extra fluff and some error checking and a large copyright comment. Updating ACL's would increase the size too. It would however be relatively simple I think. The public GPFS API documentation on ACL's is incomplete so some guess work and testing would be required. It's stupidly fast on my laptop changing the ownership of the latest version of gcc untarred. However there is only one user in the map file and it's an SSD. Obviously if you have billions of files it is going to take longer :-) JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG
Lohit, I did this while working @ NASA. I had two tools I used, one affectionately known as "luke file walker" (to modify traditional unix permissions) and the other known as the "milleniumfacl" (to modify posix ACLs). Stupid jokes aside, there were some real technical challenges here. I don't know if anyone from the NCCS team at NASA is on the list, but if they are perhaps they'll jump in if they're willing to share the code :)
From what I recall, I used uthash and the gpfs API's to store in-memory a hash of inodes and their uid/gid information. I then walked the filesystem using the gpfs API's and could lookup the given inode in the in-memory hash to view its ownership details. Both the inode traversal and directory walk were parallelized/threaded. They way I actually executed the chown was particularly security-minded. There is a race condition that exists if you chown /path/to/file. All it takes is either a malicious user or someone monkeying around with the filesystem while it's live to accidentally chown the wrong file if a symbolic link ends up in the file path. My work around was to use openat() and fchmod (I think that was it, I played with this quite a bit to get it right) and for every path to be chown'd I would walk the hierarchy, opening each component with the O_NOFOLLOW flags to be sure I didn't accidentally stumble across a symlink in the way. I also implemented caching of open path component file descriptors since odds are I would be chowning/chgrp'ing files in the same directory. That bought me some speed up.
I opened up RFE's at one point, I believe, for gpfs API calls to do this type of operation. I would ideally have liked a mechanism to do this based on inode number rather than path which would help avoid issues of race conditions. One of the gotchas to be aware of, is quotas. My wrapper script would clone quotas from the old uid to the new uid. That's easy enough. However, keep in mind, if the uid is over their quota your chown operation will absolutely kill your cluster. Once a user is over their quota the filesystem seems to want to quiesce all of its accounting information on every filesystem operation for that user. I would check for adequate quota headroom for the user in question and abort if there wasn't enough. The ACL changes were much more tricky. There's no way, of which I'm aware, to atomically update ACL entries. You run the risk that you could clobber a user's ACL update if it occurs in the milliseconds between you reading the ACL and updating it as part of the UID/GID update. Thankfully we were using Posix ACLs which were easier for me to deal with programmatically. I still had the security concern over symbolic links appearing in paths to have their ACLs updated either maliciously or organically. I was able to deal with that by modifying libacl to implement ACL calls that used variants of xattr calls that took file descriptors as arguments and allowed me to throw nofollow flags. That code is here ( https://github.com/aaronknister/acl/commits/nofollow). I couldn't take advantage of the GPFS API's here to meet my requirements, so I just walked the filesystem tree in parallel if I recall correctly, retrieved every ACL and updated if necessary. If you're using NFS4 ACLs... I don't have an easy answer for you :) We did manage to migrate UID numbers for several hundred users and half a billion inodes in a relatively small amount of time with the filesystem active. Some of the concerns about symbolic links can be mitigated if there are no users active on the filesystem while the migration is underway. -Aaron On Mon, Jun 8, 2020 at 2:01 PM Lohit Valleru <valleru@cbio.mskcc.org> wrote:
Hello Everyone,
We are planning to migrate from LDAP to AD, and one of the best solution was to change the uidNumber and gidNumber to what SSSD or Centrify would resolve.
May I know, if anyone has come across a tool/tools that can change the uidNumbers and gidNumbers of billions of files efficiently and in a reliable manner? We could spend some time to write a custom script, but wanted to know if a tool already exists.
Please do let me know, if any one else has come across a similar situation, and the steps/tools used to resolve the same.
Regards, Lohit _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss
Quota … I thought there was a work around for this. I think it went along the lines of. Set the soft quota to what you want. Set the hard quota 150% more. Set the grace period to 1 second. I think the issue is that when you are over soft quota, each operation has to queisce each time until you hit hard/grace period. Whereas once you hit grace, it no longer does this. I was just looking for the slide deck about this, but can’t find it at the moment! Tomer spoke about it at one point. Simon From: <gpfsug-discuss-bounces@spectrumscale.org> on behalf of "aaron.knister@gmail.com" <aaron.knister@gmail.com> Reply to: "gpfsug-discuss@spectrumscale.org" <gpfsug-discuss@spectrumscale.org> Date: Wednesday, 10 June 2020 at 02:16 To: "gpfsug-discuss@spectrumscale.org" <gpfsug-discuss@spectrumscale.org> Subject: Re: [gpfsug-discuss] Change uidNumber and gidNumber for billions of files Lohit, I did this while working @ NASA. I had two tools I used, one affectionately known as "luke file walker" (to modify traditional unix permissions) and the other known as the "milleniumfacl" (to modify posix ACLs). Stupid jokes aside, there were some real technical challenges here. I don't know if anyone from the NCCS team at NASA is on the list, but if they are perhaps they'll jump in if they're willing to share the code :) From what I recall, I used uthash and the gpfs API's to store in-memory a hash of inodes and their uid/gid information. I then walked the filesystem using the gpfs API's and could lookup the given inode in the in-memory hash to view its ownership details. Both the inode traversal and directory walk were parallelized/threaded. They way I actually executed the chown was particularly security-minded. There is a race condition that exists if you chown /path/to/file. All it takes is either a malicious user or someone monkeying around with the filesystem while it's live to accidentally chown the wrong file if a symbolic link ends up in the file path. My work around was to use openat() and fchmod (I think that was it, I played with this quite a bit to get it right) and for every path to be chown'd I would walk the hierarchy, opening each component with the O_NOFOLLOW flags to be sure I didn't accidentally stumble across a symlink in the way. I also implemented caching of open path component file descriptors since odds are I would be chowning/chgrp'ing files in the same directory. That bought me some speed up. I opened up RFE's at one point, I believe, for gpfs API calls to do this type of operation. I would ideally have liked a mechanism to do this based on inode number rather than path which would help avoid issues of race conditions. One of the gotchas to be aware of, is quotas. My wrapper script would clone quotas from the old uid to the new uid. That's easy enough. However, keep in mind, if the uid is over their quota your chown operation will absolutely kill your cluster. Once a user is over their quota the filesystem seems to want to quiesce all of its accounting information on every filesystem operation for that user. I would check for adequate quota headroom for the user in question and abort if there wasn't enough. The ACL changes were much more tricky. There's no way, of which I'm aware, to atomically update ACL entries. You run the risk that you could clobber a user's ACL update if it occurs in the milliseconds between you reading the ACL and updating it as part of the UID/GID update. Thankfully we were using Posix ACLs which were easier for me to deal with programmatically. I still had the security concern over symbolic links appearing in paths to have their ACLs updated either maliciously or organically. I was able to deal with that by modifying libacl to implement ACL calls that used variants of xattr calls that took file descriptors as arguments and allowed me to throw nofollow flags. That code is here ( https://github.com/aaronknister/acl/commits/nofollow). I couldn't take advantage of the GPFS API's here to meet my requirements, so I just walked the filesystem tree in parallel if I recall correctly, retrieved every ACL and updated if necessary. If you're using NFS4 ACLs... I don't have an easy answer for you :) We did manage to migrate UID numbers for several hundred users and half a billion inodes in a relatively small amount of time with the filesystem active. Some of the concerns about symbolic links can be mitigated if there are no users active on the filesystem while the migration is underway. -Aaron On Mon, Jun 8, 2020 at 2:01 PM Lohit Valleru <valleru@cbio.mskcc.org<mailto:valleru@cbio.mskcc.org>> wrote: Hello Everyone, We are planning to migrate from LDAP to AD, and one of the best solution was to change the uidNumber and gidNumber to what SSSD or Centrify would resolve. May I know, if anyone has come across a tool/tools that can change the uidNumbers and gidNumbers of billions of files efficiently and in a reliable manner? We could spend some time to write a custom script, but wanted to know if a tool already exists. Please do let me know, if any one else has come across a similar situation, and the steps/tools used to resolve the same. Regards, Lohit _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org<http://spectrumscale.org> http://gpfsug.org/mailman/listinfo/gpfsug-discuss
On 10/06/2020 02:15, Aaron Knister wrote:
Lohit,
I did this while working @ NASA. I had two tools I used, one affectionately known as "luke file walker" (to modify traditional unix permissions) and the other known as the "milleniumfacl" (to modify posix ACLs). Stupid jokes aside, there were some real technical challenges here.
I don't know if anyone from the NCCS team at NASA is on the list, but if they are perhaps they'll jump in if they're willing to share the code :)
From what I recall, I used uthash and the gpfs API's to store in-memory a hash of inodes and their uid/gid information. I then walked the filesystem using the gpfs API's and could lookup the given inode in the in-memory hash to view its ownership details. Both the inode traversal and directory walk were parallelized/threaded. They way I actually executed the chown was particularly security-minded. There is a race condition that exists if you chown /path/to/file. All it takes is either a malicious user or someone monkeying around with the filesystem while it's live to accidentally chown the wrong file if a symbolic link ends up in the file path.
Well I would expect this needs to be done with no user access to the system. Or at the very least no user access for the bits you are currently modifying. Otherwise you are going to end up in a complete mess.
My work around was to use openat() and fchmod (I think that was it, I played with this quite a bit to get it right) and for every path to be chown'd I would walk the hierarchy, opening each component with the O_NOFOLLOW flags to be sure I didn't accidentally stumble across a symlink in the way.
Or you could just use lchown so you change the ownership of the symbolic link rather than the file it is pointing to. You need to change the ownership of the symbolic link not the file it is linking to, that will be picked up elsewhere in the scan. If you don't change the ownership of the symbolic link you are going to be left with a bunch of links owned by none existent users. No race condition exists if you are doing it properly in the first place :-) I concluded that the standard nftw system call was more suited to this than the GPFS inode scan. I could see no way to turn an inode into a path to the file which lchownn, gpfs_getacl and gpfs_putacl all use. I think the problem with the GPFS inode scan is that is is for a backup application. Consequently there are some features it is lacking for more general purpose programs looking for a quick way to traverse the file system. An other example is that the gpfs_iattr_t structure returned from gpfs_stat_inode does not contain any information as to whether the file is a symbolic link like a standard stat call does.
I also implemented caching of open path component file descriptors since odds are I would be chowning/chgrp'ing files in the same directory. That bought me some speed up.
More reasons to use nftw for now, no need to open any files :-)
I opened up RFE's at one point, I believe, for gpfs API calls to do this type of operation. I would ideally have liked a mechanism to do this based on inode number rather than path which would help avoid issues of race conditions.
Well lchown to the rescue, but that does require a path to the file. The biggest problem is the inability to get a path given an inode using the GPFS inode scan which is why I steered away from it. In theory you could use gpfs_igetattrsx/gpfs_iputattrsx to modify the UID/GID of the file, but they are returned in an opaque format, so it's not possible :-(
One of the gotchas to be aware of, is quotas. My wrapper script would clone quotas from the old uid to the new uid. That's easy enough. However, keep in mind, if the uid is over their quota your chown operation will absolutely kill your cluster. Once a user is over their quota the filesystem seems to want to quiesce all of its accounting information on every filesystem operation for that user. I would check for adequate quota headroom for the user in question and abort if there wasn't enough.
Had not thought of that one. Surely the simple solution would be to set the quota's on the mapped UID/GID's after the change has been made. Then the filesystem operation would not be for the user over quota but for the new user? The other alternative is to dump the quotas to file and remove them. Change the UID's and GID's then restore the quotas on the new UID/GID's. As I said earlier surely the end users have no access to the file system while the modifications are being made. If they do all hell is going to break loose IMHO.
The ACL changes were much more tricky. There's no way, of which I'm aware, to atomically update ACL entries. You run the risk that you could clobber a user's ACL update if it occurs in the milliseconds between you reading the ACL and updating it as part of the UID/GID update. Thankfully we were using Posix ACLs which were easier for me to deal with programmatically. I still had the security concern over symbolic links appearing in paths to have their ACLs updated either maliciously or organically. I was able to deal with that by modifying libacl to implement ACL calls that used variants of xattr calls that took file descriptors as arguments and allowed me to throw nofollow flags. That code is here ( https://github.com/aaronknister/acl/commits/nofollow <https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com...>). I couldn't take advantage of the GPFS API's here to meet my requirements, so I just walked the filesystem tree in parallel if I recall correctly, retrieved every ACL and updated if necessary.
If you're using NFS4 ACLs... I don't have an easy answer for you :)
You call gpfs_getacl, walk the array of ACL's returned changing any UID/GID's as required and then call gpfs_putacl. You can modify both Posix and NFSv4 ACL's with this call. Given they only take a path to the file another reason to use nftw rather than GPFS inode scan. As I understand even if your file system is set to an ACL type of "all", any individual file/directory can only have either Posix *or* NSFv4 ACLS (ignoring the fact you can set your filesystem ACL's type to the undocumented Samba), so can all be handled automatically. Note if you are using nftw to walk the file system then you get a standard system stat structure for every file/directory and you could just skip symbolic links. I don't think you can set an ACL on a symbolic link anyway. You certainly can't set standard permissions on them. It would be sensible to wrap the main loop in gpfs_lib_init/gpfs_lib_term in this scenario. JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG
Thank you everyone for the Inputs. The answers to some of the questions are as follows: > From Jez: I've done this a few times in the past in a previous life. In many respects it is easier (and faster!) to remap the AD side to the uids already on the filesystem. - Yes we had considered/attempted this, and it does work pretty good. It is actually much faster than using SSSD auto id mapping. But the main issue with this approach was to automate entry of uidNumbers and gidNumbers for all the enterprise users/groups across the agency. Both the approaches have there pros and cons. For now, we wanted to see the amount of effort that would be needed to change the uidNumbers and gidNumbers on the filesystem side, in case the other option of entering existing uidNumber/gidNumber data on AD does not work out. > Does the filesystem have ACLs? And which ACLs? Since we have CES servers that export the filesystems on SMB protocol -> The filesystems use NFS4 ACL mode. As far as we know - We know of only one fileset that is extensively using NFS4 ACLs. > Can we take a downtime to do this change? For the current GPFS storage clusters which are are production - we are thinking of taking a downtime to do the same per cluster. For new clusters/storage clusters, we are thinking of changing to AD before any new data is written to the storage. > Do the uidNumbers/gidNumbers conflict? No. The current uidNumber and gidNumber are in 1000 - 8000 range, while the new uidNumbers,gidNumbers are above 1000000. I was thinking of taking a backup of the current state of the filesystem, with respect to posix permissions/owner/group and the respective quotas. Disable quotas with a downtime before making changes. I might mostly start small with a single lab, and only change files without ACLs. May I know if anyone has a method/tool to find out which files/dirs have NFS4 ACLs set? As far as we know - it is just one fileset/lab, but it would be good to confirm if we have them set across any other files/dirs in the filesystem. The usual methods do not seem to work. Jonathan/Aaron, Thank you for the inputs regarding the scripts/APIs/symlinks and ACLs. I will try to see what I can do given the current state. I too wish GPFS API could be better at managing this kind of scenarios but I understand that this kind of huge changes might be pretty rare. Thank you, Lohit On June 10, 2020 at 6:33:45 AM, Jonathan Buzzard (jonathan.buzzard@strath.ac.uk) wrote: On 10/06/2020 02:15, Aaron Knister wrote: > Lohit, > > I did this while working @ NASA. I had two tools I used, one > affectionately known as "luke file walker" (to modify traditional unix > permissions) and the other known as the "milleniumfacl" (to modify posix > ACLs). Stupid jokes aside, there were some real technical challenges here. > > I don't know if anyone from the NCCS team at NASA is on the list, but if > they are perhaps they'll jump in if they're willing to share the code :) > > From what I recall, I used uthash and the gpfs API's to store in-memory > a hash of inodes and their uid/gid information. I then walked the > filesystem using the gpfs API's and could lookup the given inode in the > in-memory hash to view its ownership details. Both the inode traversal > and directory walk were parallelized/threaded. They way I actually > executed the chown was particularly security-minded. There is a race > condition that exists if you chown /path/to/file. All it takes is either > a malicious user or someone monkeying around with the filesystem while > it's live to accidentally chown the wrong file if a symbolic link ends > up in the file path. Well I would expect this needs to be done with no user access to the system. Or at the very least no user access for the bits you are currently modifying. Otherwise you are going to end up in a complete mess. > My work around was to use openat() and fchmod (I > think that was it, I played with this quite a bit to get it right) and > for every path to be chown'd I would walk the hierarchy, opening each > component with the O_NOFOLLOW flags to be sure I didn't accidentally > stumble across a symlink in the way. Or you could just use lchown so you change the ownership of the symbolic link rather than the file it is pointing to. You need to change the ownership of the symbolic link not the file it is linking to, that will be picked up elsewhere in the scan. If you don't change the ownership of the symbolic link you are going to be left with a bunch of links owned by none existent users. No race condition exists if you are doing it properly in the first place :-) I concluded that the standard nftw system call was more suited to this than the GPFS inode scan. I could see no way to turn an inode into a path to the file which lchownn, gpfs_getacl and gpfs_putacl all use. I think the problem with the GPFS inode scan is that is is for a backup application. Consequently there are some features it is lacking for more general purpose programs looking for a quick way to traverse the file system. An other example is that the gpfs_iattr_t structure returned from gpfs_stat_inode does not contain any information as to whether the file is a symbolic link like a standard stat call does. > I also implemented caching of open > path component file descriptors since odds are I would be > chowning/chgrp'ing files in the same directory. That bought me some > speed up. > More reasons to use nftw for now, no need to open any files :-) > I opened up RFE's at one point, I believe, for gpfs API calls to do this > type of operation. I would ideally have liked a mechanism to do this > based on inode number rather than path which would help avoid issues of > race conditions. > Well lchown to the rescue, but that does require a path to the file. The biggest problem is the inability to get a path given an inode using the GPFS inode scan which is why I steered away from it. In theory you could use gpfs_igetattrsx/gpfs_iputattrsx to modify the UID/GID of the file, but they are returned in an opaque format, so it's not possible :-( > One of the gotchas to be aware of, is quotas. My wrapper script would > clone quotas from the old uid to the new uid. That's easy enough. > However, keep in mind, if the uid is over their quota your chown > operation will absolutely kill your cluster. Once a user is over their > quota the filesystem seems to want to quiesce all of its accounting > information on every filesystem operation for that user. I would check > for adequate quota headroom for the user in question and abort if there > wasn't enough. Had not thought of that one. Surely the simple solution would be to set the quota's on the mapped UID/GID's after the change has been made. Then the filesystem operation would not be for the user over quota but for the new user? The other alternative is to dump the quotas to file and remove them. Change the UID's and GID's then restore the quotas on the new UID/GID's. As I said earlier surely the end users have no access to the file system while the modifications are being made. If they do all hell is going to break loose IMHO. > > The ACL changes were much more tricky. There's no way, of which I'm > aware, to atomically update ACL entries. You run the risk that you could > clobber a user's ACL update if it occurs in the milliseconds between you > reading the ACL and updating it as part of the UID/GID update. > Thankfully we were using Posix ACLs which were easier for me to deal > with programmatically. I still had the security concern over symbolic > links appearing in paths to have their ACLs updated either maliciously > or organically. I was able to deal with that by modifying libacl to > implement ACL calls that used variants of xattr calls that took file > descriptors as arguments and allowed me to throw nofollow flags. That > code is here ( > https://github.com/aaronknister/acl/commits/nofollow > <https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Faaronknister%2Facl%2Fcommits%2Fnofollow&data=02%7C01%7Cjonathan.buzzard%40strath.ac.uk%7C99476bc8be4a4e2ad20408d80cdbdf21%7C631e0763153347eba5cd0457bee5944e%7C0%7C0%7C637273487058332585&sdata=h4Hgmq3jsnX5VQBDPH%2BhLS2crNg9JYNJ4uae5VM4Meo%3D&reserved=0>). > I couldn't take advantage of the GPFS API's here to meet my > requirements, so I just walked the filesystem tree in parallel if I > recall correctly, retrieved every ACL and updated if necessary. > > If you're using NFS4 ACLs... I don't have an easy answer for you :) You call gpfs_getacl, walk the array of ACL's returned changing any UID/GID's as required and then call gpfs_putacl. You can modify both Posix and NFSv4 ACL's with this call. Given they only take a path to the file another reason to use nftw rather than GPFS inode scan. As I understand even if your file system is set to an ACL type of "all", any individual file/directory can only have either Posix *or* NSFv4 ACLS (ignoring the fact you can set your filesystem ACL's type to the undocumented Samba), so can all be handled automatically. Note if you are using nftw to walk the file system then you get a standard system stat structure for every file/directory and you could just skip symbolic links. I don't think you can set an ACL on a symbolic link anyway. You certainly can't set standard permissions on them. It would be sensible to wrap the main loop in gpfs_lib_init/gpfs_lib_term in this scenario. JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss
On 10/06/2020 16:31, Lohit Valleru wrote: [SNIP]
I might mostly start small with a single lab, and only change files without ACLs. May I know if anyone has a method/tool to find out which > files/dirs have NFS4 ACLs set? As far as we know - it is just one fileset/lab, but it would be good to confirm if we have them set across any other files/dirs in the filesystem. The usual methods do not seem to work.
Use mmgetacl a file at a time and try and do something with the output? Tools to manipulate ACL's from on GPFS mounted nodes suck donkey balls, and have been that way for over a decade. Last time I raised this with IBM I was told that was by design... If they are CES then look at it client side from a Windows node? The alternative is to write something in C that calls gpfs_getacl. However it was an evening to get a basic UID remap code working in C. It would not take much more effort to make it handle ACL's. As such I would work on the premise that there are ACL's and handle it. JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG
You can do a policy scan though and get a list of files that have ACLs applied to them. Then you would not have to check every file with a shell utility or C, just process that list. Likewise, you can get the uid/gid as well and process that list with the new mapping(split it into multiple lists, processing multiple threads on multiple machines). While it is by no means the prettiest or possibly best way to handle the POSIX ACLs, I had whipped up a python api for it: https://github.com/ckerner/ssacl . It only does POSIX though. We use it in conjunction with acls (https://github.com/ckerner/acls), an ls replacement that shows effective user/group permissions based off of the acl's because most often the user would just look at the POSIX perms and say something is broken, without checking the acl. -- Chad Kerner, Senior Storage Engineer Storage Enabling Technologies National Center for Supercomputing Applications University of Illinois, Urbana-Champaign On 6/10/20, 5:30 PM, "gpfsug-discuss-bounces@spectrumscale.org on behalf of Jonathan Buzzard" <gpfsug-discuss-bounces@spectrumscale.org on behalf of jonathan.buzzard@strath.ac.uk> wrote: On 10/06/2020 16:31, Lohit Valleru wrote: [SNIP] > I might mostly start small with a single lab, and only change files > without ACLs. May I know if anyone has a method/tool to find out which > files/dirs have NFS4 ACLs set? As far as we know - it is just one > fileset/lab, but it would be good to confirm if we have them set > across any other files/dirs in the filesystem. The usual methods do > not seem to work. Use mmgetacl a file at a time and try and do something with the output? Tools to manipulate ACL's from on GPFS mounted nodes suck donkey balls, and have been that way for over a decade. Last time I raised this with IBM I was told that was by design... If they are CES then look at it client side from a Windows node? The alternative is to write something in C that calls gpfs_getacl. However it was an evening to get a basic UID remap code working in C. It would not take much more effort to make it handle ACL's. As such I would work on the premise that there are ACL's and handle it. JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss
I seem to remember Marc Kaplan discussing using the ILM and mmfind for this. There is a presentation from 2018 which skims on an example http://files.gpfsug.org/presentations/2018/USA/SpectrumScalePolicyBP.pdf -- Lauz On 10/06/2020 23:40, Kerner, Chad A wrote:
You can do a policy scan though and get a list of files that have ACLs applied to them. Then you would not have to check every file with a shell utility or C, just process that list. Likewise, you can get the uid/gid as well and process that list with the new mapping(split it into multiple lists, processing multiple threads on multiple machines).
While it is by no means the prettiest or possibly best way to handle the POSIX ACLs, I had whipped up a python api for it: https://github.com/ckerner/ssacl . It only does POSIX though. We use it in conjunction with acls (https://github.com/ckerner/acls), an ls replacement that shows effective user/group permissions based off of the acl's because most often the user would just look at the POSIX perms and say something is broken, without checking the acl.
-- Chad Kerner, Senior Storage Engineer Storage Enabling Technologies National Center for Supercomputing Applications University of Illinois, Urbana-Champaign
On 6/10/20, 5:30 PM, "gpfsug-discuss-bounces@spectrumscale.org on behalf of Jonathan Buzzard" <gpfsug-discuss-bounces@spectrumscale.org on behalf of jonathan.buzzard@strath.ac.uk> wrote:
On 10/06/2020 16:31, Lohit Valleru wrote:
[SNIP]
> I might mostly start small with a single lab, and only change files > without ACLs. May I know if anyone has a method/tool to find out which > files/dirs have NFS4 ACLs set? As far as we know - it is just one > fileset/lab, but it would be good to confirm if we have them set > across any other files/dirs in the filesystem. The usual methods do > not seem to work.
Use mmgetacl a file at a time and try and do something with the output?
Tools to manipulate ACL's from on GPFS mounted nodes suck donkey balls, and have been that way for over a decade. Last time I raised this with IBM I was told that was by design...
If they are CES then look at it client side from a Windows node?
The alternative is to write something in C that calls gpfs_getacl.
However it was an evening to get a basic UID remap code working in C. It would not take much more effort to make it handle ACL's. As such I would work on the premise that there are ACL's and handle it.
JAB.
-- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss
_______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at spectrumscale.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss
Sorry a bit behind the discussion... We were using GPFS's internal TBD2 method for UID and GID assignment (15 years ago GPFS was purchased for a single purpose with a handful of accounts) I have just been through 88 million files ADDING NFSv4 ACEs with UIDs and GIDs derived from AD RIDs. We have both the TBD2 and AD RID ACEs in the ACLs. This allowed us to do a single switch over between the authentication methods for all the data at once. The testing and prep work took months though. We have Spectrum protect and SP Space management with a tape library in the mix, so I needed to make sure ACL changes didn't cause a backup and recall then backup for migrated files. My scripts made use of mmgetacl and mmputacl. I had less than 50 unique ACEs to construct and I created a spreadsheet that auto created the commands. This could have been automated, but for that number it was just as quick for me to do by hand than learn to program it. I wrote my own scripts, with a lot of safety checks, as it went AWOL at one point and started changing permissions at the root for the GPFS file system, removing access for everyone. We had a mix of posix only and nfsv4 ACLs. Testing them revealed a lot of skeletons in the way some systems had been set up - allow a lot of time for unknowns if you have systems using GPFS as a back end. Some way into it to this, I discovered IBM have created code to do this - I didn't keep the link as it was too late for me. The switch over went seamlessly btw, it had to with all the prep work! Kindest regards, Paul Paul Ward TS Infrastructure Architect Natural History Museum T: 02079426450 E: p.ward@nhm.ac.uk<mailto:p.ward@nhm.ac.uk> [A picture containing drawing Description automatically generated] From: gpfsug-discuss-bounces@spectrumscale.org <gpfsug-discuss-bounces@spectrumscale.org> On Behalf Of Lohit Valleru Sent: 08 June 2020 18:44 To: gpfsug main discussion list <gpfsug-discuss@spectrumscale.org> Subject: [gpfsug-discuss] Change uidNumber and gidNumber for billions of files Hello Everyone, We are planning to migrate from LDAP to AD, and one of the best solution was to change the uidNumber and gidNumber to what SSSD or Centrify would resolve. May I know, if anyone has come across a tool/tools that can change the uidNumbers and gidNumbers of billions of files efficiently and in a reliable manner? We could spend some time to write a custom script, but wanted to know if a tool already exists. Please do let me know, if any one else has come across a similar situation, and the steps/tools used to resolve the same. Regards, Lohit
participants (11)
-
Aaron Knister -
Christof Schmitt -
Jez Tucker -
Jim Doherty -
Jonathan Buzzard -
Kerner, Chad A -
Laurence Horrocks-Barlow -
Lohit Valleru -
Paul Ward -
Simon Thompson -
Stephen Ulmer
