-
Notifications
You must be signed in to change notification settings - Fork 98
fix: pause pools for passwordless users with passthrough auth #413
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
Open
Gunnarguy
wants to merge
1
commit into
pgdogdev:main
Choose a base branch
from
Gunnarguy:fix-passthrough-auth-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+95
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Test that passwordless users get their pools paused when passthrough auth is enabled | ||
| # This validates the specific feature added in the PR | ||
|
|
||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
| export PGPASSWORD=pgdog | ||
| export PGPORT=6432 | ||
| export PGHOST=127.0.0.1 | ||
|
|
||
| echo "🧪 Testing pool pausing for passwordless users with passthrough auth..." | ||
|
|
||
| # Kill any existing pgdog processes | ||
| killall -TERM pgdog 2> /dev/null || true | ||
| sleep 1 | ||
|
|
||
| # Start pgdog with passthrough auth enabled | ||
| echo "📦 Starting PgDog with passthrough auth enabled..." | ||
| ${SCRIPT_DIR}/../../../target/release/pgdog \ | ||
| --config ${SCRIPT_DIR}/pgdog-enabled.toml \ | ||
| --users ${SCRIPT_DIR}/users.toml & | ||
|
|
||
| PGDOG_PID=$! | ||
| sleep 2 | ||
|
|
||
| # Check if pgdog started successfully (this validates pools didn't get banned) | ||
| if ! kill -0 $PGDOG_PID 2>/dev/null; then | ||
| echo "❌ FAIL: PgDog process died (probably due to pool banning)" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "✅ PASS: PgDog started successfully without pool banning" | ||
|
|
||
| # Try to connect with the passwordless user (pgdog1) | ||
| # This should work because passthrough auth is enabled | ||
| echo "🔑 Testing connection with passwordless user..." | ||
| if psql -U pgdog1 pgdog -c 'SELECT 1 AS test_connection' > /dev/null 2>&1; then | ||
| echo "✅ PASS: Passwordless user can connect with passthrough auth" | ||
| else | ||
| echo "❌ FAIL: Passwordless user cannot connect" | ||
| kill $PGDOG_PID 2>/dev/null || true | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Clean up | ||
| kill $PGDOG_PID 2>/dev/null || true | ||
| sleep 1 | ||
|
|
||
| # Test that without passthrough auth, passwordless users are properly rejected | ||
| echo "🔒 Testing without passthrough auth (should reject passwordless user)..." | ||
| ${SCRIPT_DIR}/../../../target/release/pgdog \ | ||
| --config ${SCRIPT_DIR}/pgdog-disabled.toml \ | ||
| --users ${SCRIPT_DIR}/users.toml & | ||
|
|
||
| PGDOG_PID=$! | ||
| sleep 2 | ||
|
|
||
| # Check if pgdog started successfully | ||
| if ! kill -0 $PGDOG_PID 2>/dev/null; then | ||
| echo "❌ FAIL: PgDog process died when passthrough auth disabled" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Try to connect with passwordless user - this should fail | ||
| echo "🚫 Testing that passwordless user is rejected..." | ||
| if psql -U pgdog1 pgdog -c 'SELECT 1' > /dev/null 2>&1; then | ||
| echo "❌ FAIL: Passwordless user should not be able to connect when passthrough auth disabled" | ||
| kill $PGDOG_PID 2>/dev/null || true | ||
| exit 1 | ||
| else | ||
| echo "✅ PASS: Passwordless user properly rejected when passthrough auth disabled" | ||
| fi | ||
|
|
||
| # Clean up | ||
| kill $PGDOG_PID 2>/dev/null || true | ||
| sleep 1 | ||
|
|
||
| echo "🎉 All tests passed! Pool pausing feature is working correctly." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -425,12 +425,27 @@ pub(crate) fn new_pool( | |||||
| config.multi_tenant(), | ||||||
| ); | ||||||
|
|
||||||
| // Create cluster from the configuration | ||||||
| let cluster = Cluster::new(cluster_config); | ||||||
|
|
||||||
| // If passthrough auth is enabled and user has no password, pause the pools | ||||||
| // to prevent connection attempts with empty credentials | ||||||
| let is_admin = user.database == config.admin.name && user.name == config.admin.user; | ||||||
| if general.passthrough_auth() && user.password().is_empty() && !is_admin { | ||||||
|
||||||
| if general.passthrough_auth() && user.password().is_empty() && !is_admin { | |
| if general.passthrough_auth() && user.password().is_none() && !is_admin { |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using
killallcan affect other pgdog processes running on the system. Consider using a more targeted approach like storing the PID and killing specific processes, or using a unique process identifier.