From c29f45fc3041d22ec8fddb20faf115ffa0e0d086 Mon Sep 17 00:00:00 2001 From: kfox1111 Date: Tue, 8 Oct 2024 10:50:32 -0700 Subject: [PATCH] Add AWS DB types (#464) * Add remaining data store options Signed-off-by: Kevin Fox * Fix env var Signed-off-by: Kevin Fox * Add aws db types Signed-off-by: Kevin Fox * Update charts/spire/README.md Co-authored-by: Faisal Memon Signed-off-by: kfox1111 * Update charts/spire/README.md Co-authored-by: Faisal Memon Signed-off-by: kfox1111 * Fix mysql vars Signed-off-by: Kevin Fox * Incorperate feedback Signed-off-by: Kevin Fox * Incorperate feedback Signed-off-by: Kevin Fox * Fix missing ) Signed-off-by: Kevin Fox * Incorperate feedback Signed-off-by: Kevin Fox * Update charts/spire/charts/spire-server/values.yaml Co-authored-by: Marco Franssen Signed-off-by: kfox1111 * Fix readme Signed-off-by: Kevin Fox --------- Signed-off-by: Kevin Fox Signed-off-by: kfox1111 Co-authored-by: Faisal Memon Co-authored-by: Marco Franssen --- charts/spire/charts/spire-server/README.md | 21 ++++++------- .../spire-server/templates/_helpers.tpl | 30 ++++++++++++++----- .../templates/server-resource.yaml | 8 ++--- charts/spire/charts/spire-server/values.yaml | 23 +++++++------- 4 files changed, 50 insertions(+), 32 deletions(-) diff --git a/charts/spire/charts/spire-server/README.md b/charts/spire/charts/spire-server/README.md index a2e7852..8c68060 100644 --- a/charts/spire/charts/spire-server/README.md +++ b/charts/spire/charts/spire-server/README.md @@ -125,13 +125,13 @@ In order to run Tornjak with simple HTTP Connection only, make sure you don't cr | `persistence.accessMode` | What access mode to use for persistence. Valid options are ReadWriteOnce (recommended), ReadWriteOncePod, ReadWriteMany (not recommended) | `ReadWriteOnce` | | `persistence.storageClass` | What storage class to use for persistence | `nil` | | `persistence.hostPath` | Which path to use on the host when persistence.type = hostPath | `""` | -| `dataStore.sql.databaseType` | Other supported databases are "postgres" and "mysql" | `sqlite3` | -| `dataStore.sql.databaseName` | Only used by "postgres" or "mysql" | `spire` | -| `dataStore.sql.host` | Only used by "postgres" or "mysql" | `""` | +| `dataStore.sql.databaseType` | Other supported databases are ["postgres", "mysql", "aws_postgresql", "aws_mysql"]. Note: aws type databases are still experimental | `sqlite3` | +| `dataStore.sql.databaseName` | Only used when type != "sqlite3" | `spire` | +| `dataStore.sql.host` | Only used when type != "sqlite3" | `""` | | `dataStore.sql.port` | If 0 (default), it will auto set to 5432 for postgres and 3306 for mysql. Only used by those databases. | `0` | -| `dataStore.sql.username` | Only used by "postgres" or "mysql" | `spire` | -| `dataStore.sql.password` | Only used by "postgres" or "mysql" | `""` | -| `dataStore.sql.options` | Only used by "postgres" or "mysql" | `[]` | +| `dataStore.sql.username` | Only used when type != "sqlite3" | `spire` | +| `dataStore.sql.password` | Only used when type != "sqlite3" | `""` | +| `dataStore.sql.options` | Only used when type != "sqlite3" | `[]` | | `dataStore.sql.rootCAPath` | Path to Root CA bundle (MySQL only) | `""` | | `dataStore.sql.clientCertPath` | Path to client certificate (MySQL only) | `""` | | `dataStore.sql.clientKeyPath` | Path to private key for client certificate (MySQL only) | `""` | @@ -142,12 +142,13 @@ In order to run Tornjak with simple HTTP Connection only, make sure you don't cr | `dataStore.sql.maxIdleConns` | The maximum number of idle connections in the pool | `2` | | `dataStore.sql.connMaxLifetime` | The maximum amount of time a connection may be reused. If 0, time is unlimited | `0` | | `dataStore.sql.disableMigration` | True to disable auto-migration functionality | `false` | +| `dataStore.sql.region` | Region to use when database type is either aws_mysql or aws_postgresql | `""` | | `dataStore.sql.readOnly.enabled` | Set to true to configure a readOnly dartabase connection | `false` | -| `dataStore.sql.readOnly.host` | Only used by "postgres" or "mysql" | `""` | +| `dataStore.sql.readOnly.host` | Only used when type != "sqlite3" | `""` | | `dataStore.sql.readOnly.port` | If 0 (default), it will auto set to 5432 for postgres and 3306 for mysql. Only used by those databases. | `0` | -| `dataStore.sql.readOnly.username` | Only used by "postgres" or "mysql" | `spire` | -| `dataStore.sql.readOnly.password` | Only used by "postgres" or "mysql" | `""` | -| `dataStore.sql.readOnly.options` | Only used by "postgres" or "mysql" | `[]` | +| `dataStore.sql.readOnly.username` | Only used when type != "sqlite3" | `spire` | +| `dataStore.sql.readOnly.password` | Only used when type != "sqlite3" | `""` | +| `dataStore.sql.readOnly.options` | Only used when type != "sqlite3" | `[]` | | `dataStore.sql.readOnly.externalSecret.enabled` | Enable external secret for datastore creds | `false` | | `dataStore.sql.readOnly.externalSecret.name` | The name of the secret object | `""` | | `dataStore.sql.readOnly.externalSecret.key` | The key of the secret object whose value is the dataStore.sql password | `""` | diff --git a/charts/spire/charts/spire-server/templates/_helpers.tpl b/charts/spire/charts/spire-server/templates/_helpers.tpl index 299dae3..7fb09cd 100644 --- a/charts/spire/charts/spire-server/templates/_helpers.tpl +++ b/charts/spire/charts/spire-server/templates/_helpers.tpl @@ -190,28 +190,42 @@ Create the name of the service account to use {{- define "spire-server.datastore-config" }} {{- $config := dict }} +{{- $pw := "" }} +{{- $ropw := "" }} {{- if eq .Values.dataStore.sql.databaseType "sqlite3" }} {{- $_ := set $config "database_type" "sqlite3" }} {{- $_ := set $config "connection_string" "/run/spire/data/datastore.sqlite3" }} -{{- else if eq .Values.dataStore.sql.databaseType "mysql" }} - {{- $_ := set $config "database_type" "mysql" }} +{{- else if or (eq .Values.dataStore.sql.databaseType "mysql") (eq .Values.dataStore.sql.databaseType "aws_mysql") }} + {{- if eq .Values.dataStore.sql.databaseType "mysql" }} + {{- $_ := set $config "database_type" "mysql" }} + {{- $pw = "${DBPW}" }} + {{- $ropw = "${RODBPW}" }} + {{- else }} + {{- $_ := set $config "database_type" (list (dict "aws_mysql" (dict "region" .Values.dataStore.sql.region))) }} + {{- end }} {{- $port := int .Values.dataStore.sql.port | default 3306 }} {{- $query := include "spire-server.config-mysql-query" .Values.dataStore.sql.options }} - {{- $_ := set $config "connection_string" (printf "%s:${DBPW}@tcp(%s:%d)/%s%s" .Values.dataStore.sql.username .Values.dataStore.sql.host $port .Values.dataStore.sql.databaseName $query) }} + {{- $_ := set $config "connection_string" (printf "%s:%s@tcp(%s:%d)/%s%s" .Values.dataStore.sql.username $pw .Values.dataStore.sql.host $port .Values.dataStore.sql.databaseName $query) }} {{- if .Values.dataStore.sql.readOnly.enabled }} {{- $roPort := int .Values.dataStore.sql.readOnly.port | default 3306 }} {{- $roQuery := include "spire-server.config-mysql-query" .Values.dataStore.sql.readOnly.options }} - {{- $_ := set $config "ro_connection_string" (printf "%s:${RODBPW}@tcp(%s:%d)/%s%s" .Values.dataStore.sql.readOnly.username .Values.dataStore.sql.readOnly.host $roPort .Values.dataStore.sql.readOnly.databaseName $roQuery) }} + {{- $_ := set $config "ro_connection_string" (printf "%s:%s@tcp(%s:%d)/%s%s" .Values.dataStore.sql.readOnly.username $ropw .Values.dataStore.sql.readOnly.host $roPort .Values.dataStore.sql.readOnly.databaseName $roQuery) }} + {{- end }} +{{- else if or (eq .Values.dataStore.sql.databaseType "postgres") (eq .Values.dataStore.sql.databaseType "aws_postgres") }} + {{- if eq .Values.dataStore.sql.databaseType "postgres" }} + {{- $_ := set $config "database_type" "postgres" }} + {{- $pw = " password=${DBPW}" }} + {{- $ropw = " password=${RODBPW}" }} + {{- else }} + {{- $_ := set $config "database_type" (list (dict "aws_postgres" (dict "region" .Values.dataStore.sql.region))) }} {{- end }} -{{- else if eq .Values.dataStore.sql.databaseType "postgres" }} - {{- $_ := set $config "database_type" "postgres" }} {{- $port := int .Values.dataStore.sql.port | default 5432 }} {{- $options:= include "spire-server.config-postgresql-options" .Values.dataStore.sql.options }} - {{- $_ := set $config "connection_string" (printf "dbname=%s user=%s password=${DBPW} host=%s port=%d%s" .Values.dataStore.sql.databaseName .Values.dataStore.sql.username .Values.dataStore.sql.host $port $options) }} + {{- $_ := set $config "connection_string" (printf "dbname=%s user=%s%s host=%s port=%d%s" .Values.dataStore.sql.databaseName .Values.dataStore.sql.username $pw .Values.dataStore.sql.host $port $options) }} {{- if .Values.dataStore.sql.readOnly.enabled }} {{- $roPort := int .Values.dataStore.sql.readOnly.port | default 5432 }} {{- $roOptions:= include "spire-server.config-postgresql-options" .Values.dataStore.sql.readOnly.options }} - {{- $_ := set $config "ro_connection_string" (printf "dbname=%s user=%s password=${RODBPW} host=%s port=%d%s" .Values.dataStore.sql.readOnly.databaseName .Values.dataStore.sql.readOnly.username .Values.dataStore.sql.readOnly.host $roPort $roOptions) }} + {{- $_ := set $config "ro_connection_string" (printf "dbname=%s user=%s%s host=%s port=%d%s" .Values.dataStore.sql.readOnly.databaseName $ropw .Values.dataStore.sql.readOnly.username .Values.dataStore.sql.readOnly.host $roPort $roOptions) }} {{- end }} {{- else }} {{- fail "Unsupported database type" }} diff --git a/charts/spire/charts/spire-server/templates/server-resource.yaml b/charts/spire/charts/spire-server/templates/server-resource.yaml index 3cf971b..97a5894 100644 --- a/charts/spire/charts/spire-server/templates/server-resource.yaml +++ b/charts/spire/charts/spire-server/templates/server-resource.yaml @@ -53,15 +53,15 @@ {{- if hasKey .Values.dataStore.sql "plugin_data" }} {{- fail "The plugin_data setting to the sql data store is no longer supported." }} {{- end }} -{{- if ne .Values.dataStore.sql.databaseType "mysql" }} +{{- if and (ne .Values.dataStore.sql.databaseType "mysql") (ne .Values.dataStore.sql.databaseType "aws_mysql") }} {{- if ne .Values.dataStore.sql.rootCAPath "" }} -{{- fail "rootCAPath can only be set with database type mysql." }} +{{- fail "rootCAPath can only be set with database type mysql or aws_mysql." }} {{- end }} {{- if ne .Values.dataStore.sql.clientCertPath "" }} -{{- fail "clientCertPath can only be set with database type mysql." }} +{{- fail "clientCertPath can only be set with database type mysql or aws_mysql." }} {{- end }} {{- if ne .Values.dataStore.sql.clientKeyPath "" }} -{{- fail "clientKeyPath can only be set with database type mysql." }} +{{- fail "clientKeyPath can only be set with database type mysql or aws_mysql." }} {{- end }} {{- end }} {{- if not .Values.externalServer }} diff --git a/charts/spire/charts/spire-server/values.yaml b/charts/spire/charts/spire-server/values.yaml index 11a81e9..7fe6bd8 100644 --- a/charts/spire/charts/spire-server/values.yaml +++ b/charts/spire/charts/spire-server/values.yaml @@ -155,19 +155,19 @@ persistence: dataStore: sql: - ## @param dataStore.sql.databaseType Other supported databases are "postgres" and "mysql" + ## @param dataStore.sql.databaseType Other supported databases are ["postgres", "mysql", "aws_postgresql", "aws_mysql"]. Note: aws type databases are still experimental databaseType: sqlite3 - ## @param dataStore.sql.databaseName Only used by "postgres" or "mysql" + ## @param dataStore.sql.databaseName Only used when type != "sqlite3" databaseName: spire - ## @param dataStore.sql.host Only used by "postgres" or "mysql" + ## @param dataStore.sql.host Only used when type != "sqlite3" host: "" ## @param dataStore.sql.port If 0 (default), it will auto set to 5432 for postgres and 3306 for mysql. Only used by those databases. port: 0 - ## @param dataStore.sql.username Only used by "postgres" or "mysql" + ## @param dataStore.sql.username Only used when type != "sqlite3" username: spire - ## @param dataStore.sql.password Only used by "postgres" or "mysql" + ## @param dataStore.sql.password Only used when type != "sqlite3" password: "" - ## @param dataStore.sql.options [array] Only used by "postgres" or "mysql" + ## @param dataStore.sql.options [array] Only used when type != "sqlite3" options: [] ## @param dataStore.sql.rootCAPath Path to Root CA bundle (MySQL only) @@ -195,18 +195,21 @@ dataStore: ## @param dataStore.sql.disableMigration True to disable auto-migration functionality disableMigration: false + ## @param dataStore.sql.region Region to use when database type is either aws_mysql or aws_postgresql + region: "" + readOnly: ## @param dataStore.sql.readOnly.enabled Set to true to configure a readOnly dartabase connection enabled: false - ## @param dataStore.sql.readOnly.host Only used by "postgres" or "mysql" + ## @param dataStore.sql.readOnly.host Only used when type != "sqlite3" host: "" ## @param dataStore.sql.readOnly.port If 0 (default), it will auto set to 5432 for postgres and 3306 for mysql. Only used by those databases. port: 0 - ## @param dataStore.sql.readOnly.username Only used by "postgres" or "mysql" + ## @param dataStore.sql.readOnly.username Only used when type != "sqlite3" username: spire - ## @param dataStore.sql.readOnly.password Only used by "postgres" or "mysql" + ## @param dataStore.sql.readOnly.password Only used when type != "sqlite3" password: "" - ## @param dataStore.sql.readOnly.options [array] Only used by "postgres" or "mysql" + ## @param dataStore.sql.readOnly.options [array] Only used when type != "sqlite3" options: [] ## When an external source creates the secret. The secret should reside in the same namespace as the spire server externalSecret: