-
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 rotation script #2453
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
# This script updates the munge key used in the system. | ||
# It fetches the key from AWS Secrets Manager or generates one if it doesn't exist. | ||
# The script does not require any argument. | ||
# | ||
# Usage: ./update_munge_key.sh | ||
# # | ||
|
||
set -e | ||
|
||
MUNGE_KEY_FILE="/etc/munge/munge.key" | ||
SECRET_ARN="<%= @munge_key_secret_arn %>" | ||
REGION="<%= @region %>" | ||
MUNGE_USER="<%= @munge_user %>" | ||
MUNGE_GROUP="<%= @munge_group %>" | ||
CLUSTER_USER="<%= @cluster_user %>" | ||
|
||
# If SECRET_ARN is provided, fetch the munge key from Secrets Manager | ||
if [ -n "${SECRET_ARN}" ]; then | ||
echo "Fetching munge key from AWS Secrets Manager: ${SECRET_ARN}" | ||
encoded_key=$(aws secretsmanager get-secret-value --secret-id ${SECRET_ARN} --query 'SecretString' --output text --region ${REGION}) | ||
|
||
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 munge.key file | ||
decoded_key=$(echo $encoded_key | base64 -d) | ||
if [ $? -ne 0 ]; then | ||
echo "Error decoding the munge key with base64" | ||
exit 1 | ||
fi | ||
|
||
# Remove current munge key if exists | ||
if [ -f "${MUNGE_KEY_FILE}" ]; then | ||
rm -f ${MUNGE_KEY_FILE} | ||
fi | ||
|
||
echo "${decoded_key}" > ${MUNGE_KEY_FILE} | ||
|
||
# Set ownership on the key | ||
chown ${MUNGE_USER}:${MUNGE_GROUP} ${MUNGE_KEY_FILE} | ||
# Enforce correct permission on the key | ||
chmod 0600 ${MUNGE_KEY_FILE} | ||
|
||
else | ||
echo "MUNGE KEY SECRET ARN isn't provided" | ||
exit 1 | ||
fi | ||
|
||
# Enable and restart munge service | ||
systemctl enable munge | ||
echo "Start to Restart munge service" | ||
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. Minor: 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! |
||
systemctl restart munge || { sleep 10; systemctl restart munge; } || { sleep 10; systemctl restart munge; } || { sleep 10; systemctl restart munge; } || { sleep 10; systemctl restart munge; } | ||
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. Is there a reason for the multiple sleep commands? Is it to wait for the service to restart? I think Did you notice asynchronous behaviour while running the command? Also after restarting the munge service we can check if it's running 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.
I add the retry codes because I mentioned the But yes, I think we can remove it. Also I added the checking commands. |
||
echo "Restart munge service completed" | ||
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. Minor: 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! 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. Also done for |
||
|
||
# Share munge key | ||
echo "Start to Share munge key" | ||
mkdir -p /home/${CLUSTER_USER}/.munge | ||
cp /etc/munge/munge.key /home/${CLUSTER_USER}/.munge/.munge.key | ||
echo "Share munge key completed" | ||
|
||
exit 0 |
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.
See comment in the update PR: 2452/files#r1325705545
I think we can simply override the existing key without explicitly removing it.
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.
Have safely removing these codes.