Skip to content

Commit

Permalink
Merge pull request #164 from anchore/fix-upgrades-for-ssl-db
Browse files Browse the repository at this point in the history
Fix connection strings for db using TLS
  • Loading branch information
Btodhunter authored Sep 2, 2021
2 parents bb2ab87 + 985a036 commit 0a4d7b9
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion stable/anchore-engine/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: anchore-engine
version: 1.14.3
version: 1.14.4
appVersion: 0.10.1
description: Anchore container analysis and policy evaluation engine service
keywords:
Expand Down
5 changes: 4 additions & 1 deletion stable/anchore-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,9 @@ anchoreEnterpriseUI:
## Install using an existing/external PostgreSQL instance
*Note: it is recommended to use an external Postgresql instance for production installs*
*Note: it is recommended to use an external Postgresql instance for production installs.*
See comments in the values.yaml file for details on using SSL for external database connections.
```yaml
postgresql:
Expand All @@ -574,6 +576,7 @@ postgresql:
anchoreGlobal:
dbConfig:
ssl: true
sslMode: require
```
## Install using Google CloudSQL
Expand Down
8 changes: 5 additions & 3 deletions stable/anchore-engine/templates/engine_configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ data:
credentials:
database:
{{- if .Values.anchoreGlobal.dbConfig.ssl }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{- .Values.anchoreGlobal.dbConfig.sslMode -}}&sslrootcert=/home/anchore/certs/{{- .Values.anchoreGlobal.dbConfig.sslRootCertName -}}"
{{- else }}
{{- if not .Values.anchoreGlobal.dbConfig.ssl }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}"
{{- else if eq .Values.anchoreGlobal.dbConfig.sslMode "require" }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{- .Values.anchoreGlobal.dbConfig.sslMode -}}"
{{- else }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{- .Values.anchoreGlobal.dbConfig.sslMode -}}&sslrootcert=/home/anchore/certs/{{- .Values.anchoreGlobal.dbConfig.sslRootCertName -}}"
{{- end }}
db_connect_args:
timeout: {{ .Values.anchoreGlobal.dbConfig.timeout }}
Expand Down
11 changes: 7 additions & 4 deletions stable/anchore-engine/templates/engine_upgrade_job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ spec:
{{- end }}
command: ["/bin/bash", "-c"]
args:
{{- if .Values.anchoreGlobal.dbConfig.ssl }}
{{- if not .Values.anchoreGlobal.dbConfig.ssl }}
- |
anchore-manager db --db-use-ssl --db-connect postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{ .Values.anchoreGlobal.dbConfig.sslMode }}\\&sslrootcert=/home/anchore/certs/{{ .Values.anchoreGlobal.dbConfig.sslRootCertName }} upgrade --dontask;
anchore-manager db --db-connect postgresql://"${ANCHORE_DB_USER}":"${ANCHORE_DB_PASSWORD}"@"${ANCHORE_DB_HOST}"/"${ANCHORE_DB_NAME}" upgrade --dontask;
{{- else if eq .Values.anchoreGlobal.dbConfig.sslMode "require"}}
- |
anchore-manager db --db-use-ssl --db-connect postgresql://"${ANCHORE_DB_USER}":"${ANCHORE_DB_PASSWORD}"@"${ANCHORE_DB_HOST}"/"${ANCHORE_DB_NAME}"?sslmode={{- .Values.anchoreGlobal.dbConfig.sslMode }} upgrade --dontask;
{{- else }}
- |
anchore-manager db --db-connect postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME} upgrade --dontask;
anchore-manager db --db-use-ssl --db-connect postgresql://"${ANCHORE_DB_USER}":"${ANCHORE_DB_PASSWORD}"@"${ANCHORE_DB_HOST}"/"${ANCHORE_DB_NAME}"?sslmode={{- .Values.anchoreGlobal.dbConfig.sslMode -}}\&sslrootcert=/home/anchore/certs/{{- .Values.anchoreGlobal.dbConfig.sslRootCertName }} upgrade --dontask;
{{- end }}
{{- if .Values.cloudsql.enabled }}
sql_proxy_pid=$(pgrep cloud_sql_proxy) && kill -INT $sql_proxy_pid;
Expand Down Expand Up @@ -138,4 +141,4 @@ spec:
{{- with .Values.anchoreGlobal.serviceAccountName }}
serviceAccountName: {{ . }}
{{- end }}
{{- end }}
{{- end }}
8 changes: 5 additions & 3 deletions stable/anchore-engine/templates/enterprise_configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ data:
credentials:
database:
{{- if .Values.anchoreGlobal.dbConfig.ssl }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{- .Values.anchoreGlobal.dbConfig.sslMode -}}&sslrootcert=/home/anchore/certs/{{- .Values.anchoreGlobal.dbConfig.sslRootCertName }}"
{{- else }}
{{- if not .Values.anchoreGlobal.dbConfig.ssl }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}"
{{- else if eq .Values.anchoreGlobal.dbConfig.sslMode "require" }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{- .Values.anchoreGlobal.dbConfig.sslMode -}}"
{{- else }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{- .Values.anchoreGlobal.dbConfig.sslMode -}}&sslrootcert=/home/anchore/certs/{{- .Values.anchoreGlobal.dbConfig.sslRootCertName -}}"
{{- end }}
db_connect_args:
timeout: {{ .Values.anchoreGlobal.dbConfig.timeout }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ data:
credentials:
database:
{{- if .Values.anchoreEnterpriseFeeds.dbConfig.ssl }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_FEEDS_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{- .Values.anchoreEnterpriseFeeds.dbConfig.sslMode -}}&sslrootcert=/home/anchore/certs/{{- .Values.anchoreEnterpriseFeeds.dbConfig.sslRootCertName }}"
{{- else }}
{{- if not .Values.anchoreEnterpriseFeeds.dbConfig.ssl }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_FEEDS_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}"
{{- else if eq .Values.anchoreEnterpriseFeeds.dbConfig.sslMode "require" }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_FEEDS_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{- .Values.anchoreEnterpriseFeeds.dbConfig.sslMode -}}"
{{- else }}
db_connect: "postgresql://${ANCHORE_DB_USER}:${ANCHORE_FEEDS_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{- .Values.anchoreEnterpriseFeeds.dbConfig.sslMode -}}&sslrootcert=/home/anchore/certs/{{- .Values.anchoreEnterpriseFeeds.dbConfig.sslRootCertName }}"
{{- end }}
db_connect_args:
timeout: {{ .Values.anchoreEnterpriseFeeds.dbConfig.timeout }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ spec:
image: {{ .Values.anchoreEnterpriseGlobal.image }}
command: ["/bin/bash", "-c"]
args:
{{- if .Values.anchoreGlobal.dbConfig.ssl }}
{{- if not .Values.anchoreEnterpriseFeeds.dbConfig.ssl }}
- |
anchore-enterprise-manager db --db-use-ssl --db-connect postgresql://${ANCHORE_DB_USER}:${ANCHORE_FEEDS_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{ .Values.anchoreGlobal.dbConfig.sslMode }}\\&sslrootcert=/home/anchore/certs/{{ .Values.anchoreGlobal.dbConfig.sslRootCertName }} upgrade --dontask;
anchore-enterprise-manager db --db-connect postgresql://"${ANCHORE_DB_USER}":"${ANCHORE_FEEDS_DB_PASSWORD}"@"${ANCHORE_DB_HOST}"/"${ANCHORE_DB_NAME}" upgrade --dontask;
{{- else if eq .Values.anchoreEnterpriseFeeds.dbConfig.sslMode "require" }}
- |
anchore-enterprise-manager db --db-use-ssl --db-connect postgresql://"${ANCHORE_DB_USER}":"${ANCHORE_FEEDS_DB_PASSWORD}"@"${ANCHORE_DB_HOST}"/"${ANCHORE_DB_NAME}"?sslmode={{- .Values.anchoreEnterpriseFeeds.dbConfig.sslMode }} upgrade --dontask;
{{- else }}
- |
anchore-enterprise-manager db --db-connect postgresql://${ANCHORE_DB_USER}:${ANCHORE_FEEDS_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME} upgrade --dontask;
anchore-enterprise-manager db --db-use-ssl --db-connect postgresql://"${ANCHORE_DB_USER}":"${ANCHORE_FEEDS_DB_PASSWORD}"@"${ANCHORE_DB_HOST}"/"${ANCHORE_DB_NAME}"?sslmode={{- .Values.anchoreEnterpriseFeeds.dbConfig.sslMode -}}\&sslrootcert=/home/anchore/certs/{{- .Values.anchoreEnterpriseFeeds.dbConfig.sslRootCertName }} upgrade --dontask;
{{- end }}
{{- if .Values.cloudsql.enabled }}
sql_proxy_pid=$(pgrep cloud_sql_proxy) && kill -INT $sql_proxy_pid;
Expand Down
9 changes: 6 additions & 3 deletions stable/anchore-engine/templates/enterprise_upgrade_job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ spec:
image: {{ .Values.anchoreEnterpriseGlobal.image }}
command: ["/bin/bash", "-c"]
args:
{{- if .Values.anchoreGlobal.dbConfig.ssl }}
{{- if not .Values.anchoreGlobal.dbConfig.ssl }}
- |
anchore-enterprise-manager db --db-use-ssl --db-connect postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME}?sslmode={{ .Values.anchoreGlobal.dbConfig.sslMode }}\\&sslrootcert=/home/anchore/certs/{{ .Values.anchoreGlobal.dbConfig.sslRootCertName }} upgrade --dontask;
anchore-enterprise-manager db --db-connect postgresql://"${ANCHORE_DB_USER}":"${ANCHORE_DB_PASSWORD}"@"${ANCHORE_DB_HOST}"/"${ANCHORE_DB_NAME}" upgrade --dontask;
{{- else if eq .Values.anchoreGlobal.dbConfig.sslMode "require" }}
- |
anchore-enterprise-manager db --db-use-ssl --db-connect postgresql://"${ANCHORE_DB_USER}":"${ANCHORE_DB_PASSWORD}"@"${ANCHORE_DB_HOST}"/"${ANCHORE_DB_NAME}"?sslmode={{- .Values.anchoreGlobal.dbConfig.sslMode }} upgrade --dontask;
{{- else }}
- |
anchore-enterprise-manager db --db-connect postgresql://${ANCHORE_DB_USER}:${ANCHORE_DB_PASSWORD}@${ANCHORE_DB_HOST}/${ANCHORE_DB_NAME} upgrade --dontask;
anchore-enterprise-manager db --db-use-ssl --db-connect postgresql://"${ANCHORE_DB_USER}":"${ANCHORE_DB_PASSWORD}"@"${ANCHORE_DB_HOST}"/"${ANCHORE_DB_NAME}"?sslmode={{- .Values.anchoreGlobal.dbConfig.sslMode -}}\&sslrootcert=/home/anchore/certs/{{- .Values.anchoreGlobal.dbConfig.sslRootCertName }} upgrade --dontask;
{{- end }}
{{- if .Values.cloudsql.enabled }}
sql_proxy_pid=$(pgrep cloud_sql_proxy) && kill -INT $sql_proxy_pid;
Expand Down
13 changes: 8 additions & 5 deletions stable/anchore-engine/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ anchoreGlobal:
# Configure the database connection within anchore-engine & enterprise-ui. This may get split into 2 different configurations based on service utilized.
dbConfig:
timeout: 120
# Use ssl, but the default postgresql config in helm's stable repo does not support ssl on server side, so this should be set for external dbs only.
# All ssl dbConfig values are only utilized when ssl=true
# Use ssl, but the default postgresql config from the dependent chart does not support server side ssl, so this should only be enabled for external dbs
ssl: false
# set sslMode to `require` to ignore verifying the root CA - see https://www.postgresql.org/docs/9.1/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS
sslMode: verify-full
# sslRootCertName is the name of the postgres root CA certificate stored in anchoreGlobal.certStoreSecretName
# Specify path to an additional root CA certificate - this is only utilized if 'ssl: true & sslMode: verify-full' are configured.
# sslRootCertName describes the filename that is mounted in `/home/anchore/certs` from the secret defined in anchoreGlobal.certStoreSecretName
sslRootCertName: Null
connectionPoolSize: 30
connectionPoolMaxOverflow: 100
Expand Down Expand Up @@ -767,10 +768,12 @@ anchoreEnterpriseFeeds:
# Configure the database connection within anchore-engine & enterprise-ui. This may get split into 2 different configurations based on service utilized.
dbConfig:
timeout: 120
# Use ssl, but the default postgresql config in helm's stable repo does not support ssl on server side, so this should be set for external dbs
# Use ssl, but the default postgresql config from the dependent chart does not support server side ssl, so this should only be enabled for external dbs
ssl: false
# set sslMode to `require` to ignore verifying the root CA - see https://www.postgresql.org/docs/9.1/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS
sslMode: verify-full
# Specify path to an additional root CA certificate - this is only utilized if 'ssl: true' is configured.
# Specify path to an additional root CA certificate - this is only utilized if 'ssl: true & sslMode: verify-full' are configured.
# sslRootCertName describes the filename that is mounted in `/home/anchore/certs` from the secret defined in anchoreGlobal.certStoreSecretName
sslRootCertName: Null
connectionPoolSize: 30
connectionPoolMaxOverflow: 100
Expand Down

0 comments on commit 0a4d7b9

Please sign in to comment.