Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Dependency check chart to create randomly Generate Postgresql Password #90

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ CI based on Github Actions, Kind and Chart-testing tool. See [Youtube video](htt

Add the repo:
`helm repo add evryfs-oss https://evryfs.github.io/helm-charts/`

this repo contains charts for the following deployments
4 changes: 2 additions & 2 deletions charts/dependency-track/templates/backend/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ spec:
- name: ALPINE_DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-postgresql
key: postgresql-password
name: {{- if .Values.postgresql.existingSecret }} {{ .Values.postgresql.existingSecret }} {{ else }} {{ .Release.Name }}-postgresql {{- end }}
key: {{ .Values.postgresql.secretKey }}
- name: ALPINE_DATABASE_USERNAME
value: {{ .Values.postgresql.postgresqlUsername }}
{{- end }}
Expand Down
41 changes: 41 additions & 0 deletions charts/dependency-track/templates/secret-postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- if .Values.createPostgresqlSecret -}}
{{- $relname := printf "%s-%s" .Release.Name "postgresql" -}}
apiVersion: v1
kind: Secret
metadata:
name: {{- if .Values.postgresql.existingSecret }} {{ .Values.postgresql.existingSecret }} {{ else }} {{ $relname }} {{- end }}
labels: {{- include "backend.labels.standard" . | nindent 4 }}
annotations:
type: Opaque
data:
{{- if .Release.IsUpgrade }}
# check to see if secret already exists in namespace.
{{- if (index (lookup "v1" "Secret" .Release.Namespace $relname ) ) }}
postgresql-postgres-password: {{ index (lookup "v1" "Secret" .Release.Namespace $relname ).data "postgresql-password" }}
{{ .Values.postgresql.secretKey }}: {{ index (lookup "v1" "Secret" .Release.Namespace $relname ).data "postgresql-password" }}
{{- else if (index (lookup "v1" "Secret" .Release.Namespace .Values.postgresql.existingSecret ) ) }}
postgresql-postgres-password: {{ index (lookup "v1" "Secret" .Release.Namespace .Values.postgresql.existingSecret ).data "postgresql-password" }}
{{ .Values.postgresql.secretKey }}: {{ index (lookup "v1" "Secret" .Release.Namespace .Values.postgresql.existingSecret ).data "postgresql-password" }}
{{ else }}
# if a secret isn't found when perfroming an upgrade create a new secret.
{{- if .Values.postgresql.postgresqlPassword }}
postgresql-postgres-password: {{ .Values.postgresql.postgresqlPassword | b64enc | quote }}
{{ .Values.postgresql.secretKey }}: {{ .Values.postgresql.postgresqlPassword | b64enc | quote }}
{{- else }}
{{- $postgresRandomPassword := randAlphaNum 16 | b64enc | quote }}
postgresql-postgres-password: {{ $postgresRandomPassword }}
{{ .Values.postgresql.secretKey }}: {{ $postgresRandomPassword }}
{{- end }}
{{- end }}
{{ else }}
# Perform normal install operation
{{- if .Values.postgresql.postgresqlPassword }}
postgresql-postgres-password: {{ .Values.postgresql.postgresqlPassword | b64enc | quote }}
{{ .Values.postgresql.secretKey }}: {{ .Values.postgresql.postgresqlPassword | b64enc | quote }}
{{- else }}
{{- $postgresRandomPassword := randAlphaNum 16 | b64enc | quote }}
postgresql-postgres-password: {{ $postgresRandomPassword }}
{{ .Values.postgresql.secretKey }}: {{ $postgresRandomPassword }}
{{- end }}
{{- end }}
{{- end }}
6 changes: 5 additions & 1 deletion charts/dependency-track/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,14 @@ ingress:
## allow large bom.xml uploads:
# nginx.ingress.kubernetes.io/proxy-body-size: 10m
host: chart-example.local

createPostgresqlSecret: true # create the postgresql secret in Dependency Track chart, outside of the postgresql chart.

# Postgres variables
postgresql:
enabled: true
postgresqlUsername: deptrack
postgresqlPassword: deptrack
postgresqlPassword: ""
postgresqlDatabase: deptrack
existingSecret: deptrack-postgresql # This is the full name of the secret that will be created
secretKey: postgresql-password