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

Make more sslmode available for postgresql connection (Fixes #925) #927

Merged
merged 4 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 7 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/signal"
"sort"
"strconv"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -127,8 +128,12 @@ func NewHeadscale(cfg *Config) (*Headscale, error) {
cfg.DBuser,
)

if !cfg.DBssl {
dbString += " sslmode=disable"
if s, err := strconv.ParseBool(cfg.DBssl); err == nil {
if !s {
dbString += " sslmode=disable"
}
OrvilleQ marked this conversation as resolved.
Show resolved Hide resolved
} else {
dbString += fmt.Sprintf(" sslmode=%s", cfg.DBssl)
}

if cfg.DBport != 0 {
Expand Down
2 changes: 2 additions & 0 deletions config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ db_path: ./db.sqlite

# # Postgres config
# If using a Unix socket to connect to Postgres, set the socket path in the 'host' field and leave 'port' blank.
# Also if other 'sslmode' is required instead of 'require(true)' and 'disabled(false)', set the 'sslmode' you need
# in the 'db_ssl' field. Refers to https://www.postgresql.org/docs/current/libpq-ssl.html Table 34.1.
OrvilleQ marked this conversation as resolved.
Show resolved Hide resolved
# db_type: postgres
# db_host: localhost
# db_port: 5432
Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Config struct {
DBname string
DBuser string
DBpass string
DBssl bool
DBssl string

TLS TLSConfig

Expand Down Expand Up @@ -545,7 +545,7 @@ func GetHeadscaleConfig() (*Config, error) {
DBname: viper.GetString("db_name"),
DBuser: viper.GetString("db_user"),
DBpass: viper.GetString("db_pass"),
DBssl: viper.GetBool("db_ssl"),
DBssl: viper.GetString("db_ssl"),

TLS: GetTLSConfig(),

Expand Down