Skip to content

Commit 39a93c1

Browse files
Move the cluster user out of /home when the default_user_home option is set to local
1 parent 06edb61 commit 39a93c1

File tree

9 files changed

+71
-23
lines changed

9 files changed

+71
-23
lines changed

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 out of home if the config param is set
21+
include_recipe "aws-parallelcluster-environment::move_default_user" if node['cluster']['default_user_home'] == 'local'
22+
2023
case node['cluster']['shared_storage_type']
2124
when 'efs'
2225
include_recipe "aws-parallelcluster-environment::mount_internal_use_efs"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright:: 2023 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+
# Backup the cluster user's default home directory
16+
bash "Backup #{node['cluster']['cluster_user_home']}" do
17+
user 'root'
18+
group 'root'
19+
code <<-EOH
20+
mkdir -p /tmp#{node['cluster']['cluster_user_home']}
21+
rsync -a #{node['cluster']['cluster_user_home']} /tmp#{node['cluster']['cluster_user_home']}
22+
EOH
23+
end
24+
25+
# Move the cluster user's default home directory
26+
bash "Move #{node['cluster']['cluster_user_home']}" do
27+
user 'root'
28+
group 'root'
29+
code <<-EOH
30+
mkdir -p #{node['cluster']['cluster_user_local_home']}
31+
rsync -a /tmp#{node['cluster']['cluster_user_home']}/ #{node['cluster']['cluster_user_local_home']}
32+
usermod -d #{node['cluster']['cluster_user_local_home']} #{node['cluster']['cluster_user']}
33+
rm -rf /tmp#{node['cluster']['cluster_user_home']}
34+
EOH
35+
end
36+
37+
Chef::Log.info("user home before #{node['cluster']['cluster_user_home']}")
38+
node.normal['cluster']['cluster_user_home'] = node['cluster']['cluster_user_local_home']
39+
Chef::Log.info("user home after #{node['cluster']['cluster_user_home']}")
40+

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,46 @@
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+
Chef::Log.info("config - user home before #{node['cluster']['cluster_user_home']}")
16+
node.normal['cluster']['cluster_user_home'] = node['cluster']['cluster_user_local_home'] if node['cluster']['default_user_home'] == 'local'
17+
Chef::Log.info("config - user home after #{node['cluster']['cluster_user_home']}")
18+
1519
case node['cluster']['node_type']
1620
when 'HeadNode'
1721
# Setup cluster user
1822
user node['cluster']['cluster_user'] do
1923
manage_home true
2024
comment 'AWS ParallelCluster user'
21-
home "/home/#{node['cluster']['cluster_user']}"
25+
home "#{node['cluster']['cluster_user_home']}"
2226
shell '/bin/bash'
2327
end
2428

2529
# Setup SSH auth for cluster user
2630
bash "ssh-keygen" do
27-
cwd "/home/#{node['cluster']['cluster_user']}"
31+
cwd "#{node['cluster']['cluster_user_home']}"
2832
code <<-KEYGEN
2933
set -e
3034
su - #{node['cluster']['cluster_user']} -c \"ssh-keygen -q -t ed25519 -f ~/.ssh/id_ed25519 -N ''\"
3135
KEYGEN
32-
not_if { ::File.exist?("/home/#{node['cluster']['cluster_user']}/.ssh/id_ed25519") }
36+
not_if { ::File.exist?("#{node['cluster']['cluster_user_home']}/.ssh/id_ed25519") }
3337
end
3438

3539
bash "copy_and_perms" do
36-
cwd "/home/#{node['cluster']['cluster_user']}"
40+
cwd "#{node['cluster']['cluster_user_home']}"
3741
code <<-PERMS
3842
set -e
3943
su - #{node['cluster']['cluster_user']} -c \"cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys && touch ~/.ssh/authorized_keys_cluster\"
4044
PERMS
41-
not_if { ::File.exist?("/home/#{node['cluster']['cluster_user']}/.ssh/authorized_keys_cluster") }
45+
not_if { ::File.exist?("#{node['cluster']['cluster_user_home']}/.ssh/authorized_keys_cluster") }
4246
end
4347

4448
bash "ssh-keyscan" do
45-
cwd "/home/#{node['cluster']['cluster_user']}"
49+
cwd "#{node['cluster']['cluster_user_home']}"
4650
code <<-KEYSCAN
4751
set -e
4852
su - #{node['cluster']['cluster_user']} -c \"ssh-keyscan #{node['hostname']} > ~/.ssh/known_hosts && chmod 0600 ~/.ssh/known_hosts\"
4953
KEYSCAN
50-
not_if { ::File.exist?("/home/#{node['cluster']['cluster_user']}/.ssh/known_hosts") }
54+
not_if { ::File.exist?("#{node['cluster']['cluster_user_home']}/.ssh/known_hosts") }
5155
end
5256

5357
when 'ComputeFleet', 'LoginNode'
@@ -56,7 +60,7 @@
5660
user node['cluster']['cluster_user'] do
5761
manage_home false
5862
comment 'AWS ParallelCluster user'
59-
home "/home/#{node['cluster']['cluster_user']}"
63+
home "#{node['cluster']['cluster_user_home']}"
6064
shell '/bin/bash'
6165
end
6266
else

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,19 @@
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+
if (platform?('amazon') && node['platform_version'].to_i == 2) ||
23+
(platform?('redhat') && node['platform_version'].to_i == 8)
24+
default['cluster']['cluster_user'] = 'ec2-user'
25+
elsif platform?('centos') && node['platform_version'].to_i == 7
26+
default['cluster']['cluster_user'] = 'centos'
27+
elsif platform?('rocky') && node['platform_version'].to_i == 8
28+
default['cluster']['cluster_user'] = 'rocky'
29+
elsif platform?('ubuntu')
30+
default['cluster']['cluster_user'] = 'ubuntu'
31+
else
32+
raise "The OS must be one of the following: Amazon Linux 2, Ubuntu, CentOS 7, RHEL 8, or Rocky 8"
33+
end
34+
35+
default['cluster']['cluster_user_home'] = "/home/#{node['cluster']['cluster_user']}"
36+
default['cluster']['cluster_user_local_home'] = "/local/home/#{node['cluster']['cluster_user']}"

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)