Skip to content

Commit

Permalink
scripts: Add a check on minion ID in bootstrap
Browse files Browse the repository at this point in the history
The check validates that the Salt minion ID
follows the RFC1123 since this ID will be used
for the Kubernetes Node name.

Refs: #3258
  • Loading branch information
alexandre-allard committed May 3, 2021
1 parent e7869f7 commit cf3716b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/bootstrap.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ check_ca_minion() {
fi
}


main() {
run "Determine the OS" determine_os
if [ -z "${PYTHON:-}" ]; then
Expand All @@ -181,6 +180,7 @@ main() {
run "Disabling Salt minion service" disable_salt_minion_service
run "Stopping Salt minion service" stop_salt_minion_service
run "Installing mandatory packages" install_packages "${PACKAGES[@]}"
run "Checking Salt minion ID" check_minion_id
run "Configuring Salt minion to run in local mode" configure_salt_minion_local_mode
run "Ensure archive is available" ensure_archives_mounted
run "Calculating Salt grains in local mode" set_local_grains
Expand Down
21 changes: 20 additions & 1 deletion scripts/common.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ get_salt_env() {
}

get_salt_minion_id() {
"$SALT_CALL" --out txt grains.get id | cut -c 8-
"$SALT_CALL" --local --out txt grains.get id | cut -c 8-
}

get_salt_minion_ids() {
Expand Down Expand Up @@ -404,3 +404,22 @@ retry() {

echo "$stdout"
}

check_minion_id() {
# Minion ID is used as the Kubernetes Node name, so it must follow the
# RFC1123 (https://tools.ietf.org/html/rfc1123).
# This means the name must:
# - contain no more than 253 characters
# - contain only lowercase alphanumeric characters, '-' or '.'
# - start with an alphanumeric character
# - end with an alphanumeric character
minion_id=$(get_salt_minion_id)

if ! [[ $minion_id =~ ^(([0-9a-z][0-9a-z.-]{0,251}[0-9a-z])|[0-9a-z])$ ]]; then
echo "Invalid Salt minion ID '$minion_id': The ID must be compliant" \
"with RFC1123, which means it must contain no more than 253" \
"characters, contain only lowercase alphanumeric characters, '-'" \
"or '.' and start and end with an alphanumeric character."
return 1
fi
}
1 change: 1 addition & 0 deletions scripts/restore.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ run "Disabling Salt minion service" disable_salt_minion_service
run "Stopping Salt minion service" stop_salt_minion_service
run "Configuring local repositories" configure_repositories
run "Installing mandatory packages" install_packages "${PACKAGES[@]}"
run "Checking Salt minion ID" check_minion_id
run "Configuring Salt minion to run in local mode" configure_salt_minion_local_mode

run "Restoring MetalK8s configurations" restore_metalk8s_conf
Expand Down

0 comments on commit cf3716b

Please sign in to comment.