Skip to content

Commit

Permalink
Revert "Fixes argoproj#10234 - Postgres SSL Certificate fix (argoproj…
Browse files Browse the repository at this point in the history
…#10300)" (#16)

This PR:
- reverts the broken postgres connection PR
  • Loading branch information
JPZ13 authored Mar 22, 2023
1 parent f3d4c77 commit 5d67218
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 52 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ FROM gcr.io/distroless/static as workflow-controller

USER 8737

WORKDIR /home/argo

COPY hack/ssh_known_hosts /etc/ssh/
COPY hack/nsswitch.conf /etc/
COPY --chown=8737 --from=workflow-controller-build /go/src/github.com/argoproj/argo-workflows/dist/workflow-controller /bin/
Expand Down
15 changes: 2 additions & 13 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,8 @@ func (c DatabaseConfig) GetHostname() string {

type PostgreSQLConfig struct {
DatabaseConfig
SSL bool `json:"ssl,omitempty"`
SSLMode string `json:"sslMode,omitempty"`
CaCertSecret apiv1.SecretKeySelector `json:"caCertSecret,omitempty"`
ClientCertSecret apiv1.SecretKeySelector `json:"clientCertSecret,omitempty"`
ClientKeySecret apiv1.SecretKeySelector `json:"clientKeySecret,omitempty"`
CertPath string `json:"certPath"`
}

func (c PostgreSQLConfig) GetPGCertPath() string {
if c.CertPath != "" {
return c.CertPath
}
return "/home/argo/pgcerts"
SSL bool `json:"ssl,omitempty"`
SSLMode string `json:"sslMode,omitempty"`
}

type MySQLConfig struct {
Expand Down
39 changes: 2 additions & 37 deletions persist/sqldb/sqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sqldb
import (
"context"
"fmt"
"os"
"time"

"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -54,43 +53,9 @@ func CreatePostGresDBSession(kubectlConfig kubernetes.Interface, namespace strin
}

if cfg.SSL {
if cfg.SSLMode != "" && cfg.SSLMode != "disable" {
err := os.MkdirAll(cfg.GetPGCertPath(), 0700)
if err != nil {
return nil, "", err
}
rootCertByte, err := util.GetSecrets(ctx, kubectlConfig, namespace, cfg.CaCertSecret.Name, cfg.CaCertSecret.Key)
if err != nil {
return nil, "", err
}
err = os.WriteFile(cfg.GetPGCertPath()+"/ca.crt", rootCertByte, 0600)
if err != nil {
return nil, "", err
}

serverCertByte, err := util.GetSecrets(ctx, kubectlConfig, namespace, cfg.ClientCertSecret.Name, cfg.ClientCertSecret.Key)
if err != nil {
return nil, "", err
}
err = os.WriteFile(cfg.GetPGCertPath()+"/tls.crt", serverCertByte, 0600)
if err != nil {
return nil, "", err
}

serverKeyByte, err := util.GetSecrets(ctx, kubectlConfig, namespace, cfg.ClientKeySecret.Name, cfg.ClientKeySecret.Key)
if err != nil {
return nil, "", err
}
err = os.WriteFile(cfg.GetPGCertPath()+"/tls.key", serverKeyByte, 0400)
if err != nil {
return nil, "", err
}

if cfg.SSLMode != "" {
options := map[string]string{
"sslmode": cfg.SSLMode,
"sslrootcert": cfg.GetPGCertPath() + "/ca.crt",
"sslkey": cfg.GetPGCertPath() + "/tls.key",
"sslcert": cfg.GetPGCertPath() + "/tls.crt",
"sslmode": cfg.SSLMode,
}
settings.Options = options
}
Expand Down

0 comments on commit 5d67218

Please sign in to comment.