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

Set default table privileges in first migration #188

Merged
merged 20 commits into from
Aug 18, 2023
Merged

Conversation

lorenyu
Copy link
Contributor

@lorenyu lorenyu commented Aug 11, 2023

Ticket

Resolves #186

Changes

  • Add first migration that alters default table privileges for migrator user to grant table privileges to app user
  • Combine two subsequent migrations into one file to simplify the template
  • Make CI checks run in parallel to improve visibility into what actually failed
  • Use docker compose v2

Context for reviewers

These migration changes don't follow the append-only practice of writing migrations, but since this is a template rather than an active project, I think that makes sense so that we can keep the project's initial setup clean.

Testing

Ran make db-recreate then make db-upgrade and make db-downgrade-all manually locally

Also this should be covered by CI since we have a test-migrations test

def upgrade():
# Change default privileges for future tables created by the `migrator`
# user to automatically be accessible by the `app` user.
op.execute("ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO app")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to add more rules than just tables?

When I set this up for local development on my project, I did this for each schema, borrowing some of it from our PFML project:

  • REVOKE ALL ON SCHEMA PUBLIC FROM PUBLIC"
  • GRANT USAGE ON SCHEMA {schema_name} TO {role}; (I think this is automatic for the public schema)
  • ALTER DEFAULT PRIVILEGES IN SCHEMA {schema_name} GRANT ALL ON TABLES TO {role};
  • ALTER DEFAULT PRIVILEGES IN SCHEMA {schema_name} GRANT ALL ON SEQUENCES TO {role};
  • ALTER DEFAULT PRIVILEGES IN SCHEMA {schema_name} GRANT ALL ON ROUTINES TO {role};

Sequences and routines are a bit less necessary, but threw them in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah those are all great. The idea I had was to do as much as possible in the infra template, so the first two items (1) REVOKE ALL ON SCHEMA public FROM public and (2) GRANT USAGE ON SCHEMA {schema_name} TO {role} are going to be done in template-infra. (2) is already done and (1) is captured by this ticket.

I'm fine adding SEQUENCES and ROUTINES to this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok added

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm - just thinking of a developer in the future looking at this (or at the piece in the infra), I'd wonder why those two are split into two separate places. Could you add a comment here explaining that? And maybe add to that other ticket to update the comment to link to that bit of code so a developer can see the full picture?

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 point, added a comment and updated the ticket.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chouinar no rush but lemme know if you're good with the latest changes

@lorenyu lorenyu requested a review from chouinar August 16, 2023 14:55
Copy link
Contributor

@chouinar chouinar left a comment

Choose a reason for hiding this comment

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

LGTM!

@lorenyu lorenyu merged commit d3b2f28 into main Aug 18, 2023
@lorenyu lorenyu deleted the lorenyu/tableprivileges branch August 18, 2023 19:30
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.

Fix table permissions by adding initial migration that sets default permissions
2 participants