Skip to content

Commit d37a393

Browse files
Matt PryorMoteHue
authored andcommitted
Utility for generating secrets for an environment (azimuth-cloud#191)
* Add utility for generating secrets for an environment * Add documentation for generating secrets
1 parent ddb4209 commit d37a393

File tree

13 files changed

+160
-14
lines changed

13 files changed

+160
-14
lines changed

.github/actions/setup/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ runs:
107107
source ./bin/activate "$AZIMUTH_CONFIG_ENVIRONMENT" "$AZIMUTH_ENVIRONMENT"
108108
ansible-galaxy install -f -r requirements.yml
109109
110+
- name: Generate secrets for environment
111+
shell: bash
112+
run: |
113+
set -e
114+
source ci.env
115+
source ./bin/activate "$AZIMUTH_CONFIG_ENVIRONMENT" "$AZIMUTH_ENVIRONMENT"
116+
./bin/generate-secrets
117+
110118
# Generate and append the S3 credential to the CI environment file
111119
- name: Configure S3 lock
112120
id: s3-lock-config

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
.python-version
66
/clouds.yaml*
77
tilt-settings.yaml
8+
# Ignore generated secrets in demo and CI environments
9+
environments/demo/inventory/group_vars/all/secrets.yml
10+
.github/environments/**/secrets.yml

bin/generate-secrets

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

bin/kube-connect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22

33
#####
4-
## This script uses Tilt (tilt.dev) to allow easier code development on the
5-
## currently activated environment
4+
## This script allows access to the Azimuth Kubernetes cluster from the machine
5+
## where the script is executed by using a SOCKS proxy
66
#####
77

88
set -eo pipefail

docs/configuration/05-secret-key.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ azimuth_secret_key: "<some secret key>"
99
!!! tip
1010
1111
This key should be a long, random string - at least 32 bytes (256 bits) is recommended.
12-
A suitable key can be generated using `openssl rand -hex 32`.
12+
13+
`azimuth-config` includes a utility for generating secrets for an environment:
14+
15+
```sh
16+
./bin/generate-secrets [--force] <environment-name>
17+
```
1318

1419
!!! danger
1520

docs/configuration/07-platform-identity.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ The only required configuration for platform identity is to set the admin passwo
7979
keycloak_admin_password: "<secure password>"
8080
```
8181
82+
!!! tip
83+
84+
`azimuth-config` includes a utility for generating secrets for an environment:
85+
86+
```sh
87+
./bin/generate-secrets [--force] <environment-name>
88+
```
89+
8290
!!! danger
8391

8492
This password should be kept secret. If you want to keep the password in Git - which is

docs/configuration/08-zenith.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ zenith_registrar_subdomain_token_signing_key: "<some secret key>"
1818
!!! tip
1919
2020
This key must be a long, random string - at least 32 bytes (256 bits) is required.
21-
A suitable key can be generated using `openssl rand -hex 32`.
21+
22+
`azimuth-config` includes a utility for generating secrets for an environment:
23+
24+
```sh
25+
./bin/generate-secrets [--force] <environment-name>
26+
```
2227

2328
!!! danger
2429

docs/configuration/10-kubernetes-clusters.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ harbor_admin_password: "<secure password>"
159159
harbor_secret_key: "<secure secret key>"
160160
```
161161

162+
!!! tip
163+
164+
`azimuth-config` includes a utility for generating secrets for an environment:
165+
166+
```sh
167+
./bin/generate-secrets [--force] <environment-name>
168+
```
169+
162170
!!! danger
163171

164172
These values should be kept secret. If you want to keep them in Git - which is recommended -

docs/configuration/14-monitoring.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ admin_dashboard_ingress_basic_auth_password: "<secure password>"
5151
As such you should ensure that a strong password is used, and take care when sharing
5252
it.
5353
54+
!!! tip
55+
56+
`azimuth-config` includes a utility for generating secrets for an environment:
57+
58+
```sh
59+
./bin/generate-secrets [--force] <environment-name>
60+
```
61+
5462
!!! danger
5563

5664
This password should be kept secret. If you want to keep the password in Git - which is

docs/developing/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export OS_CLIENT_CONFIG_FILE=/path/to/clouds.yaml
7070
# with other deployments that use the dev environment
7171
source ./bin/activate dev jbloggs-dev
7272

73+
# Generate secrets locally for the active environment, if required
74+
# DO NOT COMMIT THE GENERATED FILE TO GIT
75+
./bin/generate-secrets
76+
7377
# Install Azimuth as usual
7478
ansible-galaxy install -f -r requirements.yml
7579
ansible-playbook azimuth_cloud.azimuth_ops.provision

0 commit comments

Comments
 (0)