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

Prevent Segfault when connecting to non-existent DB with Scram Authentication #730

Merged
merged 7 commits into from
Aug 11, 2022

Conversation

mbsabath
Copy link
Contributor

We were seeing segfaults occur when using scram authentication to connect to non-existent databases. Looks like the issue arises when attempting to save the Scram authentication keys. This PR adds a check that the DB isn't fake before attempting to save the credentials

Copy link
Member

@JelteF JelteF left a comment

Choose a reason for hiding this comment

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

Code looks good. I left some comments on the tests.

Also CI is failing on Windows. I'm not sure why, but various tests are being skipped on windows. I think we could do the same for the offending test, which seems to be: test_no_database_md5_auth_success

Adding this line at the top of the test should skip it on windows:

case `uname` in MINGW*) return 77;; esac

PS. Alpine is also failing, but that's expected because of: #722

test/test.sh Outdated
}

test_no_database_md5_auth_success() {
# Testing what happens on successful SCRAM auth connection to non-existent DB
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Testing what happens on successful SCRAM auth connection to non-existent DB
# Testing what happens on successful MD5 auth connection to non-existent DB

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fun times with lazy and copy and pasting

# Testing what happens on successful SCRAM auth connection to non-existent DB
# Segfaults have been seen after mock authentication was put in place

admin "set auth_type='md5'"
Copy link
Member

Choose a reason for hiding this comment

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

After testing, it seems that md5 was used here on purpose to trigger the bug. Using scram-256 as auth_type doesn't crash. Would be good to add this detail to the comment above.

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 reran the tests using the current master branch of pgbouncer and saw the segfault occur when auth_type was set to scram or md5 with a scram PW. I've added more detail about the source of the bug to the tests though

# Testing what happens on successful SCRAM auth connection to non-existent DB
# Segfaults have been seen after mock authentication was put in place

admin "set auth_type='md5'"
Copy link
Member

Choose a reason for hiding this comment

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

This test didn't fail before. I agree that it makes sense for completeness, but maybe swap the auth_type here too (so use scram-256 instead of md5). Or add all 4 different combinations:

  1. scramuser1 + md5
  2. scramuser1 + scram-256
  3. muser1 + md5
  4. muser1 + scram-256

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. Added all combinations here except for muser1 + scram since that failed authentication (as its supposed to).

@mbsabath
Copy link
Contributor Author

mbsabath commented Jul 2, 2022

Thanks @JelteF for the review! I missed some conditions when I set up those tests so hopefully things will no longer hang on the Windows tests.

@JelteF JelteF merged commit 060e6f1 into pgbouncer:master Aug 11, 2022
NguyenHoangPhuTien pushed a commit to julofinance/pgbouncer that referenced this pull request Nov 25, 2022
…tication (pgbouncer#730)

It was possible to get segfaults when using scram authentication while connecting
to non-existent databases. Looks like the issue arises when attempting to save the
Scram authentication keys. This PR adds a check that the DB isn't fake before 
attempting to save the credentials

Co-authored-by: Ben Sabath <mbsabath@Bens-MacBook-Pro.local>
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.

2 participants