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

cleanup: Use projects instead of groups and orgs #1054

Merged
merged 1 commit into from
Oct 3, 2023
Merged

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Sep 29, 2023

This takes into use the concept of projects in Mediator, thus replacing our usage
of groups.

In the background, we also got rid of the organizations SQL table and use projects
underneath. Organizations are identifiable via a is_organization boolean in the table.

Projects and Organizations now use a UUID index.

The intent is to have this PR reimplement the existing functionality as to not break existing logic. This is just the start in an effort to support hierarchical structures and consolidate our authz strategy.

@JAORMX JAORMX changed the title cleanup: Use projects instead of groups and orgs WIP: cleanup: Use projects instead of groups and orgs Sep 29, 2023
@JAORMX JAORMX force-pushed the no-more-groups branch 2 times, most recently from e63aa9e to 3921687 Compare September 29, 2023 13:11
@evankanderson
Copy link
Member

I suspect we'll need an additional "OrgInfo" table for org-level metadata for things like billing, but I'm happy to use a star schema for that.

Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

I made it to internal/engine so far, most of my comments are small and/or can be deferred.

CREATE TABLE projects (
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
name TEXT NOT NULL,
metadata JSONB NOT NULL,
is_organization 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.

Rather than adding an is_organization which should be equivalent to parent_id IS NULL, let's put the organization information a separate table?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about adding a well known schema for this in the metadata?

Comment on lines +26 to +27
CREATE UNIQUE INDEX ON projects(name) WHERE parent_id IS NULL; -- if parent_id is null, then name must be unique
CREATE UNIQUE INDEX ON projects(parent_id, name) WHERE parent_id IS NOT NULL; -- if parent_id is not null, then name must be unique for that parent
Copy link
Member

Choose a reason for hiding this comment

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

Put these in the table definition as:

CREATE TABLE PROJECTS (
    -- Row definitions
    CONSTRAINT "unique name in parent" UNIQUE NULLS NOT DISTINCT (parent_id, name)
);


-- roles table
CREATE TABLE roles (
id SERIAL PRIMARY KEY,
organization_id INTEGER NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
group_id INTEGER REFERENCES groups(id) ON DELETE CASCADE,
organization_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
Copy link
Member

Choose a reason for hiding this comment

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

Do we need an organization ID for roles anymore?

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'll leave that here for now and we can move it off later. Trying to replicate what we already have.

@@ -60,7 +41,7 @@ CREATE TABLE roles (
-- users table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
organization_id INTEGER NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
organization_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe not for this PR, but I'm wondering if we want users to be associated with only one organization. I suspect not. But maybe we only shave one yak today.

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, I'm trying to keep the exact same functionality we have today with this new constructs. But I'd saynin the near future we should remove this restriction and allow users to belong to more than one org.

Comment on lines +55 to 60
-- user/projects
CREATE TABLE user_projects (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
group_id INTEGER NOT NULL REFERENCES groups(id) ON DELETE CASCADE
project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE
);
Copy link
Member

Choose a reason for hiding this comment

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

What is this supposed to be for? Should it also be referencing a role?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently this tracks users belonging to a group. I'm keeping the same functionality for now. In the near future we should remove this and rely on role assignments instead.

internal/controlplane/handlers_projects.go Outdated Show resolved Hide resolved
internal/controlplane/handlers_repositories.go Outdated Show resolved Hide resolved
internal/controlplane/handlers_repositories.go Outdated Show resolved Hide resolved
internal/controlplane/handlers_repositories.go Outdated Show resolved Hide resolved
internal/controlplane/handlers_repositories.go Outdated Show resolved Hide resolved
@JAORMX
Copy link
Contributor Author

JAORMX commented Sep 30, 2023

I suspect we'll need an additional "OrgInfo" table for org-level metadata for things like billing, but I'm happy to use a star schema for that.

We could do that. I was thinking instead of using the JSONB column to add company and billing info. We anyway will use another system for the actual billing so we would just have pointers to that external system anyway. Then the idea is to expose as little of the metadata to the user as possible. We might build a proprietary microservice to handle the billing metadata.

@JAORMX JAORMX force-pushed the no-more-groups branch 17 times, most recently from 240fb57 to 8812386 Compare October 2, 2023 12:35
Copy link
Contributor

@eleftherias eleftherias left a comment

Choose a reason for hiding this comment

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

Nice! I left one small comment about file names, so they don't accidentally slip through.

cmd/cli/app/project/group.go Outdated Show resolved Hide resolved
@JAORMX JAORMX force-pushed the no-more-groups branch 2 times, most recently from 16063e5 to 837f766 Compare October 2, 2023 14:33
Copy link
Member

@rdimitrov rdimitrov left a comment

Choose a reason for hiding this comment

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

I know it's still WIP, but it's nice to see this consistent 🚀 Try running git grep group to see other things that might have been missed, i.e. the rules type definitions, log messages and random variables are left to be updated 👍

internal/controlplane/handlers_organization.go Outdated Show resolved Hide resolved
IsProtected: true,
Description: fmt.Sprintf("Default admin group for %s", org.Name),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would admin group even exist still with 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.

it does, we're not changing the existing functionality yet. Just making the current logic work with he new structure. We'll start changing logic in subsequent PRs

@JAORMX JAORMX force-pushed the no-more-groups branch 2 times, most recently from dc6e952 to 279e470 Compare October 3, 2023 09:00
@JAORMX JAORMX changed the title WIP: cleanup: Use projects instead of groups and orgs cleanup: Use projects instead of groups and orgs Oct 3, 2023
eleftherias
eleftherias previously approved these changes Oct 3, 2023
eleftherias
eleftherias previously approved these changes Oct 3, 2023
This takes into use the concept of projects in Mediator, thus replacing our usage
of groups.

In the background, we also got rid of the organizations SQL table and use projects
underneath. Organizations are identifiable via a `is_organization` boolean in the table.

Projects and Organizations now use a UUID index.
@jhrozek
Copy link
Contributor

jhrozek commented Oct 3, 2023

I didn't fully review the code but I tried the PR as both admin and a non-admin user and all the tasks that I normally use in development worked fine.

@JAORMX JAORMX merged commit 545aea2 into main Oct 3, 2023
13 checks passed
@JAORMX JAORMX deleted the no-more-groups branch October 3, 2023 12:22
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.

6 participants