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

bug-fixing: PostgreSQL failed to check if the server wasn't turn on the SSL #286

Merged
merged 2 commits into from
Feb 10, 2023

Conversation

haoel
Copy link
Contributor

@haoel haoel commented Feb 10, 2023

close #285

How to Reproduce

disable the SSL in prostgresql.conf by commenting on the following configuration

#ssl = on
 #ssl_ca_file = '/path/to/certs/ca.crt'
 #ssl_cert_file = '/path/to/certs/server.crt'
 #ssl_key_file = '/path/to/certs/server.key'

EaseProbe config.yaml

client:
  - name: PostgreSQL Native Client (local)
    driver: "postgres"
    host: "localhost:5432"
    username: user
    password: password

Fix

if TLS in the client is not configured, we need to configure it with a nil

@@ -62,8 +62,9 @@ func New(opt conf.Options) (*PostgreSQL, error) {
                return nil, fmt.Errorf("TLS Config Error - %v", err)
        } else if tls != nil {
                tls.InsecureSkipVerify = true
-               clientOptions = append(clientOptions, pgdriver.WithTLSConfig(tls))
        }
+       // if the tls is nil which means `sslmode=disable`
+       clientOptions = append(clientOptions, pgdriver.WithTLSConfig(tls))

Note
The other code change just move the code from the Probe() to ProbeWithPing() and ProbeWithDataChecking(), no code logics changes.

@codecov-commenter
Copy link

codecov-commenter commented Feb 10, 2023

Codecov Report

Base: 99.67% // Head: 99.67% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (9cfa69b) compared to base (24d863a).
Patch coverage: 100.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #286   +/-   ##
=======================================
  Coverage   99.67%   99.67%           
=======================================
  Files          82       82           
  Lines        5488     5503   +15     
=======================================
+ Hits         5470     5485   +15     
  Misses         12       12           
  Partials        6        6           
Impacted Files Coverage Δ
probe/client/postgres/postgres.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

return false, fmt.Sprintf("Query error - [%s], %v", v, err)
}
if !rows.Next() {
rows.Close()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need call db.Close() in error cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put the code in for loop into functionverifyData(), and use the defer db.Close() and defer rows.Close() inside.

Please review it again

@haoel haoel merged commit 7026081 into megaease:main Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Native Postgresql connection without ssl enabled
5 participants