Skip to content

Latest commit

 

History

History
326 lines (264 loc) · 11.6 KB

blocklists.mdx

File metadata and controls

326 lines (264 loc) · 11.6 KB
sidebar_position slug description
8
/modeling/blocklists
Preventing certain users from accessing objects

import { AuthzModelSnippetViewer, CardBox, CheckRequestViewer, DocumentationNotice, Playground, ProductConcept, ProductName, ProductNameFormat, RelatedSection, RelationshipTuplesViewer, WriteRequestViewer, } from '@components/Docs';

Blocklists

In this guide you'll see how to model preventing users from accessing objects using . For example, blocking users from accessing a document, even if it has been already shared with them.

Exclusion is useful while building applications. You may need to support access patterns like granting access to some users, but excluding specific people or groups, similar to how users can block others from following them on social media, or prevent them from sharing documents on Google Drive.

This is useful when:

  • Implementing the "blocking" feature, such as the profile blocking commonly present on social media platforms (e.g. Instagram and Twitter).
  • Reduce a user's access if they are part of a particular group (e.g. restricting access to members who are also guests, or restricting access to users in a certain locality).

Before You Start

Before you start this guide, make sure you're familiar with some and know how to develop the things listed below.

You will start with the below, it represents a document that can have users as editor, and team type that can have users related as member.

Let us also assume that we have a document called "planning", shared for editing within the product team (comprised of becky and carl).

<AuthzModelSnippetViewer configuration={{ schema_version: '1.1', type_definitions: [ { type: 'user', }, { type: 'document', relations: { editor: { this: {}, }, }, metadata: { relations: { editor: { directly_related_user_types: [{ type: 'user' }, { type: 'team', relation: 'member' }] }, }, }, }, { type: 'team', relations: { member: { this: {}, }, }, metadata: { relations: { member: { directly_related_user_types: [{ type: 'user' }] }, }, }, }, ], }} />

The current state of the system is represented by the following relationship tuples being in the system already:

<RelationshipTuplesViewer relationshipTuples={[ { _description: 'Members of the product team can edit the planning document', user: 'team:product#member', relation: 'editor', object: 'document:planning', }, { _description: 'Becky is a member of the product team', user: 'user:becky', relation: 'member', object: 'team:product', }, { _description: 'Carl is a member of the product team', user: 'user:carl', relation: 'member', object: 'team:product', }, ]} />


In addition, you will need to know the following:

Modeling User Groups

You need to know how to add users to groups and grant groups access to resources. Learn more →

Concepts

  • A : a class of objects that have similar characteristics
  • A : an entity in the system that can be related to an object
  • A : is a string defined in the type definition of an authorization model that defines the possibility of a relationship between an object of the same type as the type definition and a user in the system
  • An : represents an entity in the system. Users' relationships to it can be define through relationship tuples and the authorization model
  • A : a grouping consisting of a user, a relation and an object stored in
  • Exclusion Operator: the exclusion operator can be used to exclude certain usersets from being related to an object

Step By Step

With the above authorization model and relationship tuples, will correctly respond with {"allowed":true} when is called to see if Carl and Becky can edit this document.

We can verify that by issuing two check requests:

<CheckRequestViewer user={'user:becky'} relation={'editor'} object={'document:planning'} allowed={true} />

<CheckRequestViewer user={'user:carl'} relation={'editor'} object={'document:planning'} allowed={true} />

We want to share a document with the product team and also have the ability to deny certain users access, even if they have the document shared with them already. We can verify this by blocking Carl (who we have seen already has edit access) from editing the document.

In order to do that, we need to:

  1. Modify our model to allow indicating that users can be blocked from accessing a document
  2. Modify our model to indicate that users who are blocked can no longer edit the document
  3. Verify that our solution works:

a. Indicate that Carl is blocked from the planning document

b. Carl (now blocked) can no longer edit the document

c. Becky still has edit access

01. Modify Our Model So Users Can Be Blocked From Accessing A Document

To allow users to be "blocked" from accessing a document, we first need to allow this relation. We'll update our store model to add a blocked to the document type.

The authorization model becomes this:

<AuthzModelSnippetViewer configuration={{ schema_version: '1.1', type_definitions: [ { type: 'user', }, { type: 'document', relations: { blocked: { this: {}, }, editor: { this: {}, }, }, metadata: { relations: { blocked: { directly_related_user_types: [{ type: 'user' }] }, editor: { directly_related_user_types: [{ type: 'user' }, { type: 'team', relation: 'member' }] }, }, }, }, { type: 'team', relations: { member: { this: {}, }, }, metadata: { relations: { member: { directly_related_user_types: [{ type: 'user' }] }, }, }, }, ], }} />

Now we can add relationship tuples indicating that a certain user is blocked from editing a document.

02. Modify Our Model So Users Who Are Blocked Can No Longer Edit The Document

Now that we can mark users as blocked from editing documents, we need to support denying the editor relationship when a user is blocked. We do that by modifying the relation definition of editor, and making use of the the exclusion operator to exclude the set of blocked users, as we can see here:

<AuthzModelSnippetViewer configuration={{ schema_version: '1.1', type_definitions: [ { type: 'user', }, { type: 'document', relations: { blocked: { this: {}, }, editor: { difference: { base: { this: {}, }, subtract: { computedUserset: { relation: 'blocked', }, }, }, }, }, metadata: { relations: { blocked: { directly_related_user_types: [{ type: 'user' }] }, editor: { directly_related_user_types: [{ type: 'user' }, { type: 'team', relation: 'member' }] }, }, }, }, { type: 'team', relations: { member: { this: {}, }, }, metadata: { relations: { member: { directly_related_user_types: [{ type: 'user' }] }, }, }, }, ], }} />

03. Verify Our Solution Works

To check if our new model works, we'll add a relationship tuple with Carl as blocked from document:planning and then verify that Carl no longer has editor access to that document.

a. Indicate That Carl Is Blocked From The Planning Document

With our modified authorization model, we can indicate that Carl is blocked by adding this .

<WriteRequestViewer relationshipTuples={[ { _description: 'Carl is blocked from editing the planning document', user: 'user:carl', relation: 'blocked', object: 'document:planning', }, ]} />

b. Carl (now blocked) Can No Longer Edit The Document

We have modified the authorization model and added relationship tuples to indicate that Carl is blocked. Now let's make sure our solution works as expected.

To check if Carl still has access to the document, we can issue a check request with Carl as the user.

<CheckRequestViewer user={'user:carl'} relation={'editor'} object={'document:planning'} allowed={false} />

The response is false, so our solution is working as expected.

c. Becky Still Has Edit Access

To check if Becky still has access to the document, we'll issue another check request with Becky as the user.

<CheckRequestViewer user={'user:becky'} relation={'editor'} object={'document:planning'} allowed={true} />

The response is true, indicating our model change did not inadvertently deny access for users who have access but are not blocked.

:::caution Note: When creating tuples for make sure to use unique ids for each object and user within your application domain. We are using first names and human-readable identifiers to make this task easier to read. :::

Related Sections

<RelatedSection description="Check the following sections for more on how to model with {ProductName}." relatedLinks={[ { title: 'Modeling: Getting Started', description: 'Learn about how to get started with modeling.', link: './getting-started', id: './getting-started', }, { title: 'Modeling Language', description: 'Learn about {ProductName} Modeling Language.', link: '../modeling-language', id: '../modeling-language', }, { title: 'Public Access', description: 'Learn about model public access.', link: './public-access', id: './public-access', }, ]} />