|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +##### |
| 4 | +## This script generates a secrets file for an environment. |
| 5 | +## |
| 6 | +## The environment can either be given as an argument or activated. |
| 7 | +##### |
| 8 | + |
| 9 | +set -eo pipefail |
| 10 | + |
| 11 | + |
| 12 | +# Parse the command line arguments |
| 13 | +# The environment defaults to the active environment, if set |
| 14 | +COMMAND_ENVIRONMENT="${AZIMUTH_CONFIG_ENVIRONMENT:-""}" |
| 15 | +FORCE_OVERWRITE= |
| 16 | +while [[ $# -gt 0 ]]; do |
| 17 | + case $1 in |
| 18 | + -f|--force) |
| 19 | + FORCE_OVERWRITE="yes" |
| 20 | + shift |
| 21 | + ;; |
| 22 | + *) |
| 23 | + COMMAND_ENVIRONMENT="$1" |
| 24 | + shift |
| 25 | + ;; |
| 26 | + esac |
| 27 | +done |
| 28 | + |
| 29 | +# If the environment is unknown at this point, bail |
| 30 | +if [ -z "$COMMAND_ENVIRONMENT" ]; then |
| 31 | + echo "Target environment must either be specified as an argument or activated" >&2 |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +# Work out where the secrets file for the specified environment lives |
| 36 | +CONFIG_ROOT="$(dirname $(dirname $(realpath ${BASH_SOURCE[0]:-${(%):-%x}})))" |
| 37 | +# We check environments and .github/environments, as in activate |
| 38 | +if [ -d "$CONFIG_ROOT/environments/$COMMAND_ENVIRONMENT" ]; then |
| 39 | + CONFIG_ENVIRONMENT_ROOT="$CONFIG_ROOT/environments/$COMMAND_ENVIRONMENT" |
| 40 | +elif [ -d "$CONFIG_ROOT/.github/environments/$COMMAND_ENVIRONMENT" ]; then |
| 41 | + CONFIG_ENVIRONMENT_ROOT="$CONFIG_ROOT/.github/environments/$COMMAND_ENVIRONMENT" |
| 42 | +else |
| 43 | + echo "Unrecognised config environment '$COMMAND_ENVIRONMENT'" >&2 |
| 44 | + exit 1 |
| 45 | +fi |
| 46 | +SECRETS_FILE="$CONFIG_ENVIRONMENT_ROOT/inventory/group_vars/all/secrets.yml" |
| 47 | +echo "Writing secrets to $SECRETS_FILE" |
| 48 | + |
| 49 | +# If the secrets file already exists, do not overwrite it unless explicitly requested |
| 50 | +if [ -f "$SECRETS_FILE" ]; then |
| 51 | + if [ "$FORCE_OVERWRITE" = "yes" ]; then |
| 52 | + echo "$SECRETS_FILE already exists - overwriting" |
| 53 | + else |
| 54 | + echo "$SECRETS_FILE already exists - will not overwrite" >&2 |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | +fi |
| 58 | + |
| 59 | +# Write the secrets file, making sure the directory exists first |
| 60 | +mkdir -p "$(dirname $SECRETS_FILE)" |
| 61 | +cat <<EOF > $SECRETS_FILE |
| 62 | +##### |
| 63 | +# This file contains secrets for the $COMMAND_ENVIRONMENT environment |
| 64 | +# |
| 65 | +# It should be encrypted if stored in version control |
| 66 | +# https://azimuth-config.readthedocs.io/en/stable/repository/secrets/ |
| 67 | +##### |
| 68 | +
|
| 69 | +# https://azimuth-config.readthedocs.io/en/stable/configuration/05-secret-key/ |
| 70 | +# The secret key for signing Azimuth cookies |
| 71 | +azimuth_secret_key: "$(openssl rand -hex 32)" |
| 72 | +
|
| 73 | +# https://azimuth-config.readthedocs.io/en/stable/configuration/07-platform-identity/#keycloak-admin-password |
| 74 | +# The admin password for the Keycloak master realm |
| 75 | +keycloak_admin_password: "$(openssl rand -hex 16)" |
| 76 | +
|
| 77 | +# https://azimuth-config.readthedocs.io/en/stable/configuration/08-zenith/ |
| 78 | +# The secret key for signing Zenith registrar tokens |
| 79 | +zenith_registrar_subdomain_token_signing_key: "$(openssl rand -hex 32)" |
| 80 | +
|
| 81 | +# https://azimuth-config.readthedocs.io/en/stable/configuration/10-kubernetes-clusters/#harbor-registry |
| 82 | +# The password for the Harbor admin account |
| 83 | +harbor_admin_password: "$(openssl rand -hex 16)" |
| 84 | +# The secret key for Harbor |
| 85 | +harbor_secret_key: "$(openssl rand -hex 8)" |
| 86 | +
|
| 87 | +# https://azimuth-config.readthedocs.io/en/stable/configuration/14-monitoring/#accessing-web-interfaces |
| 88 | +# The admin password for Azimuth administrative dashboards |
| 89 | +admin_dashboard_ingress_basic_auth_password: "$(openssl rand -hex 16)" |
| 90 | +EOF |
0 commit comments