Skip to content
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

Centralize and fix random identifier generation. #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/install/setup_properties.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ export SERVICE_ACCOUNT_NAME="${SERVICE_ACCOUNT_NAME:-"\$DEPLOYMENT_NAME-acc-$(da
export REDIS_INSTANCE=\$DEPLOYMENT_NAME

# If bucket does not exist, it will be created.
export BUCKET_NAME="\$DEPLOYMENT_NAME-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 20 | head -n 1)-$(date +"%s")"
export BUCKET_NAME="\$DEPLOYMENT_NAME-$(random_identifier 20)-$(date +"%s")"
export BUCKET_URI="gs://\$BUCKET_NAME"

# If CSR repo does not exist, it will be created.
export CONFIG_CSR_REPO=\$DEPLOYMENT_NAME-config

# Used to authenticate calls to the audit log Cloud Function.
export AUDIT_LOG_UNAME="$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 20 | head -n 1)-$(date +"%s")"
export AUDIT_LOG_PW="$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 20 | head -n 1)-$(date +"%s")"
export AUDIT_LOG_UNAME="$(random_identifier 20)-$(date +"%s")"
export AUDIT_LOG_PW="$(random_identifier 20)-$(date +"%s")"

export CLOUD_FUNCTION_NAME="\${DEPLOYMENT_NAME//-}AuditLog"

Expand Down
6 changes: 5 additions & 1 deletion scripts/manage/add_gke_account.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash

readonly THIS_DIRECTORY=$(cd $(dirname "${0}") && pwd)

source "${THIS_DIRECTORY}/service_utils.sh"

bold() {
echo ". $(tput bold)" "$*" "$(tput sgr0)";
}
Expand Down Expand Up @@ -64,7 +68,7 @@ for r in "${GKE_REQUIRED_ROLES[@]}"; do
done

mkdir -p ~/.hal/default/credentials
KUBECONFIG_FILENAME="kubeconfig-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 9 | head -n 1)"
KUBECONFIG_FILENAME="kubeconfig-$(random_identifier 9)"

bold "Copying ~/.kube/config into ~/.hal/default/credentials/$KUBECONFIG_FILENAME so it can be pushed to your halyard daemon's pod..."

Expand Down
16 changes: 15 additions & 1 deletion scripts/manage/service_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,18 @@ check_for_shared_vpc() {
bold "Automated setup of Spinnaker for GCP with a Shared VPC host project is currently unsupported. To proceed, continue the setup in Cloud Shell."
exit 1
fi
}
}

# Generate random alpha-numeric characters in the set [0-9a-z].
#
# $1: Number of characters to generate.
random_identifier() {
local size=$((${1}))
if [[ $((size)) -le 0 ]]; then
echo "Invalid identifier size (${size})." >&2
return 1
fi
cat /dev/urandom 2>/dev/null | \
tr -dc 'a-z0-9' 2>/dev/null | \
head -c $((size))
}