This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use pam_namespaces and pam_exec to clean-up home dirs and temp space
Also DRY-up sysctl/pam code repeated in Kafka and Hadoop; should be in BCPC
- Loading branch information
1 parent
2054c2b
commit 26734f6
Showing
34 changed files
with
216 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,4 @@ | |
source "#{t}.erb" | ||
mode 0644 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,6 @@ | |
depends 'ntp' | ||
depends 'ubuntu' | ||
depends 'sudo' | ||
depends 'sysctl' | ||
depends 'pam' | ||
depends 'pdns' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# | ||
# Cookbook Name:: bcpc | ||
# Recipe:: pam | ||
# | ||
# Copyright 2018, Bloomberg Finance L.P. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Chef recipe to implement pam_namespace polyinstantiated directories | ||
# This will provide users the appearance they are the only user with data | ||
# in the affected directories -- also this will clean-up their data when | ||
# leaving the machine | ||
|
||
directory '/inst-dirs' do | ||
user 'root' | ||
group 'root' | ||
mode 0o000 | ||
end | ||
|
||
directory '/usr/local/sbin' do | ||
action :create | ||
end | ||
|
||
polyinstantion_dir = node['bcpc']['pam_namespace']['polyinstantion_dir'] | ||
shm_polyinstantion_dir = node['bcpc']['pam_namespace']['shm_polyinstantion_dir'] | ||
|
||
template '/usr/local/sbin/inst_dir.sh' do | ||
source 'inst_dir.sh.erb' | ||
mode 500 | ||
variables(shm_polyinstantion_dir: shm_polyinstantion_dir, | ||
polyinstantion_dir: polyinstantion_dir) | ||
end | ||
|
||
template '/etc/security/namespace.conf' do | ||
source 'pam_namespace.conf.erb' | ||
mode 500 | ||
variables(lazy {{ real_home_dir_users: | ||
node['bcpc']['pam_namespace']['real_home_dir_users'].join(','), | ||
shm_polyinstantion_dir: shm_polyinstantion_dir, | ||
polyinstantion_dir: polyinstantion_dir | ||
}}) | ||
end | ||
|
||
template '/etc/security/namespace.init' do | ||
source 'pam_namespace.init.erb' | ||
mode 755 | ||
end | ||
|
||
# NOTE: This include_recipe is necessary for resource collection | ||
include_recipe 'sysctl::default' | ||
|
||
# ensure we use /etc/security/limits.d to allow ulimit overriding | ||
if !node.key?('pam_d') || !node['pam_d'].key?('services') || !node['pam_d']['services'].key?('common-session') | ||
node.default['pam_d']['services'] = { | ||
'common-session' => { | ||
'main' => { | ||
'pam_permit_default' => { 'interface' => 'session', 'control_flag' => '[default=1]', 'name' => 'pam_permit.so' }, | ||
'pam_deny' => { 'interface' => 'session', 'control_flag' => 'requisite', 'name' => 'pam_deny.so' }, | ||
'pam_permit_required' => { 'interface' => 'session', 'control_flag' => 'required', 'name' => 'pam_permit.so' }, | ||
'pam_limits' => { 'interface' => 'session', 'control_flag' => 'required', 'name' => 'pam_limits.so' }, | ||
'pam_umask' => { 'interface' => 'session', 'control_flag' => 'optional', 'name' => 'pam_umask.so' }, | ||
'pam_unix' => { 'interface' => 'session', 'control_flag' => 'required', 'name' => 'pam_unix.so' }, | ||
'pam_exec' => { 'interface' => 'session', 'control_flag' => 'optional', 'name' => 'pam_exec.so', 'args' => '/usr/local/sbin/inst_dir.sh' }, | ||
'pam_namespace' => { 'interface' => 'session', 'control_flag' => 'required', 'name' => 'pam_namespace.so', 'args' => 'unmnt_remnt' }, | ||
}, | ||
'includes' => [] | ||
} | ||
} | ||
end | ||
|
||
# set vm.swapiness to 0 (to lessen swapping) | ||
sysctl_param 'vm.swappiness' do | ||
value 0 | ||
end | ||
|
||
# Reboot on kernel panic | ||
sysctl_param 'kernel.panic' do | ||
value 1800 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
# This script is managed by Chef | ||
# It is designed to setup directories using pam_exec | ||
# for the pam_namespaces module to isolate user-direcotires | ||
|
||
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 %>" \ | ||
"<%= @polyinstantion_dir %>" | ||
elif [ -z "$PAM_TYPE" -o "$PAM_TYPE" == "close_session" ]; then | ||
# 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" \ | ||
"<%= @polyinstantion_dir %>/tmp_$PAM_USER" \ | ||
"<%= @polyinstantion_dir %>/var_tmp_$PAM_USER" \ | ||
"/dev/shm/<%= @shm_polyinstantion_dir %>/inst_$PAM_USER" | ||
fi | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# /etc/security/namespace.conf | ||
# | ||
############################# | ||
# This file managed by Chef # | ||
############################# | ||
# | ||
#masked mnt point real mnt point isolation-level excluded users | ||
/var/tmp <%= @polyinstantion_dir %>/var_tmp_ user root | ||
$HOME <%= @polyinstantion_dir %>/home_ user <%= @real_home_dir_users %> | ||
/tmp <%= @polyinstantion_dir %>/tmp_ user root | ||
/dev/shm /dev/shm/<%= @shm_polyinstantion_dir %>/inst_ user root |
Oops, something went wrong.