Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add template RBAC #4125

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

Closed
wants to merge 41 commits into from
Closed

feat: add template RBAC #4125

wants to merge 41 commits into from

Conversation

sreya
Copy link
Collaborator

@sreya sreya commented Sep 19, 2022

No description provided.

@@ -0,0 +1,12 @@
BEGIN;

ALTER TABLE templates ADD COLUMN user_acl jsonb NOT NULL default '{}';
Copy link
Member

Choose a reason for hiding this comment

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

Why store this as a massive jsonb blob instead of a table? How do we plan on efficiently getting a list of all templates the user has access to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's basically the same way everything else is done. You get a list of all the templates and then you filter it through the auth filter for the subset of templates that you have access to. Just wrote a test for this here

Copy link
Member

Choose a reason for hiding this comment

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

For workspaces, it kinda does this, but we still query by the owner so it's lessened significantly.

I guess the use-case I have in mind is 10 templates with 10 users on each... for every HTTP request we'll load 100 entries into memory and check against them? That sounds like a lot of excess when we could (I don't see why not, but maybe there's a reason) have a table that just has the user ID indexed...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The memory overhead is unfortunate but this way plays better with rego is the short answer. We can look into rewriting it if you think it's a showstopper, I'm not sold on jsonb but joining tables doesn't play well with sqlc either so the maintainability of the code might suffer as a result of trying to glue everything together.

@sreya sreya requested a review from Emyrk September 20, 2022 04:33
@sreya sreya marked this pull request as ready for review September 20, 2022 15:52
@sreya sreya requested a review from a team as a code owner September 20, 2022 15:52
@sreya sreya requested review from Kira-Pilot and removed request for a team and Kira-Pilot September 20, 2022 15:52
@bpmct
Copy link
Member

bpmct commented Sep 20, 2022

Is the frontend going to be in a separate PR?

@sreya
Copy link
Collaborator Author

sreya commented Sep 20, 2022

@bpmct no @BrunoQuaresma is going to push it here

BEGIN;

ALTER TABLE templates ADD COLUMN user_acl jsonb NOT NULL default '{}';
ALTER TABLE templates ADD COLUMN is_private boolean NOT NULL default 'false';
Copy link
Member

Choose a reason for hiding this comment

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

is_ isn't necessary here

TemplateRoleAdmin TemplateRole = "admin"
TemplateRoleWrite TemplateRole = "write"
TemplateRoleRead TemplateRole = "read"
TemplateRoleDeleted TemplateRole = ""
Copy link
Member

Choose a reason for hiding this comment

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

Deleted should be Delete in this name pattern

Comment on lines +35 to +40
UPDATE
templates
SET
user_acl = $2
WHERE
id = $1`
Copy link
Member

Choose a reason for hiding this comment

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

Why can't this be done with sqlc instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because it exposes a json.RawMessage through the API. I wanted to preserve type safety as much as possible since we can't enforce the jsonb structure in the DB

}

func (q *sqlQuerier) GetTemplateUserRoles(ctx context.Context, id uuid.UUID) ([]TemplateUser, error) {
const query = `
Copy link
Member

Choose a reason for hiding this comment

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

I'm not convinced we should escape sqlc here... this function is only used once, so why not just do the struct conversion where it's queried from instead?

Copy link
Collaborator Author

@sreya sreya Sep 20, 2022

Choose a reason for hiding this comment

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

there's unfortunately multiple problems when I tried to write this with sqlc. One is that it didn't recognize the intermediate value column in the subquery. When I tried to jank around that the resulting return type was wildly different than what I tried to express 😞

@sreya sreya closed this Sep 28, 2022
@Emyrk Emyrk deleted the resource_acl_list branch February 3, 2023 19:00
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.

5 participants