Browse Source

Postgres (CockroachDB) with full certificate verification (#7076)

* Postgres (CockroachDB) with full certificate verification

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* remove duplicated comments

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
pull/7077/head
Chris Lu 2 months ago
committed by GitHub
parent
commit
d49b44f2a4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 12
      weed/command/scaffold/filer.toml
  2. 18
      weed/filer/postgres/postgres_store.go
  3. 18
      weed/filer/postgres2/postgres2_store.go

12
weed/command/scaffold/filer.toml

@ -111,6 +111,12 @@ password = ""
database = "postgres" # create or use an existing database database = "postgres" # create or use an existing database
schema = "" schema = ""
sslmode = "disable" sslmode = "disable"
# SSL certificate options for secure connections
# For sslmode=verify-full, uncomment and configure the following:
# sslcert = "/path/to/client.crt" # client certificate file
# sslkey = "/path/to/client.key" # client private key file
# sslrootcert = "/path/to/ca.crt" # CA certificate file
# sslcrl = "/path/to/client.crl" # Certificate Revocation List (CRL) (optional)
connection_max_idle = 100 connection_max_idle = 100
connection_max_open = 100 connection_max_open = 100
connection_max_lifetime_seconds = 0 connection_max_lifetime_seconds = 0
@ -142,6 +148,12 @@ password = ""
database = "postgres" # create or use an existing database database = "postgres" # create or use an existing database
schema = "" schema = ""
sslmode = "disable" sslmode = "disable"
# SSL certificate options for secure connections
# For sslmode=verify-full, uncomment and configure the following:
# sslcert = "/path/to/client.crt" # client certificate file
# sslkey = "/path/to/client.key" # client private key file
# sslrootcert = "/path/to/ca.crt" # CA certificate file
# sslcrl = "/path/to/client.crl" # Certificate Revocation List (CRL) (optional)
connection_max_idle = 100 connection_max_idle = 100
connection_max_open = 100 connection_max_open = 100
connection_max_lifetime_seconds = 0 connection_max_lifetime_seconds = 0

18
weed/filer/postgres/postgres_store.go

@ -35,13 +35,17 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix
configuration.GetString(prefix+"database"), configuration.GetString(prefix+"database"),
configuration.GetString(prefix+"schema"), configuration.GetString(prefix+"schema"),
configuration.GetString(prefix+"sslmode"), configuration.GetString(prefix+"sslmode"),
configuration.GetString(prefix+"sslcert"),
configuration.GetString(prefix+"sslkey"),
configuration.GetString(prefix+"sslrootcert"),
configuration.GetString(prefix+"sslcrl"),
configuration.GetInt(prefix+"connection_max_idle"), configuration.GetInt(prefix+"connection_max_idle"),
configuration.GetInt(prefix+"connection_max_open"), configuration.GetInt(prefix+"connection_max_open"),
configuration.GetInt(prefix+"connection_max_lifetime_seconds"), configuration.GetInt(prefix+"connection_max_lifetime_seconds"),
) )
} }
func (store *PostgresStore) initialize(upsertQuery string, enableUpsert bool, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) {
func (store *PostgresStore) initialize(upsertQuery string, enableUpsert bool, user, password, hostname string, port int, database, schema, sslmode, sslcert, sslkey, sslrootcert, sslcrl string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) {
store.SupportBucketTable = false store.SupportBucketTable = false
if !enableUpsert { if !enableUpsert {
@ -63,6 +67,18 @@ func (store *PostgresStore) initialize(upsertQuery string, enableUpsert bool, us
if sslmode != "" { if sslmode != "" {
sqlUrl += " sslmode=" + sslmode sqlUrl += " sslmode=" + sslmode
} }
if sslcert != "" {
sqlUrl += " sslcert=" + sslcert
}
if sslkey != "" {
sqlUrl += " sslkey=" + sslkey
}
if sslrootcert != "" {
sqlUrl += " sslrootcert=" + sslrootcert
}
if sslcrl != "" {
sqlUrl += " sslcrl=" + sslcrl
}
if user != "" { if user != "" {
sqlUrl += " user=" + user sqlUrl += " user=" + user
} }

18
weed/filer/postgres2/postgres2_store.go

@ -40,13 +40,17 @@ func (store *PostgresStore2) Initialize(configuration util.Configuration, prefix
configuration.GetString(prefix+"database"), configuration.GetString(prefix+"database"),
configuration.GetString(prefix+"schema"), configuration.GetString(prefix+"schema"),
configuration.GetString(prefix+"sslmode"), configuration.GetString(prefix+"sslmode"),
configuration.GetString(prefix+"sslcert"),
configuration.GetString(prefix+"sslkey"),
configuration.GetString(prefix+"sslrootcert"),
configuration.GetString(prefix+"sslcrl"),
configuration.GetInt(prefix+"connection_max_idle"), configuration.GetInt(prefix+"connection_max_idle"),
configuration.GetInt(prefix+"connection_max_open"), configuration.GetInt(prefix+"connection_max_open"),
configuration.GetInt(prefix+"connection_max_lifetime_seconds"), configuration.GetInt(prefix+"connection_max_lifetime_seconds"),
) )
} }
func (store *PostgresStore2) initialize(createTable, upsertQuery string, enableUpsert bool, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) {
func (store *PostgresStore2) initialize(createTable, upsertQuery string, enableUpsert bool, user, password, hostname string, port int, database, schema, sslmode, sslcert, sslkey, sslrootcert, sslcrl string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) {
store.SupportBucketTable = true store.SupportBucketTable = true
if !enableUpsert { if !enableUpsert {
@ -68,6 +72,18 @@ func (store *PostgresStore2) initialize(createTable, upsertQuery string, enableU
if sslmode != "" { if sslmode != "" {
sqlUrl += " sslmode=" + sslmode sqlUrl += " sslmode=" + sslmode
} }
if sslcert != "" {
sqlUrl += " sslcert=" + sslcert
}
if sslkey != "" {
sqlUrl += " sslkey=" + sslkey
}
if sslrootcert != "" {
sqlUrl += " sslrootcert=" + sslrootcert
}
if sslcrl != "" {
sqlUrl += " sslcrl=" + sslcrl
}
if user != "" { if user != "" {
sqlUrl += " user=" + user sqlUrl += " user=" + user
} }

Loading…
Cancel
Save