editor of a folder can also be an editor of all documents that folder is a parent of.
When to useObject-to-object relationships can combine with a configured authorization model to indicate that a user’s relationship with one object may influence the user’s relationship with another object. They can also eliminate the need to modify relationships between objects using user groups.The follow are examples of simple object-to-object relationships:
managersof anemployeehave access toapproverequests theemployeehas made- users who have a repository admin role (
repo_admin) in an organization automatically haveadminaccess to all repositories in that organization - users who are
subscribedto aplanget access to all thefeaturesin thatplan
Before you start
Familiarize yourself with basic OpenFGA Concepts: Assume that you have the following authorization model.You have two types:
folderthat users can be related to as aneditordocumentthat users can be related to as aneditor
Step by step
The following walkthrough models (a) folders that contain documents and (b) that a user who has editor access to a given folder has editor access to all documents in that folder. Foreditors of a folder to be editors of a containing document, you must:
- Update the authorization model to allow a
parentrelationship betweenfolderanddocument - Update the
editorrelation in thedocumenttype definition to support cascading fromfolder
bob is an editor of document:meeting_notes.doc because bob is an editor of folder:notes:
- Create a new relationship tuple to indicate that bob is a
editorof folder:notes - Create a new relationship tuple to indicate that folder:notes is a
parentof document:meeting_notes.doc - Check to see if bob is an
editorof document:meeting_notes.doc
01. Update the Authorization Model to allow a parent relationship between folder and document
As documented in Modeling Concepts: Object to Object Relationships, the following update to the authorization model allows aparent relation between a folder and a document:
The
document type now has a parent relation, indicating that other objects can be parents of documents02. Update the editor relation in the document type definition to support cascading from folder
To allow cascading relations betweenfolder and document, update the authorization model:
editor of a document can be the following:- users that are directly assigned as editors
- users that are related to any
parentof this document aseditor(editors of the parent)
folder that is a parent of a document as an editor is also an editor of that document.
03. Create a new relationship tuple to indicate that bob is an editor of folder:notes
To leverage the new cascading relation, create a relationship tuple stating that bob is an editor of folder:notes
04. Create a new relationship tuple to indicate that folder:notes is a parent of document:meeting_notes.doc
Now that bob is an editor of folder:notes, we need to indicate that folder:notes is a parent of document:meeting_notes.doc
05. Check if bob is an editor of document:meeting_notes.doc
After changing the authorization model and adding two new relationship tuples, verify that your configuration is correct by running the following check: is bob an editor of document:meeting_notes.doc.
Note: There are no other relationship tuples in the store that dictate a direct relation betweenThe chain of resolution is:bobanddocument:meeting_notes.doc. The check succeeds because of the cascading relation.
bobis aneditoroffolder:notesfolder:notesis aparentofdocument:meeting_notes.doceditorsof anyparentfolderofdocument:meeting_notes.docare alsoeditorsof thedocument- therefore
bobis aneditorofdocument:meeting_notes.doc
Related Sections
Check the following sections for more on how to model for parent and child objects.Modeling Concepts: Object to Object Relationships
Learn about how to model object to object relationships in OpenFGA.
Modeling Google Drive
See how to make folders parents of documents, and to make editors on the parent folders editors on documents inside them..
Modeling GitHub
See how to grant users access to all repositories owned by an organization.