-
Notifications
You must be signed in to change notification settings - Fork 505
fix: preserve sslmode when serializing connection config in ToPostgresURL #5958
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,9 @@ func toPostgresURL(config pgconn.Config, userinfo *url.Userinfo) string { | |
| timeoutSecond = 10 | ||
| } | ||
| queryParams := fmt.Sprintf("connect_timeout=%d", timeoutSecond) | ||
| if _, ok := config.RuntimeParams["sslmode"]; !ok { | ||
| queryParams += fmt.Sprintf("&sslmode=%s", getSSLMode(config)) | ||
| } | ||
| for k, v := range config.RuntimeParams { | ||
| queryParams += fmt.Sprintf("&%s=%s", k, url.QueryEscape(v)) | ||
| } | ||
|
|
@@ -61,6 +64,26 @@ func toPostgresURL(config pgconn.Config, userinfo *url.Userinfo) string { | |
| ) | ||
| } | ||
|
|
||
| func getSSLMode(config pgconn.Config) string { | ||
| if mode, ok := config.RuntimeParams["sslmode"]; ok { | ||
| return mode | ||
| } | ||
| if config.TLSConfig == nil { | ||
| if len(config.Fallbacks) > 0 && config.Fallbacks[0].TLSConfig != nil { | ||
| return "allow" | ||
| } | ||
| return "disable" | ||
|
Comment on lines
+71
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Many remote configs are constructed directly rather than by Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Severity: MEDIUM
💡 Fix SuggestionSuggestion: The root cause is that The correct fix is in |
||
| } | ||
| if len(config.Fallbacks) > 0 && config.Fallbacks[0].TLSConfig == nil { | ||
| return "prefer" | ||
| } | ||
| if !config.TLSConfig.InsecureSkipVerify { | ||
| return "verify-full" | ||
| } | ||
| return "require" | ||
|
Comment on lines
+80
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an input Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
|
|
||
| var ErrPrimaryNotFound = errors.New("primary database not found") | ||
|
|
||
| func GetPoolerConfigPrimary(ctx context.Context, ref string) (api.SupavisorConfigResponse, error) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever this serialized URL is passed to
GetRootCA, it now already contains ansslmode, butisRequireSSLstill appends another&sslmode=requireininternal/gen/types/types.go. pgconn reads the first value for duplicate URL parameters, so a deriveddisableorpreferremains effective; against a plaintext-only database the probe can connect without TLS and incorrectly report that TLS is required, causing downstream pg-meta/pg-delta setup to receive CA/TLS configuration for a server that does not support it. The probe should replace the query parameter rather than append a duplicate.Useful? React with 👍 / 👎.