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

Fix database user auto-provisioning #51945

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

GavinFrazar
Copy link
Contributor

@GavinFrazar GavinFrazar commented Feb 7, 2025

Changelog: Fixed Postgres database access control privileges auto-provisioning to grant USAGE on schemas as needed for table privileges and fixed an issue that prevented user privileges from being revoked at the end of their session in some cases.

Fixes #51681

Fixes #51851

This PR includes the following:

  • Use a custom query to find user db privileges on tables to avoid the "grantor" filter condition in the information_schema.tables_privileges view. This fixes the cases where the grantor for a privilege is set to the table owner rather than the user (teleport) who issued the grant. Most notably, this happens when a superuser grants privileges on a table they do not own to a user.
  • Grant USAGE on schemas that contain tables where we intend to grant table privileges. This is necessary to use the table privileges we grant.
  • Wrap all remaining plpgsql procedure creation/calls with retries.
  • Add a db permissions e2e test for RDS
  • Expand e2e tests to test with and without a superuser db admin
  • Significantly speed up the RDS e2e tests by wrapping EventuallyWithT in a helper func that tries the condition func immediately rather than waiting for the first tick duration.

I tested this quite a bit manually on RDS postgres and self-hosted, but still expanded the e2e tests just to be sure and to avoid regressions
I'm also hopeful that the additional retries I added will fix the Redshift flakiness.

Reviewers: sorry for the large diff in the e2e tests, but I noticed they were wasting quite a lot time after each subtest just waiting for 10 seconds before trying the post-connection test fn.

@GavinFrazar GavinFrazar added aws Used for AWS Related Issues. database-access Database access related issues and PRs db/postgres PostgreSQL related database access issues backport/branch/v15 backport/branch/v16 backport/branch/v17 labels Feb 7, 2025
@GavinFrazar GavinFrazar force-pushed the gavinfrazar/fix-db-auto-user-bugs branch 2 times, most recently from 9789f5f to 925e216 Compare February 7, 2025 08:07
@GavinFrazar GavinFrazar marked this pull request as ready for review February 7, 2025 18:24
@github-actions github-actions bot requested a review from avatus February 7, 2025 18:25
lib/srv/db/postgres/sql/update-permissions.sql Outdated Show resolved Hide resolved
e2e/aws/rds_test.go Show resolved Hide resolved
e2e/aws/rds_test.go Show resolved Hide resolved
e2e/aws/rds_test.go Show resolved Hide resolved
@greedy52
Copy link
Contributor

greedy52 commented Feb 7, 2025

🙏 thanks for all the effort you've put into investigating this!!!

Copy link
Contributor

@Tener Tener left a comment

Choose a reason for hiding this comment

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

Just minor things.

@GavinFrazar GavinFrazar added this pull request to the merge queue Feb 12, 2025
@GavinFrazar GavinFrazar removed this pull request from the merge queue due to a manual request Feb 12, 2025
* Use a custom query to find user db privileges on tables to avoid the
  "grantor" filter condition in the information_schema.tables_privileges
  view. This fixes the cases where the grantor for a privilege is set to
  the table owner rather than the user (teleport) who issued the grant.
  Most notably, this happens when a superuser grants privileges on a
  table they do not own to a user.
* Grant USAGE on schemas that contain tables where we intend to grant
  table privileges. This is necessary to use the table privileges we
  grant.
* Wrap all remaining plpgsql procedure creation/calls with retries.
* Add a db permissions e2e test for RDS
* Expand e2e tests to test with and without a superuser db admin
* Significantly speed up the RDS e2e tests by wrapping EventuallyWithT
  in a helper func that tries the condition func immediately rather than
  waiting for the first tick duration.
@GavinFrazar GavinFrazar force-pushed the gavinfrazar/fix-db-auto-user-bugs branch from 59671e1 to 19bbc25 Compare February 12, 2025 01:54
@GavinFrazar GavinFrazar added this pull request to the merge queue Feb 12, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 12, 2025
@GavinFrazar GavinFrazar added this pull request to the merge queue Feb 12, 2025
Merged via the queue into master with commit 0bcabee Feb 12, 2025
43 checks passed
@GavinFrazar GavinFrazar deleted the gavinfrazar/fix-db-auto-user-bugs branch February 12, 2025 03:11
@public-teleport-github-review-bot

@GavinFrazar See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Failed
branch/v17 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Used for AWS Related Issues. backport/branch/v15 backport/branch/v16 backport/branch/v17 database-access Database access related issues and PRs db/postgres PostgreSQL related database access issues size/md
Projects
None yet
4 participants