From d3da3eed553d4b7790783e31f64bde3d4c85931a Mon Sep 17 00:00:00 2001 From: kfox1111 Date: Wed, 10 May 2023 05:04:34 -0700 Subject: [PATCH] External database configuration (#225) This patch makes all the database settings configurable. fixes: https://github.com/spiffe/helm-charts/issues/37 --------- Signed-off-by: Kevin Fox Signed-off-by: kfox1111 Co-authored-by: Faisal Memon Co-authored-by: Marco Franssen --- .github/tests/charts.json | 10 ++++ .../production-external-mysql/install.sh | 46 ++++++++++++++++++ .../mysql-values.yaml | 7 +++ .../production-external-mysql/post-install.sh | 18 +++++++ .../production-external-mysql/pre-install.sh | 6 +++ .../production-external-postgresql/install.sh | 46 ++++++++++++++++++ .../post-install.sh | 18 +++++++ .../postgresql-values.yaml | 8 ++++ .../pre-install.sh | 6 +++ charts/spire/charts/spire-server/README.md | 16 +++++-- .../spire-server/templates/_helpers.tpl | 48 +++++++++++++++++++ .../spire-server/templates/configmap.yaml | 3 +- .../charts/spire-server/templates/secret.yaml | 9 ++++ .../spire-server/templates/statefulset.yaml | 24 +++++++--- charts/spire/charts/spire-server/values.yaml | 23 ++++++++- examples/bin/readpw.sh | 3 ++ examples/external-mysql/README.md | 22 +++++++++ examples/external-mysql/values.yaml | 10 ++++ examples/external-postgresql/README.md | 23 +++++++++ examples/external-postgresql/values.yaml | 10 ++++ 20 files changed, 342 insertions(+), 14 deletions(-) create mode 100755 .github/tests/production-external-mysql/install.sh create mode 100644 .github/tests/production-external-mysql/mysql-values.yaml create mode 100755 .github/tests/production-external-mysql/post-install.sh create mode 100755 .github/tests/production-external-mysql/pre-install.sh create mode 100755 .github/tests/production-external-postgresql/install.sh create mode 100755 .github/tests/production-external-postgresql/post-install.sh create mode 100644 .github/tests/production-external-postgresql/postgresql-values.yaml create mode 100755 .github/tests/production-external-postgresql/pre-install.sh create mode 100644 charts/spire/charts/spire-server/templates/secret.yaml create mode 100644 examples/bin/readpw.sh create mode 100644 examples/external-mysql/README.md create mode 100644 examples/external-mysql/values.yaml create mode 100644 examples/external-postgresql/README.md create mode 100644 examples/external-postgresql/values.yaml diff --git a/.github/tests/charts.json b/.github/tests/charts.json index 1b8006f..eb72d77 100644 --- a/.github/tests/charts.json +++ b/.github/tests/charts.json @@ -13,5 +13,15 @@ "name": "ingress-nginx", "repo": "https://kubernetes.github.io/ingress-nginx", "version": "4.6.1" + }, + { + "name": "mysql", + "repo": "https://charts.bitnami.com/bitnami", + "version": "9.7.2" + }, + { + "name": "postgresql", + "repo": "https://charts.bitnami.com/bitnami", + "version": "12.2.2" } ] diff --git a/.github/tests/production-external-mysql/install.sh b/.github/tests/production-external-mysql/install.sh new file mode 100755 index 0000000..fc979cd --- /dev/null +++ b/.github/tests/production-external-mysql/install.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +set -xe + +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "$SCRIPT") + +DB=spire +DBUSER=spire +DBPW=$(uuidgen) +DBROOTPW=$(uuidgen) + +# Generate random settings to make sure things come up with random settings. +cat < /tmp/$$-db-values.yaml +auth: + database: ${DB} + username: ${DBUSER} + password: ${DBPW} + rootPassword: ${DBROOTPW} +EOF + +cat < /tmp/$$-spire-values.yaml +spire-server: + dataStore: + sql: + databaseType: mysql + databaseName: ${DB} + username: ${DBUSER} + password: ${DBPW} + host: mysql + port: 3306 + options: + - parseTime: true +EOF + +helm install mysql mysql --namespace "spire-server" --version "$VERSION_MYSQL" --repo "$HELM_REPO_MYSQL" \ + --values "${SCRIPTPATH}/mysql-values.yaml" \ + --values /tmp/$$-db-values.yaml --wait + +helm install \ + --namespace "spire-server" \ + --values /tmp/$$-spire-values.yaml \ + --values "${SCRIPTPATH}/../../../examples/production/values.yaml" \ + spire charts/spire --wait + +helm test spire --namespace "spire-server" diff --git a/.github/tests/production-external-mysql/mysql-values.yaml b/.github/tests/production-external-mysql/mysql-values.yaml new file mode 100644 index 0000000..62f27e2 --- /dev/null +++ b/.github/tests/production-external-mysql/mysql-values.yaml @@ -0,0 +1,7 @@ +primary: + containerSecurityContext: + allowPrivilegeEscalation: false + capabilities: + drop: [ALL] + seccompProfile: + type: RuntimeDefault diff --git a/.github/tests/production-external-mysql/post-install.sh b/.github/tests/production-external-mysql/post-install.sh new file mode 100755 index 0000000..29335e6 --- /dev/null +++ b/.github/tests/production-external-mysql/post-install.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -x + +SCRIPT="$(readlink -f "$0")" +SCRIPTPATH="$(dirname "${SCRIPT}")" +scenario="${scenario:-$(basename "${SCRIPTPATH}")}" + +# shellcheck source=/dev/null +source "${SCRIPTPATH}/../common.sh" + +print_helm_releases +print_spire_workload_status spire-server spire-system + +if [[ "$1" -ne 0 ]]; then + get_namespace_details spire-server + get_namespace_details spire-system +fi diff --git a/.github/tests/production-external-mysql/pre-install.sh b/.github/tests/production-external-mysql/pre-install.sh new file mode 100755 index 0000000..b33d1ed --- /dev/null +++ b/.github/tests/production-external-mysql/pre-install.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +kubectl create namespace spire-system +kubectl label namespace spire-system pod-security.kubernetes.io/enforce=privileged +kubectl create namespace spire-server +kubectl label namespace spire-server pod-security.kubernetes.io/enforce=restricted diff --git a/.github/tests/production-external-postgresql/install.sh b/.github/tests/production-external-postgresql/install.sh new file mode 100755 index 0000000..38b56c4 --- /dev/null +++ b/.github/tests/production-external-postgresql/install.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +set -xe + +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "$SCRIPT") + +DB=$(uuidgen) +DBUSER=$(uuidgen) +DBPW=$(uuidgen) +DBPGPW=$(uuidgen) + +# Generate random settings to make sure things come up with random settings. +cat > /tmp/$$-db-values.yaml < /tmp/$$-spire-values.yaml <