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

feat: add ssl config to postgres #135

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/migration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ jobs:
run: |
set -e
kubectl create ns reports-server
kubectl apply -f ./config/install.yaml
export HELM=${{ steps.helm.outputs.helm-path }}
make kind-apply
- name: Wait for report server ready
run: |
set -e
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ kind-install-inmemory: $(HELM) kind-load ## Build image, load it in kind cluster
--set postgresql.enabled=false \
--set image.repository=$(PACKAGE) \
--set image.tag=$(GIT_SHA)

.PHONY: kind-apply
kind-apply: $(HELM) kind-load ## Build image, load it in kind cluster and deploy helm chart
@echo Install chart... >&2
@$(HELM) template reports-server --namespace reports-server ./charts/reports-server \
--set image.registry=$(KO_REGISTRY) \
--set image.repository=$(PACKAGE) \
--set image.tag=$(GIT_SHA) \
| kubectl apply -f -

########
# HELP #
Expand Down
4 changes: 4 additions & 0 deletions charts/reports-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ helm install reports-server --namespace reports-server --create-namespace report
| config.db.userSecretKeyName | string | `"username"` | The database username will be read from this `key` in the specified Secret, when `db.secretName` is set. |
| config.db.password | string | `"reports"` | Database password |
| config.db.passwordSecretKeyName | string | `"password"` | The database password will be read from this `key` in the specified Secret, when `db.secretName` is set. |
| config.db.sslmode | string | `"disable"` | Database SSL |
| config.db.sslrootcert | string | `""` | Database SSL root cert |
| config.db.sslkey | string | `""` | Database SSL key |
| config.db.sslcert | string | `""` | Database SSL cert |

## Source Code

Expand Down
4 changes: 4 additions & 0 deletions charts/reports-server/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ spec:
- --dbname={{ include "reports-server.dbName" . }}
- --dbuser={{ include "reports-server.dbUser" . }}
- --dbpassword={{ include "reports-server.dbPassword" . }}
- --dbsslmode={{ .Values.config.db.sslmode }}
- --dbsslrootcert={{ .Values.config.db.sslrootcert }}
- --dbsslkey={{ .Values.config.db.sslkey }}
- --dbsslcert={{ .Values.config.db.sslcert }}
{{- end }}
- --cert-dir=/tmp
- --secure-port=4443
Expand Down
14 changes: 14 additions & 0 deletions charts/reports-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,24 @@ config:

# -- Database user
user: postgres

# -- The database username will be read from this `key` in the specified Secret, when `db.secretName` is set.
userSecretKeyName: "username"

# -- Database password
password: reports

# -- The database password will be read from this `key` in the specified Secret, when `db.secretName` is set.
passwordSecretKeyName: "password"

# -- Database SSL
sslmode: disable

# -- Database SSL root cert
sslrootcert: ""

# -- Database SSL key
sslkey: ""

# -- Database SSL cert
sslcert: ""
4 changes: 4 additions & 0 deletions config/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ spec:
- --dbname=reportsdb
- --dbuser=postgres
- --dbpassword=reports
- --dbsslmode=disable
- --dbsslrootcert=
- --dbsslkey=
- --dbsslcert=
- --cert-dir=/tmp
- --secure-port=4443
securityContext:
Expand Down
34 changes: 24 additions & 10 deletions pkg/app/opts/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ type Options struct {
ShowVersion bool
Debug bool
Kubeconfig string
DBHost string
DBPort int
DBUser string
DBPassword string
DBName string

// dbopts
DBHost string
DBPort int
DBUser string
DBPassword string
DBName string
DBSSLMode string
DBSSLRootCert string
DBSSLKey string
DBSSLCert string

// Only to be used to for testing
DisableAuthForTesting bool
Expand Down Expand Up @@ -67,6 +73,10 @@ func (o *Options) Flags() (fs flag.NamedFlagSets) {
msfs.StringVar(&o.DBUser, "dbuser", "postgres", "Username to login into postgres")
msfs.StringVar(&o.DBPassword, "dbpassword", "password", "Password to login into postgres")
msfs.StringVar(&o.DBName, "dbname", "reportsdb", "Name of the database to store policy reports in")
msfs.StringVar(&o.DBSSLMode, "dbsslmode", "disable", "SSL mode of the postgres database.")
msfs.StringVar(&o.DBSSLRootCert, "dbsslrootcert", "", "Path to database root cert.")
msfs.StringVar(&o.DBSSLKey, "dbsslkey", "", "Path to database ssl key.")
msfs.StringVar(&o.DBSSLCert, "dbsslcert", "", "Path to database ssl cert.")

o.SecureServing.AddFlags(fs.FlagSet("apiserver secure serving"))
o.Authentication.AddFlags(fs.FlagSet("apiserver authentication"))
Expand Down Expand Up @@ -101,11 +111,15 @@ func (o Options) ServerConfig() (*server.Config, error) {
}

dbconfig := &db.PostgresConfig{
Host: o.DBHost,
Port: o.DBPort,
User: o.DBUser,
Password: o.DBPassword,
DBname: o.DBName,
Host: o.DBHost,
Port: o.DBPort,
User: o.DBUser,
Password: o.DBPassword,
DBname: o.DBName,
SSLMode: o.DBSSLMode,
SSLRootCert: o.DBSSLRootCert,
SSLKey: o.DBSSLKey,
SSLCert: o.DBSSLCert,
}

return &server.Config{
Expand Down
18 changes: 11 additions & 7 deletions pkg/storage/db/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,19 @@ func (p *postgresstore) Ready() bool {
}

type PostgresConfig struct {
Host string
Port int
User string
Password string
DBname string
Host string
Port int
User string
Password string
DBname string
SSLMode string
SSLRootCert string
SSLKey string
SSLCert string
}

func (p PostgresConfig) String() string {
return fmt.Sprintf("host=%s port=%d user=%s "+
"password=%s dbname=%s sslmode=disable",
p.Host, p.Port, p.User, p.Password, p.DBname)
"password=%s dbname=%s sslmode=%s sslrootcert=%s sslkey=%s sslcert=%s",
p.Host, p.Port, p.User, p.Password, p.DBname, p.SSLMode, p.SSLRootCert, p.SSLKey, p.SSLCert)
}
Loading