-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utility for generating secrets for an environment (#191)
* Add utility for generating secrets for an environment * Add documentation for generating secrets
- Loading branch information
Showing
13 changed files
with
160 additions
and
14 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env bash | ||
|
||
##### | ||
## This script generates a secrets file for an environment. | ||
## | ||
## The environment can either be given as an argument or activated. | ||
##### | ||
|
||
set -eo pipefail | ||
|
||
|
||
# Parse the command line arguments | ||
# The environment defaults to the active environment, if set | ||
COMMAND_ENVIRONMENT="${AZIMUTH_CONFIG_ENVIRONMENT:-""}" | ||
FORCE_OVERWRITE= | ||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
-f|--force) | ||
FORCE_OVERWRITE="yes" | ||
shift | ||
;; | ||
*) | ||
COMMAND_ENVIRONMENT="$1" | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
# If the environment is unknown at this point, bail | ||
if [ -z "$COMMAND_ENVIRONMENT" ]; then | ||
echo "Target environment must either be specified as an argument or activated" >&2 | ||
exit 1 | ||
fi | ||
|
||
# Work out where the secrets file for the specified environment lives | ||
CONFIG_ROOT="$(dirname $(dirname $(realpath ${BASH_SOURCE[0]:-${(%):-%x}})))" | ||
# We check environments and .github/environments, as in activate | ||
if [ -d "$CONFIG_ROOT/environments/$COMMAND_ENVIRONMENT" ]; then | ||
CONFIG_ENVIRONMENT_ROOT="$CONFIG_ROOT/environments/$COMMAND_ENVIRONMENT" | ||
elif [ -d "$CONFIG_ROOT/.github/environments/$COMMAND_ENVIRONMENT" ]; then | ||
CONFIG_ENVIRONMENT_ROOT="$CONFIG_ROOT/.github/environments/$COMMAND_ENVIRONMENT" | ||
else | ||
echo "Unrecognised config environment '$COMMAND_ENVIRONMENT'" >&2 | ||
exit 1 | ||
fi | ||
SECRETS_FILE="$CONFIG_ENVIRONMENT_ROOT/inventory/group_vars/all/secrets.yml" | ||
echo "Writing secrets to $SECRETS_FILE" | ||
|
||
# If the secrets file already exists, do not overwrite it unless explicitly requested | ||
if [ -f "$SECRETS_FILE" ]; then | ||
if [ "$FORCE_OVERWRITE" = "yes" ]; then | ||
echo "$SECRETS_FILE already exists - overwriting" | ||
else | ||
echo "$SECRETS_FILE already exists - will not overwrite" >&2 | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# Write the secrets file, making sure the directory exists first | ||
mkdir -p "$(dirname $SECRETS_FILE)" | ||
cat <<EOF > $SECRETS_FILE | ||
##### | ||
# This file contains secrets for the $COMMAND_ENVIRONMENT environment | ||
# | ||
# It should be encrypted if stored in version control | ||
# https://azimuth-config.readthedocs.io/en/stable/repository/secrets/ | ||
##### | ||
# https://azimuth-config.readthedocs.io/en/stable/configuration/05-secret-key/ | ||
# The secret key for signing Azimuth cookies | ||
azimuth_secret_key: "$(openssl rand -hex 32)" | ||
# https://azimuth-config.readthedocs.io/en/stable/configuration/07-platform-identity/#keycloak-admin-password | ||
# The admin password for the Keycloak master realm | ||
keycloak_admin_password: "$(openssl rand -hex 16)" | ||
# https://azimuth-config.readthedocs.io/en/stable/configuration/08-zenith/ | ||
# The secret key for signing Zenith registrar tokens | ||
zenith_registrar_subdomain_token_signing_key: "$(openssl rand -hex 32)" | ||
# https://azimuth-config.readthedocs.io/en/stable/configuration/10-kubernetes-clusters/#harbor-registry | ||
# The password for the Harbor admin account | ||
harbor_admin_password: "$(openssl rand -hex 16)" | ||
# The secret key for Harbor | ||
harbor_secret_key: "$(openssl rand -hex 8)" | ||
# https://azimuth-config.readthedocs.io/en/stable/configuration/14-monitoring/#accessing-web-interfaces | ||
# The admin password for Azimuth administrative dashboards | ||
admin_dashboard_ingress_basic_auth_password: "$(openssl rand -hex 16)" | ||
EOF |
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
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
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
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