(2024-01-13) Lab Notebook: Sharing directories with other HPCC users
Warning
This is as a Lab Notebook which describes how to solve a specific problem at a specific time. Please keep this in mind as you read and use the content. Please pay close attention to the date, version information and other details.
Overview
MSU HPCC's GPFS filesystem supports NFS V4 access control lists (ACLs). By modifying ACLs of your directories and files, you will be able to fine control access by other users. This tutorial provides a step-by-step instruction for setting up file sharing through modifying ACLs. We assume that you've put all your files in a single directory and are ready to share that directory with another HPCC user.
To deal with ACLs, you will use three commands: 1) mmgetacl
for obtaining existing ACLs; 2) mmputacl
for changing ACLs; and 3) mmdelacl
for deleting ACLs. Compared with the basic chmod
utility, being able to modify ACLs gives users more fine-grained control over file access.
Viewing existing ACLs
To view ACL of a directory or a file, we use the command mmgetacl
:
1 2 |
|
The output should be mostly self-explanatory; for a complete description of the format of ACL entries, refer to IBM NFS V4 ACL Syntax or IU's supercomputer user's guide.
Example of sharing a directory
Let's say under myuser
's home directory, there is a subdirectory named acl_demo
. It contains two files and two directories (each dir has one file inside), as shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Our goal is to share the entire acl_demo
directory with our collaborator collab
on the HPCC. Specifically, we will grant read-only access to collab
.
First, we need to get the original ACLs for the acl_demo
directory and one of the files (say, file1
) inside it, using mmgetacl
that we've used earlier. The original ACL of a directory/file when created is determined by umask set by myuser
. We will save their ACLs to two files in ~/tmp
, since we want to differentiate directories from files when manipulating their ACLs. Make sure you have created a subdirectory ~/tmp
in your home directory beforehand.
1 2 3 4 5 |
|
Then, we will change the ACLs (for directories and files) using the mmputacl
command. Its usage is simple:
1 |
|
The above shows that mmputacl
takes an input file (-i
) containing user-defined ACL entries. It's important to note that, in this example, we will need to use mmputacl
to change ACLs for both directories and files. This also means that we need to prepare two different input files for mmputacl
.
To give collab
read and execute (execute permission is needed to navigate to the directory) permission of a directory, we only need to add an entry to that directory's existing ACL. The same applies to changing a file. Below we display two files that each contain the additional entry for granting rx
(read and execute) access to user collab
:
1 2 3 4 5 6 7 8 9 |
|
Above, selected permissions are marked with an X
; permissions that are not selected are marked with a -
. ACLs for directories have two additional flags (FileInherit
and DirInherit
) as compared to those for files. These two files (i.e., dir.acl
and file.acl
) are saved in ~/tmp
as before. In practice, you can copy the above content down to your own files and make changes as needed, such as user name and/or permission choices.
Our next step is to combine the new entry (which corresponds to the modified permission) with existing ACL. To do so, in the code below we append our newly added entry to the current ACL, for both directories and files. In other words, the two previously generated files, acl-dir.txt
and acl-file.txt
have been updated now (take a look at the two files to make sure everything is in order).
1 2 |
|
With all the preparation completed, we are now ready to call mmputacl
. In order to make sure all the files and directories inside will be accessible to collab
, we need to apply ACL changes at all levels, or, recursively. The following commands accomplish this.
1 2 3 4 5 |
|
Here is a breakdown of the above code:
- The first line applies the change to the very top level directory
acl_demo
. This allowscollab
to traverse into this directory. - The second line brings us inside the
acl_demo
directory. - The third line recursively changes ACLs for subdirectories (
dir1
anddir2
), based on permissions defined inacl-dir.txt
. Furthermore, if there are subdirectories withindir1
and/ordir2
, their ACLs will be changed in the same manner. - The fourth line recursively changes ACLs for files (
file1
,file2
,dir1/ffile1
, anddir2/ffile2
), based on permissions defined inacl-file.txt
.
Optional: deleting ACLs
If we want to disable access from the collaborator after file sharing is complete, we can use mmdelacl
to delete extended ACLs we've added to acl_demo
. Then the ACLs will be reset to their original entries. To perform deletion, we can use the following commands:
1 2 3 4 5 |
|
After deletion, we can run mmgetacl
on those files and directories again, to confirm.