Context
A small web application with REST API and postgres as db, that has users, documents and teams. A user can do basic CRUD operations on document.
A user is always a part of a team. A team is generated on user signup. A team has at least one member and zero or more documents.
Policy model
CREATE TABLE IF NOT EXISTS policy ( id UUID UNIQUE NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY, namespace VARCHAR(64) NOT NULL, subject UUID NOT NULL, scope VARCHAR(64) NOT NULL, object UUID NOT NULL, created_at TIMESTAMP WITH TIME ZONE NOT NULL, UNIQUE (namespace, subject, scope, object) ); Example
| id | namespace | subject | scope | object | | policy-uuid | "user" | user-uuid | "CreateDocument" | team-uuid | -> User can create document in team-uuid | policy-uuid | "user" | user-uuid | "CreateTeam" | app-uuid | -> User can create team in app-uuid instance | policy-uuid | "user" | user-uuid | "FindDocument" | document-uuid | -> User can find document-uuid (search) | policy-uuid | "user" | user-uuid | "DeleteDocument" | document-uuid | -> User can delete document-uuid | policy-uuid | "user" | user-uuid | "FindUser" | user-uuid | -> User can find user-uuid (search) | policy-uuid | "user" | user1-uuid | "UpdateUser" | user2-uuid | -> User1 (admin) can update User2's info | policy-uuid | "document" | document1-uuid | "LinkDocument" | document2-uuid | -> Document1 can link to Document2 Checking
So a function new_team() will check if (user.uuid, "CreateTeam", app-uuid) is present in policy table and update_doc(doc: Document) will check (user.uuid, "UpdateDocument", doc.uuid).
Ignore namespace. It's an application level identifier, not used for checking policy.
Question
Are there any obvious pitfalls I haven't considered? And if so, is there a better way of modeling these kinds of policies?
jsonbfields.