This examnple explores the authorizazation model for a cloud-based sharing system.
For more information about exploring this example using the Cedar CLI, see Cedar Example Use Cases.
Envision a cloud-based document sharing system, like Google Drive or Dropbox. This system can be used by a single user who is working on documents across multiple computers, by multiple users who are collaborating on a shared set of documents, or by the public as a hosting solution. Users need to be able to upload, delete, and modify the sharing permissions on their documents. Users also need to be able to view, comment on, and modify documents that they have access to. The system enforces correct access control logic. Since this is a multi-tenant system, it must have a mechanism to protect against cross-user abuse. This system includes a blocklist feature to accomplish this.
Users are the main principals of the system. They are the ones who view/edit/delete documents, as well as the ones who control sharing permissions on documents. They may also block other users. For instance, if Alice blocks Bob, then Bob should not be able to view any documents Alice owns or share anything with Alice.
For convenience, users can be organized into groups. Documents can be shared with entire groups at once. We’ll borrow from Unix and say that every user also has a group containing only them.
A principal that represents an unauthenticated user.
Documents are the core resource of the system. Every document has an owner, which is the user who created it. Documents have 3 methods of sharing
- Private: only the owner can view/edit/comment/delete the document
- Access-control List (ACL): List of users/groups that are allowed view, groups allowed to comment, groups allowed to edit, groups allowed to manage.
- Public: The public can view/edit/comment on the document.
It is always enforced that only the owner can delete or edit the sharing state of a document.
Create a new document in the system. Any authenticated user can do this.
Users must be on the ACL for the document.
Only the owner of the document can do this.
Users must be on the ACL for the document.
Users must be on the ACL for the document.
Only the owner of the document can do this.
Users who have manage access can do this. The owner can never have their access be revoked.
Anyone who has edit access can do this.
Any authenticated user can do this.
Only the owner of the document can do this.
Only the owner of the document can do this.
Whether or not the request is from an authenticated user
DocumentShare- A group-entity. All children of this entity are
groups that are allowed to perform some action on a document.
- A group-entity. All children of this entity are
User- attributes
personalGroupaGroup, links to the group containing exactly this userblockeda set ofUserentities.
- memberOfTypes:
Group, can be a member of any group. - Invariants:
- for any
Useru,u in u.personalGroupshould always be true- as well as
u == u.personalGroup.owner
- as well as
- for any
- attributes
Group- attributes:
owner: aUser
- memberOfTypes:
DocumentShare
- attributes:
Document- attributes:
owner: aUserisPrivate: a booleanpublicAccess: a string, one of:none,view, oreditviewACLaDocumentSharemodifyACLaDocumentSharemanageACLaDocumentShare
- attributes:
Public- There is exactly one instance of
publicthat represents the un-authenticated user. - memberOfTypes:
DocumentShare
- There is exactly one instance of
Drive- A “container entity” that represents the entire application.
CreateDocument: Create a new document in the system. Any authenticated user can do this.- principals:
User - resources:
Drive
- principals:
ViewDocument: Users must be on the ACL for the document.- principals:
User - resources:
Document
- principals:
DeleteDocument: Only the owner of the document can do this.- principals:
User - resources:
Document
- principals:
ModifyDocument: Users must be on the ACL for the document.- principals:
User - resources:
Document
- principals:
EditIsPrivate: Only the owner of the document can do this.- principals:
User - resources:
Document
- principals:
AddToShareACL: Users who have manage access can do this. The owner can never have their access be revoked.- principals:
User - resources:
Document
- principals:
EditPublicAccess: Anyone who has edit access can do this.- principals:
User - resources:
Document
- principals:
CreateGroup: Any authenticated user can do this.- principals:
User - resources:
Drive
- principals:
ModifyGroup: Only the owner of the document can do this.- principals:
User - resources:
Group
- principals:
DeleteGroup: Only the owner of the document can do this.- principals:
User - resources:
Group
- principals:
is_authenticated- Attributes:
- type: a boolean
- Attributes:
permit (
principal,
action == Action::"CreateDocument",
resource == Drive::"drive"
);
The owner should always be able to view the document.
permit (
principal,
action == Action::"ViewDocument",
resource
)
when { principal == resource.owner };
Anyone who is in the view ACL should be able to view the document, when it’s not private
permit (
principal,
action == Action::"ViewDocument",
resource
)
when { principal in resource.viewACL }
unless { resource.isPrivate };
An un-authenticated principal can view only when explicitly permitted
permit (
principal == Public::"public",
action == Action::"ViewDocument",
resource
)
when { resource.publicAccess == "view" || resource.publicAccess == "edit" }
unless { resource.isPrivate };
Simiarly, only the owner can do this
permit (
principal,
action == Action::"deleteDocument",
resource
)
when { principal == resource.owner };
Very similar to viewing, just different ACL:
permit (
principal,
action == Action::"ModifyDocument",
resource
)
when { principal == resource.owner };
permit (
principal,
action == Action::"ModifyDocument",
resource
)
when { principal in resource.modifyACL }
unless { resource.isPrivate };
permit (
principal == Public::"public",
action == Action::"ViewDocument",
resource
)
when { resource.publicAccess == "edit" }
unless { resource.isPrivate };
permit (
principal,
action in
[Action::"EditIsPrivate",
Action::"AddToShareACL",
Action::"EditPublicAccess"],
resource
)
when { principal == resource.owner };
permit (
principal,
action in [Action::"AddToShareACL", Action::"EditPublicAccess"],
resource
)
when { principal in resource.manageACL };
permit (
principal,
action == Action::"CreateGroup",
resource == Drive::"drive"
);
permit (
principal,
action in [Action::"ModifyGroup", Action::"DeleteGroup"],
resource
)
when { principal == resource.owner };
If you’ve blocked someone, they can’t see any of your documents and you can’t see any of theirs.
Note: We need a constraint principal has blocked for this policy to pass validation because Action::"ViewDocument" applies to either User or Public whereas the blocked list only contains User entities. This constraint rules out the scenario where principal is a Public.
forbid (
principal,
action in
[Action::"ViewDocument",
Action::"ModifyDocument",
Action::"EditIsPrivate",
Action::"AddToShareACL",
Action::"EditPublicAccess",
Action::"DeleteDocument"],
resource
)
when
{
principal has blocked &&
(resource.owner.blocked.contains(principal) ||
principal.blocked.contains(resource.owner))
};
This forbid policy is a guard rail. We could enforce it at runtime, or prove that the other policies implement it:
forbid (principal, action, resource)
when
{
resource has owner &&
principal != resource.owner &&
resource has isPrivate &&
resource.isPrivate
};
This forbid policy requires that requests contain a valid authentication context:
forbid (
principal,
action,
resource
)
when { !context.is_authenticated };
We use the following entities for our tests, included in the entities.json file:
- There are 3
Userentities,User::"alice",User::"bob",User::"charlie".- Alice is a member of the
alice_personaluser group and has blocked Bob. - Bob is a member of the
bob_personaluser group. - Charlie is a member of the
charlie_personaluser group.
- Alice is a member of the
- There are 3
UserGroupentities,alice_personal,bob_personal, andcharlie_personal. - There is 1
Driveentity,Drive::"drive". - There is 1
DocumentShareentity,alice_public_view. Bothbob_personalandcharlie_personalare children of this entity.
Note:alice_personaldoesn't need to be a child of this because Alice owns the documents she creates by default. - There is 1
Documententity,alice_public.
Here are some authz requests to test, included in the ALLOW and DENY folders:
- Alice tries to create a document in drive: ALLOW because she is authenticated.
- Alice tries to view alice_public: ALLOW because she owns the document.
- Charlie tries to view alice_public: ALLOW because
charlie_personalis inalice_public_view. - Alice tries to create a document in drive: DENY because she is not authenticated.
- Bob tries to view alice_public: DENY because, even though
bob_personalis inalice_public_view, Alice has blocked him.