-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[develop] Add custom munge key config logic #2451
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1522536
Munge key config
hehe7318 c2b0df0
Address comments
hehe7318 f42eded
Modify the config of kitchen tests
hehe7318 56cf708
Add a null value for custom munge key secret arn for now.
hehe7318 b1bc02d
Test of kitchen tests
hehe7318 ed1305d
Merge branch 'develop' into wip/munge-key-config
hehe7318 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 18 additions & 0 deletions
18
cookbooks/aws-parallelcluster-slurm/recipes/config/config_munge_key.rb
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
# | ||
# Cookbook:: aws-parallelcluster-slurm | ||
# Recipe:: config_munge_key | ||
# | ||
# Copyright:: 2013-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the | ||
# License. A copy of the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
setup_munge_head_node unless on_docker? |
72 changes: 72 additions & 0 deletions
72
cookbooks/aws-parallelcluster-slurm/resources/munge_key_manager.rb
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,72 @@ | ||
# frozen_string_literal: true | ||
|
||
# | ||
# Cookbook:: aws-parallelcluster-slurm | ||
# Recipe:: config_head_node | ||
# | ||
# Copyright:: 2013-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the | ||
# License. A copy of the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
resource_name :munge_key_manager | ||
provides :munge_key_manager | ||
unified_mode true | ||
|
||
property :munge_key_secret_arn, String | ||
|
||
default_action :setup_munge_key | ||
|
||
action :setup_munge_key do | ||
if new_resource.munge_key_secret_arn | ||
# This block will fetch the munge key from Secrets Manager | ||
bash 'fetch_and_decode_munge_key' do | ||
user 'root' | ||
group 'root' | ||
cwd '/tmp' | ||
code <<-FETCH_AND_DECODE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
set -e | ||
# Get encoded munge key from secrets manager | ||
encoded_key=$(aws secretsmanager get-secret-value --secret-id #{new_resource.munge_key_secret_arn} --query 'SecretString' --output text --region #{node['cluster']['region']}) | ||
# If encoded_key doesn't have a value, error and exit | ||
if [ -z "$encoded_key" ]; then | ||
echo "Error fetching munge key from Secrets Manager or the key is empty" | ||
exit 1 | ||
fi | ||
|
||
# Decode munge key and write to /etc/munge/munge.key | ||
decoded_key=$(echo $encoded_key | base64 -d) | ||
if [ $? -ne 0 ]; then | ||
echo "Error decoding the munge key with base64" | ||
exit 1 | ||
fi | ||
|
||
echo "$decoded_key" > /etc/munge/munge.key | ||
|
||
# Set ownership on the key | ||
chown #{node['cluster']['munge']['user']}:#{node['cluster']['munge']['group']} /etc/munge/munge.key | ||
# Enforce correct permission on the key | ||
chmod 0600 /etc/munge/munge.key | ||
FETCH_AND_DECODE | ||
end | ||
else | ||
# This block will generate a munge key if it doesn't exist | ||
bash 'generate_munge_key' do | ||
not_if { ::File.exist?('/etc/munge/munge.key') } | ||
user node['cluster']['munge']['user'] | ||
group node['cluster']['munge']['group'] | ||
cwd '/tmp' | ||
code <<-GENERATE_KEY | ||
set -e | ||
/usr/sbin/mungekey --verbose | ||
chmod 0600 /etc/munge/munge.key | ||
GENERATE_KEY | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
controls
should be nested underverifier
.