Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Ensure unprivileged users have unique tmp and home dirs #1278

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cbaenziger
Copy link
Member

@cbaenziger cbaenziger commented Sep 26, 2018

This PR introduces pam_namespaces to ensure that each user gets its own kernel usernamespace for its potential state directories that are managed outside YARN. One further addition is automatic creation and clean-up of directories as needed using pam_exec.

Providing per-user namespaces means we can prevent accidental data sharing and we will prevent many imporoper uses of temporary directories by pro-actively cleaning them up. We have seen many users impact themselves with both anti-patterns and similarly when a user disconnects we will ensure they stop taking up space on our root partition for what should be their ephemeral home directory. We will need to notify users of this change!

The directories affected are listed in `/etc/secuirty/namespaces.conf. Users listed in that file are excluded from that line.

The directories created in inst_dir.sh.erb are the necessary directories for pam_namespace to create directories and when the user is no longer running any processes and the user terminations its session the script is called to remove the directories. (If one uses nohup or such you can hold your directory around I think but I am not too concerned about that right now; we can write clean-up logic if need be later; similarly no quotas are introduced here but use of ZFS or possibly LVM could allow us to easily do that.)

The structure under the polyinstantion directory looks like follows; and inside each directory is what the user see:

ubuntu@iptables-bcpc-vm2:~$ sudo ls -l /inst-dirs
total 4
drwxrwxrwt 14 root root 4096 Sep 26 00:50 tmp_myuser
drwxrwxrwt  3 root root 4096 Sep 26 00:50 var_tmp_myuser
ubuntu@iptables-bcpc-vm2:~$ sudo ls -l /dev/shm/inst-dirs
total 0
drwxrwxrwt 2 root root 40 Sep 26 00:50 inst_myuser

@cbaenziger
Copy link
Member Author

cbaenziger commented Oct 5, 2018

Oh, also to explain; we override /etc/security/namespace.init to correct Ubuntu Bug 1081323.

@cbaenziger cbaenziger force-pushed the tmp_dirs branch 2 times, most recently from 8045dc3 to 7db2d5b Compare October 15, 2018 16:00
# see if user still has any prescence on this machine
pgrep -u "$PAM_USER" && exit 0
# if no prescense of user, remove all trace of their activity
rm -rf "<%= @polyinstantion_dir %>/home_$PAM_USER" \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chris asks please ensure that hardlink traversal isn't a risk here.

source 'pam_namespace.conf.erb'
mode 500
variables(lazy {{ real_home_dir_users:
node['bcpc']['pam_namespace']['real_home_dir_users'].join(','),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ron asks, please .uniq on node['bcpc']['pam_namespace']['real_home_dir_users'].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly also sort.

source 'pam_namespace.conf.erb'
mode 500
variables(lazy {{ real_home_dir_users:
node['bcpc']['pam_namespace']['real_home_dir_users'].join(','),
Copy link
Member

@vt0r vt0r Nov 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this would work, since I haven't tested it: Working. See below comment.

Suggested change
node['bcpc']['pam_namespace']['real_home_dir_users'].join(','),
node['bcpc']['pam_namespace']['real_home_dir_users'].uniq.sort.join(','),

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok

[1] pry(main)> blah = %w(hdfs hdfs yarn hbase mapred hdfs hbase yarn mapred mapred hdfs hbase hadoop)
=> ["hdfs", "hdfs", "yarn", "hbase", "mapred", "hdfs", "hbase", "yarn", "mapred", "mapred", "hdfs", "hbase", "hadoop"]
[2] pry(main)> blah.uniq.sort.join(',')
=> "hadoop,hbase,hdfs,mapred,yarn"

@cbaenziger
Copy link
Member Author

All requested changes made

Also DRY-up sysctl/pam code repeated in Kafka and Hadoop; should be in BCPC
directory '/inst-dirs' do
user 'root'
group 'root'
mode 0o000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mode 0o000
mode 0o0000


if [ -z "$PAM_TYPE" -o "$PAM_TYPE" == "open_session" ]; then
# need to setup the polyinstantation directory for login
mkdir -pm 000 "/dev/shm/<%= @shm_polyinstantion_dir %>" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this got merged out:

Suggested change
mkdir -pm 000 "/dev/shm/<%= @shm_polyinstantion_dir %>" \
mkdir -pm 0000 "/dev/shm/<%= @shm_polyinstantion_dir %>" \

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants