|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Restricting User Access via SLURM" |
| 4 | +tags: hpc software slurm |
| 5 | +--- |
| 6 | +Making it so users can only ssh into the nodes they have reserved is built into SLURM. I had a hard time finding all the steps in one place, here's what I did. |
| 7 | + |
| 8 | +Using centos 7.x you'll need to edit two files (both in the compute node image a.k.a vnfs): |
| 9 | +1. $CHROOT/etc/pam.d/password-auth |
| 10 | +2. $CHROOT/etc/security/access.conf |
| 11 | + |
| 12 | +Where $CHROOT is the location to your image. Edit the files like so: |
| 13 | + |
| 14 | +Edit $CHROOT/etc/pam.d/password-auth: |
| 15 | +``` |
| 16 | +account required pam_unix.so |
| 17 | +account required pam_slurm.so # Add this line, below pam_unix.so, but above everything else |
| 18 | +account sufficient pam_localuser.so |
| 19 | +account sufficient pam_succeed_if.so uid < 500 quiet |
| 20 | +account required pam_permit.so |
| 21 | +``` |
| 22 | + |
| 23 | +Edit $CHROOT/etc/security/access.conf: |
| 24 | +``` |
| 25 | +# All other users should be denied to get access from all sources. |
| 26 | ++ : root : ALL # Uncomment or add this line at the bottom of the file |
| 27 | +- : ALL : ALL # Uncomment or add this line at the bottom of the file |
| 28 | +``` |
| 29 | + |
| 30 | +Now rebuild and apply your image/vnfs to the nodes. (Not covered here.) |
| 31 | + |
| 32 | +Test it out: |
| 33 | +``` |
| 34 | +[sr@sms ~]$ ssh compute-1 |
| 35 | +Access denied: user sr (uid=1) has no active jobs on this node. |
| 36 | +Connection closed by 192.168.x.x |
| 37 | +[sr@sms ~]$ salloc -n 1 |
| 38 | +salloc: Granted job allocation 71 |
| 39 | +[sr@sms ~]$ squeue |
| 40 | + JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) |
| 41 | + 71 shared bash sr R 0:04 1 compute-1 |
| 42 | +[sr@sms ~]$ ssh compute-1 |
| 43 | +[sr@compute-1 ~]$ # Note we can log in now! |
| 44 | +[sr@compute-1 ~]$ exit |
| 45 | +logout |
| 46 | +Connection to knl-36 closed. |
| 47 | +[sr@sms ~]$ scancel 71 |
| 48 | +salloc: Job allocation 71 has been revoked. |
| 49 | +``` |
| 50 | + |
| 51 | +## References: |
| 52 | + |
| 53 | +[How to set resource limits within SLURM](https://slurm.schedmd.com/faq.html#pam) |
| 54 | + |
| 55 | +[Using PAM to secure userspace with SLURM](https://groups.google.com/forum/#!topic/slurm-devel/sVkZ1FFVq5s) |
0 commit comments