-
Notifications
You must be signed in to change notification settings - Fork 219
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
add auth_query_database config #521
base: main
Are you sure you want to change the base?
add auth_query_database config #521
Conversation
Hey, cool PR. To run the specs locally, you can install Docker & docker-compose & run:
|
b64668a
to
c3e3b34
Compare
This commit adds the new config auth_query_database to allow use a different database to get the hashes from the database instance. I updated the example folder with functional code to validate the new feature and updated the config docs. Also updated ruby code to use the new env var LOG_LEVEL. Signed-off-by: Sebastian Webber <[email protected]>
c3e3b34
to
cdd03e7
Compare
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.
Everything looks good to me. Let me know if it's ready to merge.
hey @levkk still didn't have time to add more tests in the ruby code. =/ i did try to change the existing diff --git a/tests/ruby/auth_query_spec.rb b/tests/ruby/auth_query_spec.rb
index efa5ee5..532a82c 100644
--- a/tests/ruby/auth_query_spec.rb
+++ b/tests/ruby/auth_query_spec.rb
@@ -57,6 +57,24 @@ describe "Auth Query" do
)
end
+ context "with different lookup database" do
+ let(:config) {
+ { "general" => {
+ "auth_query" => "SELECT * FROM public.user_lookup2('$1');",
+ "auth_query_user" => "md5_auth_use2r",
+ "auth_query_password" => "secret",
+ "auth_query_database" => "lookup_db", ## doesn't exist yet
+ } }
+ }
+
+ it "it uses obtained passwords" do
+ connection_string = processes.pgcat.connection_string("sharded_db", pg_user["username"])
+ conn = PG.connect(connection_string)
+
+ expect(conn.exec("SELECT 1 + 2")).not_to be_nil
+ end
+ end
+
context "with correct global parameters" do
let(:config) { { "general" => { "auth_query" => "SELECT * FROM public.user_lookup('$1');", "auth_query_user" => "md5_auth_user", "auth_query_password" => "secret" } } }
context "and with cleartext passwords set" do
diff --git a/tests/ruby/helpers/auth_query_helper.rb b/tests/ruby/helpers/auth_query_helper.rb
index 60e8571..5b06131 100644
--- a/tests/ruby/helpers/auth_query_helper.rb
+++ b/tests/ruby/helpers/auth_query_helper.rb
@@ -1,3 +1,5 @@
+require "awesome_print"
+
module Helpers
module AuthQuery
def self.single_shard_auth_query(
@@ -44,7 +46,7 @@ module Helpers
pgcat_cfg["general"]["port"] = pgcat.port
pgcat.update_config(pgcat_cfg)
pgcat.start
-
+
pgcat.wait_until_ready(
pgcat.connection_string(
"sharded_db",
@@ -53,6 +55,7 @@ module Helpers
)
) if wait_until_ready
+ pp pgcat.current_config
OpenStruct.new.tap do |struct|
struct.pgcat = pgcat
struct.primary = primary
@@ -98,7 +101,7 @@ module Helpers
},
},
"users" => { "0" => user.merge(config_user) }
- }
+ }
end
# Main proxy configs
pgcat_cfg["pools"] = {
@@ -109,7 +112,6 @@ module Helpers
pgcat_cfg["general"]["port"] = pgcat.port
pgcat.update_config(pgcat_cfg.deep_merge(extra_conf))
pgcat.start
-
pgcat.wait_until_ready(pgcat.connection_string("sharded_db0", pg_user['username'], pg_user['password']))
OpenStruct.new.tap do |struct| Since the db doesn't exist, I'm expecting some errors but is saying that is ok:
I hope to have some time over the weekend to figure out what is wrong so I can add the missing tests and finish the PR. |
context 'when auth_query is configured' do | ||
context 'with global configuration' do | ||
context "when auth_query is configured" do | ||
context "with global configuration" do | ||
around(:example) do |example| | ||
|
||
# Set up auth query | ||
Helpers::AuthQuery.set_up_auth_query_for_user( |
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.
Do those methods actually reload pgcat?
Signed-off-by: Sebastian Webber <[email protected]>
7b9fa60
to
e41ed75
Compare
This PR adds the new config
auth_query_database
to allow a different database to get the hashes from the database instance. This is useful to avoid recreating the lookup function between all databases the pooler connects.I updated the example folder with functional code to validate the new feature and updated the config docs.
Can you guys give me some tips about running the ruby specs locally so I can add a new commit to test this change?