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

RLS Policies #132

Merged
merged 1 commit into from
May 29, 2024
Merged

RLS Policies #132

merged 1 commit into from
May 29, 2024

Conversation

bplunkett-stripe
Copy link
Collaborator

@bplunkett-stripe bplunkett-stripe commented May 28, 2024

Description

  • Add support for RLS Policies
  • RLS policies cannot be added to individual partitions yet, but they can be put on the parent table (I want to refactor the code a bit)

Little status update: Bit of a hiatus due to other priorities. Before adding more features to schema diffing, I'd like to clean up the tests and code a bit.

cc @sweatybridge

Motivation

Fixes #111

Testing

Tested via unit tests

@bplunkett-stripe bplunkett-stripe force-pushed the bplunkett/rls-policies branch 2 times, most recently from 49771b3 to e13edf1 Compare May 28, 2024 01:29
@bplunkett-stripe bplunkett-stripe added the enhancement New feature or request label May 28, 2024
@bplunkett-stripe bplunkett-stripe force-pushed the bplunkett/rls-policies branch 2 times, most recently from 31e22e7 to c75e3c3 Compare May 28, 2024 01:43
Copy link
Collaborator

@alexaub-stripe alexaub-stripe left a comment

Choose a reason for hiding this comment

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

Some thoughts, but nothing blocking. Supporting RLS is super impressive!

also thank goodness for acceptance tests...

Comment on lines +47 to +48
// roles is a list of roles that should be created before the DDL is applied
roles []string
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: I wonder if we should make it possible to define roles in schema somehow. Since they're global I figure that would erode the "you're only applying a single schema" paradigm we have, but it feels like a shame that roles have to be defined outside of pg-schema-diff.

// ResetInstance attempts to reset the cluster to a clean state.
// It deletes all cluster level objects, i.e., roles, which are not deleted
// by dropping database(s). This can be useful for re-using a cluster for multiple tests.
func ResetInstance(ctx context.Context, db *sql.DB) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: Shouldn't this also drop databases? As is it feels like this is implemented specifically for how it's used in the AT suite.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We actually have the AT's drop the database. This is more design cluster-scope values. I could totally see databases considered cluster-scope though... Right now, we will just keep the individual AT's dropping their own databases, since if they fail to do that, it indicates a bug.

Comment on lines +231 to +232
// Weirdly, you can't actually drop a "USING EXPRESSION" clause from an ALL policy even though you
// can have an ALL policy with only a check expression.
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't there be an ErrNotImplemented somewhere to cover this case?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah i see that's handled by if diff.old isn't mutated to match diff.new

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep. That's the "canonical" pattern I'm going for. It makes "ErrNotImplemented" free for any feature we inherently haven't explicitly coded support for.

return nil, fmt.Errorf("getting target columns: %w", err)
}

// Run after the new columns are added/altered
Copy link
Collaborator

Choose a reason for hiding this comment

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

Policies on partitions must be dropped before the base table is altered, otherwise the SQL could fail because, e.g., the policy references a column that no longer exists.

Is this quirk from above covered by the column dependencies?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah maybe it's handled by how the policy generator is called by the table generator?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is a quirk covered by the column dependencies. It's also the same reason we can't easily support partition-level RLS policies yet

@bplunkett-stripe bplunkett-stripe merged commit 045fd2c into main May 29, 2024
6 checks passed
@bplunkett-stripe bplunkett-stripe deleted the bplunkett/rls-policies branch May 29, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Row security policies
2 participants