I'm using ldap for remote user authentication and I basically need to either figure out how to:
a. chroot a user on machine b from machine a via nfs,(which doesn't seem possible without mounting more directories than I'm comfortable with)
or -------
b. After adding a user to the ldap db on machine a, force a script to be executed on machine b during the users login that will auto chroot the user before they are allowed to do anything upon their first login.
I'm thinking my second option is probably the best bet, and was thinking along the lines of using pam_exec.so to call the script. However, I have a few concerns about this approach. First, I'm not sure if the script that will be run will have root permissions which it will need to perform the chroot. Second, I'm not sure if pam_exec happens early enough in the login process to be an effective option. Lastly, I need to make sure that the code works in both pam.d/ssh and pam.d/su to consider it a valid solution.
Are my concerns valid or does it seem like this would be a good solution? Or is there a better approach to this problem.
First of all, arguably,
chroot
might not be considered a security feature. There are opinions in the other direction, as well.Arguably, what you need to implement is a reproducible, auditable method of limiting the ability of the user to perform actions other than the strictly allowed.
If you register your users in LDAP, surely you have already deployed the mechanisms to perform LDAP authentication on any machine connected to this LDAP, be it by means of
sssd
or using any other PAM module, it is not relevant to the rest of the solution, and is assumed to be already in place (in my case, I'm using freeIPA andsssd
).To implement this scenario, what I currently do is the following (be aware that this kind of restrictions requires that several conditions are met, otherwise the restriction can be easily circumvented):
wheel
group, the only one authorized to usesu
(enforced via PAM). Usually, a non-LDAP user (sysadm
) exists to allow trusted administrators performing actions in cases of disaster recovery or LDAP unavailability.The users are given a properly secured
rbash
with a read-only PATH pointing to a private~/bin
, this~/bin/
directory contains links to all allowed commands, for example:the users are given a restricted, read-only environment (think of stuff like
LESSSECURE
,TMOUT
,HISTFILE
variables). This is to avoidshell
escapes from commands likeless
orvim
.staff_u
and given rights to execute commands as other user as required viasudo
. The specificsudorules
allowed need to be carefully reviewed to prevent the user from circumventing these limitations, and can also be deployed in your existing LDAP infrastructure (this is one of freeIPA features).the users'
/home
,/tmp
and possibly/var/tmp
are polyinstantiated via/etc/security/namespace.conf
:Polyinstantiation of directories is not a new feature, it has been available for quite a long time now. As a reference, see this article from 2006. As a matter of fact, a lot of modules already use
pam_namespace
by default, but the default configuration at/etc/security/namespace.conf
does not enable polyinstantiation. Also,/etc/security/namespace.init
should make all skeletal files read-only for the users and owned byroot
.This way you can choose whether the users can execute any command on their own behalf (via a link in the private
~/bin
directory, provisioned via/etc/skel
, as explained above), on behalf of other user (viasudo
) or none at all.