Skip to content

Commit 747517b

Browse files
Process the config option `DeploymentSettings/DefaultUserHome and move the cluster user out of /home when the default_user_home option is set to local (#2620)
Refactored the cookbook to use an attribute for the default user's home directory so that it can be changed when using the new config option. Also simplified the users attribute file since the exta OS specific files were not adding any value and duplicating code.
1 parent a39e96a commit 747517b

File tree

14 files changed

+217
-9
lines changed

14 files changed

+217
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This file is used to list changes made in each version of the AWS ParallelCluste
77
------
88

99
**ENHANCEMENTS**
10+
- Add the configuration parameter `DeploymentSettings/DefaultUserHome` to allow users to move the default user's home directory to `/local/home` instead of `/home` (default).
1011
- Add support for installing Intel OneAPI Base Toolkit and HPC Toolkit, and Intel Python.
1112
- Intel OneAPI Base Toolkits: 2023.2.0
1213
- Intel OneAPI HPC Toolkits: 2023.2.0

cookbooks/aws-parallelcluster-environment/kitchen.environment-config.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,3 +752,39 @@ suites:
752752
dependencies:
753753
- recipe:aws-parallelcluster-platform::directories
754754
- resource:spack:setup
755+
- name: default_user_local_home_head_node
756+
run_list:
757+
- recipe[aws-parallelcluster-tests::setup]
758+
- recipe[aws-parallelcluster-environment::config_default_user_home]
759+
verifier:
760+
controls:
761+
- local_default_user_home
762+
attributes:
763+
cluster:
764+
node_type: 'HeadNode'
765+
scheduler: 'slurm'
766+
default_user_home: 'local'
767+
- name: default_user_local_home_compute
768+
run_list:
769+
- recipe[aws-parallelcluster-tests::setup]
770+
- recipe[aws-parallelcluster-environment::config_default_user_home]
771+
verifier:
772+
controls:
773+
- local_default_user_home
774+
attributes:
775+
cluster:
776+
node_type: 'ComputeFleet'
777+
scheduler: 'slurm'
778+
default_user_home: 'local'
779+
- name: default_user_local_home_login
780+
run_list:
781+
- recipe[aws-parallelcluster-tests::setup]
782+
- recipe[aws-parallelcluster-environment::config_default_user_home]
783+
verifier:
784+
controls:
785+
- local_default_user_home
786+
attributes:
787+
cluster:
788+
node_type: 'LoginNode'
789+
scheduler: 'slurm'
790+
default_user_home: 'local'

cookbooks/aws-parallelcluster-environment/recipes/init.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
action :configure
1818
end
1919

20+
# move the default user dir out of /home if the config param is set to 'local'
21+
include_recipe "aws-parallelcluster-environment::config_default_user_home"
22+
2023
case node['cluster']['shared_storage_type']
2124
when 'efs'
2225
include_recipe "aws-parallelcluster-environment::mount_internal_use_efs"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright:: 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the
7+
# License. A copy of the License is located at
8+
#
9+
# http://aws.amazon.com/apache2.0/
10+
#
11+
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
12+
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
return if node['cluster']['default_user_home'] == 'shared'
16+
17+
# Backup the cluster user's default home directory
18+
bash "Backup #{node['cluster']['cluster_user_home']}" do
19+
user 'root'
20+
group 'root'
21+
code <<-EOH
22+
set -e
23+
if [ -d /tmp#{node['cluster']['cluster_user_home']} ]; then
24+
echo "/tmp#{node['cluster']['cluster_user_home']} exists!"
25+
exit 1
26+
else
27+
mkdir -p /tmp#{node['cluster']['cluster_user_home']}
28+
fi
29+
rsync -a #{node['cluster']['cluster_user_home']}/ /tmp#{node['cluster']['cluster_user_home']}
30+
EOH
31+
end
32+
33+
# move the cluster user's default home directory
34+
bash "Move #{node['cluster']['cluster_user_home']}" do
35+
user 'root'
36+
group 'root'
37+
code <<-EOH
38+
set -e
39+
mkdir -p #{node['cluster']['cluster_user_local_home']}
40+
rsync -a /tmp#{node['cluster']['cluster_user_home']}/ #{node['cluster']['cluster_user_local_home']}
41+
usermod -d #{node['cluster']['cluster_user_local_home']} #{node['cluster']['cluster_user']}
42+
chown -R #{node['cluster']['cluster_user']}: #{node['cluster']['cluster_user_local_home']}
43+
rm -rf /tmp#{node['cluster']['cluster_user_home']}
44+
rm -rf #{node['cluster']['cluster_user_home']}
45+
EOH
46+
end
47+
48+
node.override['cluster']['cluster_user_home'] = node['cluster']['cluster_user_local_home']
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'spec_helper'
2+
3+
describe 'aws-parallelcluster-environment::config_default_user_home' do
4+
for_all_oses do |platform, version|
5+
context "on #{platform}#{version}" do
6+
context 'when local' do
7+
cached(:chef_run) do
8+
runner = runner(platform: platform, version: version) do |node|
9+
node.override['cluster']['default_user_home'] = "local"
10+
node.override['cluster']['cluster_user_home'] = "/home/user"
11+
node.override['cluster']['cluster_user_local_home'] = "/local/home/user"
12+
end
13+
runner.converge(described_recipe)
14+
end
15+
cached(:node) { chef_run.node }
16+
17+
it 'runs the recipe' do
18+
is_expected.to run_bash("Backup /home/user")
19+
is_expected.to run_bash("Move /home/user")
20+
expect(chef_run.node['cluster']['cluster_user_home']).to eq('/local/home/user')
21+
end
22+
end
23+
context 'when shared' do
24+
cached(:chef_run) do
25+
runner = runner(platform: platform, version: version) do |node|
26+
node.override['cluster']['default_user_home'] = "shared"
27+
node.override['cluster']['cluster_user_home'] = "/home/user"
28+
node.override['cluster']['cluster_user_local_home'] = "/local/home/user"
29+
end
30+
runner.converge(described_recipe)
31+
end
32+
cached(:node) { chef_run.node }
33+
34+
it 'skips the recipe' do
35+
is_expected.not_to run_bash("Backup /home/user")
36+
is_expected.not_to run_bash("Move /home/user")
37+
expect(chef_run.node['cluster']['cluster_user_home']).to eq('/home/user')
38+
end
39+
end
40+
end
41+
end
42+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright:: 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License").
4+
# You may not use this file except in compliance with the License. A copy of the License is located at
5+
#
6+
# http://aws.amazon.com/apache2.0/
7+
#
8+
# or in the "LICENSE.txt" file accompanying this file.
9+
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
10+
# See the License for the specific language governing permissions and limitations under the License.
11+
12+
control 'local_default_user_home' do
13+
title 'Check if the home directory is in a local directory'
14+
15+
only_if { !os_properties.on_docker? }
16+
17+
describe directory("/local/home") do
18+
it { should exist }
19+
its('owner') { should eq 'root' }
20+
its('group') { should eq 'root' }
21+
its('mode') { should cmp '0755' }
22+
end
23+
describe directory("#{node['cluster']['cluster_user_local_home']}") do
24+
it { should exist }
25+
its('owner') { should eq "#{node['cluster']['cluster_user']}" }
26+
its('group') { should eq "#{node['cluster']['cluster_user']}" }
27+
its('mode') { should cmp '0700' }
28+
end
29+
end

cookbooks/aws-parallelcluster-platform/recipes/config/cluster_user.rb

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,88 @@
1212
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
node.override['cluster']['cluster_user_home'] = node['cluster']['cluster_user_local_home'] if node['cluster']['default_user_home'] == 'local'
16+
1517
case node['cluster']['node_type']
1618
when 'HeadNode'
1719
# Setup cluster user
1820
user node['cluster']['cluster_user'] do
1921
manage_home true
2022
comment 'AWS ParallelCluster user'
21-
home "/home/#{node['cluster']['cluster_user']}"
23+
home "#{node['cluster']['cluster_user_home']}"
2224
shell '/bin/bash'
2325
end
2426

2527
# Setup SSH auth for cluster user
2628
bash "ssh-keygen" do
27-
cwd "/home/#{node['cluster']['cluster_user']}"
29+
cwd "#{node['cluster']['cluster_user_home']}"
2830
code <<-KEYGEN
2931
set -e
3032
su - #{node['cluster']['cluster_user']} -c \"ssh-keygen -q -t ed25519 -f ~/.ssh/id_ed25519 -N ''\"
3133
KEYGEN
32-
not_if { ::File.exist?("/home/#{node['cluster']['cluster_user']}/.ssh/id_ed25519") }
34+
not_if { ::File.exist?("#{node['cluster']['cluster_user_home']}/.ssh/id_ed25519") }
3335
end
3436

3537
bash "copy_and_perms" do
36-
cwd "/home/#{node['cluster']['cluster_user']}"
38+
cwd "#{node['cluster']['cluster_user_home']}"
3739
code <<-PERMS
3840
set -e
3941
su - #{node['cluster']['cluster_user']} -c \"cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys && touch ~/.ssh/authorized_keys_cluster\"
4042
PERMS
41-
not_if { ::File.exist?("/home/#{node['cluster']['cluster_user']}/.ssh/authorized_keys_cluster") }
43+
not_if { ::File.exist?("#{node['cluster']['cluster_user_home']}/.ssh/authorized_keys_cluster") }
44+
end
45+
46+
bash "share_auth_keys_for_local_default_user_home" do
47+
code <<-PERMS
48+
set -e
49+
cp -p #{node['cluster']['cluster_user_home']}/.ssh/authorized_keys #{node['cluster']['shared_dir']}
50+
cp -p #{node['cluster']['cluster_user_home']}/.ssh/authorized_keys #{node['cluster']['shared_dir_login_nodes']}
51+
PERMS
52+
only_if { node['cluster']['default_user_home'] == 'local' }
4253
end
4354

4455
bash "ssh-keyscan" do
45-
cwd "/home/#{node['cluster']['cluster_user']}"
56+
cwd "#{node['cluster']['cluster_user_home']}"
4657
code <<-KEYSCAN
4758
set -e
4859
su - #{node['cluster']['cluster_user']} -c \"ssh-keyscan #{node['hostname']} > ~/.ssh/known_hosts && chmod 0600 ~/.ssh/known_hosts\"
4960
KEYSCAN
50-
not_if { ::File.exist?("/home/#{node['cluster']['cluster_user']}/.ssh/known_hosts") }
61+
not_if { ::File.exist?("#{node['cluster']['cluster_user_home']}/.ssh/known_hosts") }
62+
end
63+
64+
when 'ComputeFleet'
65+
# Setup cluster user
66+
user node['cluster']['cluster_user'] do
67+
manage_home false
68+
comment 'AWS ParallelCluster user'
69+
home "#{node['cluster']['cluster_user_home']}"
70+
shell '/bin/bash'
5171
end
5272

53-
when 'ComputeFleet', 'LoginNode'
73+
bash "copy_auth_file" do
74+
code <<-PERMS
75+
set -e
76+
cp -p #{node['cluster']['shared_dir']}/authorized_keys #{node['cluster']['cluster_user_home']}/.ssh/authorized_keys
77+
PERMS
78+
only_if { node['cluster']['default_user_home'] == 'local' }
79+
end
5480

81+
when 'LoginNode'
5582
# Setup cluster user
5683
user node['cluster']['cluster_user'] do
5784
manage_home false
5885
comment 'AWS ParallelCluster user'
59-
home "/home/#{node['cluster']['cluster_user']}"
86+
home "#{node['cluster']['cluster_user_home']}"
6087
shell '/bin/bash'
6188
end
89+
90+
bash "copy_auth_file" do
91+
code <<-PERMS
92+
set -e
93+
cp -p #{node['cluster']['shared_dir_login_nodes']}/authorized_keys #{node['cluster']['cluster_user_home']}/.ssh/authorized_keys
94+
PERMS
95+
only_if { node['cluster']['default_user_home'] == 'local' }
96+
end
6297
else
6398
raise "node_type must be HeadNode, LoginNode or ComputeFleet"
6499
end

cookbooks/aws-parallelcluster-shared/attributes/users.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
default['cluster']['munge']['user_id'] = node['cluster']['reserved_base_uid'] + 2
1919
default['cluster']['munge']['group'] = node['cluster']['munge']['user']
2020
default['cluster']['munge']['group_id'] = node['cluster']['munge']['user_id']
21+
22+
default['cluster']['cluster_user_home'] = "/home/#{node['cluster']['cluster_user']}"
23+
default['cluster']['cluster_user_local_home'] = "/local#{node['cluster']['cluster_user_home']}"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
return unless platform?('amazon') && node['platform_version'] == "2"
22

33
default['cluster']['cluster_user'] = 'ec2-user'
4+
default['cluster']['cluster_user_home'] = "/home/#{node['cluster']['cluster_user']}"
5+
default['cluster']['cluster_user_local_home'] = "/local#{node['cluster']['cluster_user_home']}"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
return unless platform?('centos') && node['platform_version'].to_i == 7
22

33
default['cluster']['cluster_user'] = 'centos'
4+
default['cluster']['cluster_user_home'] = "/home/#{node['cluster']['cluster_user']}"
5+
default['cluster']['cluster_user_local_home'] = "/local#{node['cluster']['cluster_user_home']}"

0 commit comments

Comments
 (0)