-
Notifications
You must be signed in to change notification settings - Fork 805
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
implement postgres support for TLS #3488
Conversation
if attrs != "" { | ||
dsn += "?" + attrs | ||
} | ||
return dsn | ||
} | ||
|
||
// TODO: implement postgres specific support for TLS |
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.
Should we remove the TODO? Or remove the method if it's not being used.
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.
We could. The only reason I kept it in, because I thought it to be an interface implementation.
Although I must say, I did a pass at temporal as well and the source files were slightly different, I might do another commit before going forward to synchronize the two directly, if that’s okay for you?
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.
Not quite follow exactly. Another commit for this? I thought this commit is working already. Or do you mean for other purpose.
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.
Sorry about the confusion, it does work, however I want to synchronize with https://github.com/temporalio/temporal/blob/master/common/persistence/sql/sqlplugin/postgres/plugin.go so I will do an additional commit tomorrow, before we go ahead with this one. I hope that makes sense.
Thank you for making this @nadilas for us! |
// Maps struct names in CamelCase to snake without need for db struct tags. | ||
db.MapperFunc(strcase.ToSnake) | ||
return db, nil | ||
dsn := fmt.Sprintf(dsnFmt, "postgresql", cfg.User, host, port, dbName) |
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.
Tests are failling. Seems like this is not compatible with pq server that without TSL enabled:
FAIL: TestSQLHistoryV2PersistenceSuite (0.00s) | 1s
-- | --
| panic: pq: SSL is not enabled on the server [recovered]
| panic: pq: SSL is not enabled on the server
|
| goroutine 10 [running]:
| testing.tRunner.func1(0xc000392300)
| /usr/local/go/src/testing/testing.go:874 +0x69f
| panic(0x2030fe0, 0xc0000b8880)
| /usr/local/go/src/runtime/panic.go:679 +0x1b2
| github.com/uber/cadence/common/persistence/sql.(*TestCluster).CreateDatabase(0xc0005a4840)
| /cadence/common/persistence/sql/sqlPersistenceTest.go:113 +0x2df
| github.com/uber/cadence/common/persistence/sql.(*TestCluster).SetupTestDatabase(0xc0005a4840)
| /cadence/common/persistence/sql/sqlPersistenceTest.go:74 +0x51
| github.com/uber/cadence/common/persistence/persistence-tests.(*TestBase).Setup(0xc0003c2658)
| /cadence/common/persistence/persistence-tests/persistenceTestBase.go:178 +0xdf
| github.com/uber/cadence/common/persistence/sql/sqlplugin/postgres.TestSQLHistoryV2PersistenceSuite(0xc000392300)
| /cadence/common/persistence/sql/sqlplugin/postgres/postgres_server_test.go:68 +0xed
| testing.tRunner(0xc000392300, 0x22e8f98)
| /usr/local/go/src/testing/testing.go:909 +0x19a
| created by testing.(*T).Run
| /usr/local/go/src/testing/testing.go:960 +0x652
| FAIL github.com/uber/cadence/common/persistence/sql/sqlplugin/postgres 0.041s
| FAIL
| make: *** [Makefile:196: cover_profile] Error 1
| ⚠️ Failed to run command, exited with 2
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.
I just made the necessary adjustments, can you please test again?
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.
Still not passing:
panic: pq: password authentication failed for user "postgres" [recovered]
--
| panic: pq: password authentication failed for user "postgres"
You can see it if you click the details
in
buildkite/cadence-server/pr/golang-unit-test — Failed (exit status 2)
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.
Are you able to run the test locally? That will be easier to debug and fix the test.
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.
yeah e2e tests
Sure since we have it in this repo. The reason we didn't do that is that we ran into timing issues with buildkite. But it should be fine since we are running tests in parallel now.
Unrelated to this, we might want to add the pg tests to buildkite, similar to what we do for MySQL. @longquanzheng what do you think? |
https://github.com/uber/cadence/blob/master/docker/buildkite/docker-compose.yml |
yeah e2e tests |
@nadilas unit tests are still failing. Can you check?
|
dataSourceNamePostgres = "user=%v host=%v port=%v dbname=%v sslmode=disable %v " | ||
dataSourceNamePostgresPassword = "password=%v" | ||
PluginName = "postgres" | ||
dsnFmt = "postgres://%s@%s:%s/%s" |
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.
Is the test failure because this is not compatible with basic authentication?
Thank you very much for making this PR. @nadilas Hey I added more document to https://github.com/uber/cadence/blob/master/CONTRIBUTING.md Or I can take this over, if it's too complex for you :P |
I’m sorry @longquanzheng Life happened, I got sidetracked by my day job 😅 But if you have it urgent feel free to step in. |
Oh thanks for the reply. It's not urgent at all. Feel free to slack me when you got stuck. It's not really easy thing to start development for Cadence project. We really love to have your contribution. |
@meiliang86 I just rebased the PR, can you help kick off the test? |
@nadilas looks like my rebase at Github UI doens't work, we need to do rebase manually so re-sync the go.mod. I don't have permission to push into your branch, could you rebase it? |
@longquanzheng I updated the branch, let's try this again :) |
It failed at :
Can you run
to re-format the code? |
common/persistence/sql/sqlplugin/postgres/postgres_server_test.go
Outdated
Show resolved
Hide resolved
…/plugin.go removes duplicate getTestClusterSetup() from postgres_server_test.go ran make fmt
@longquanzheng ready to rumble. |
Thanks @nadilas and @longquanzheng ! |
sslParams = url.Values{} | ||
if cfg.TLS != nil && cfg.TLS.Enabled { | ||
sslParams.Set("ssl", "true") | ||
sslParams.Set("sslmode", "require") |
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.
I know I'm late to the party, but is it wise to hard code this? How would I connect using the more secure modes verify-ca
or verify-full
for example?
Could as well let the user choose?
sslParams.Set("sslmode", cfg.TLS.SSLMode)
Just looking at the config it's hard to know what cfg.TLS.Enabled
means; is it allow
, prefer
, require
, verify-ca
or verify-full
? All of those modes are enabling TLS support to various degrees.
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.
Hey @JosefWN you are not late! Apparently I don't have enough expertise/experience about security so I didn't think too much about that.
Is value of sslmode
the only thing needed to change to support all other modes like you mention? If so then I could make a PR out for this.
Or it would be nice if you can make a PR for this. Because I am not sure how to test it.
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.
I think making the sslmode
configurable is sufficient (which would also make cfg.TLS.Enabled
redundant).
Perhaps something like this:
sslParams.Set("sslmode", cfg.SSLMode)
if cfg.SSLMode != "disable" && cfg.TLS != nil {
sslParams.Set("sslrootcert", cfg.TLS.CaFile)
sslParams.Set("sslkey", cfg.TLS.KeyFile)
sslParams.Set("sslcert", cfg.TLS.CertFile)
}
The default is prefer
, so it should be backwards compatible even if SSLMode
is not set (but would need to test that it actually works).
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.
Thanks a lot! PR out here: https://github.com/uber/cadence/pull/3787/files
But I think we have to make default as require now...since people started to use it. I believe it's okay, lmk if I am wrong.
TLS support implemented for postgres plugin
The changes were tested by deploying
cadence
andcadence_visibility
to a clean postgres database using TLS connection via thecadence-sql-tool
Potential risks
Backwards compatibility for password authentication to be tested by test-suite on a dev database instance