Skip to main content

Modeling Blocklists

note
Auth0 Fine Grained Authorization (FGA) is the early-stage product we are building at Auth0 to solve fine-grained authorization at scale. Sign up for the Developer Community Preview to try it out, and join our Discord community if you are interested in learning more about our plans.

Please note that at this point in time, it is not considered production-ready and does not come with any SLAs; availability and uptime are not guaranteed. Limitations of Auth0 FGA during the Developer Community Preview can be found here.

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

When to use

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 Auth0 FGA Concepts and know how to develop the things listed below.

You will start with the authorization model below, it represents a document type that can have users related 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).

type document
relations
define editor as self
type team
relations
define member as self

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

[
// Members of the product team can edit the planning document
{
"user": "team:product#member",
"relation": "editor",
"object": "document:planning",
},
// Becky is a member of the product team
{
"user": "becky",
"relation": "member",
"object": "team:product",
},
// Carl is a member of the product team
{
"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 →

Auth0 FGA Concepts

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

The Playground

Try this guide out on the Auth0 FGA Playground

Step by Step

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

We can verify that by issuing two check requests:

Initialize the SDK
// FGA_ENVIRONMENT can be "us" (default if not set) for Developer Community Preview or "playground" for the Playground API
// import the SDK
const { Auth0FgaApi } = require('@auth0/fga');

// Initialize the SDK
const fgaClient = new Auth0FgaApi({
environment: process.env.FGA_ENVIRONMENT,
storeId: process.env.FGA_STORE_ID,
clientId: process.env.FGA_CLIENT_ID,
clientSecret: process.env.FGA_CLIENT_SECRET,
});

// Run a check
const { allowed } = await fgaClient.check({
tuple_key: {
user: 'becky',
relation: 'editor',
object: 'document:planning',
},});

// allowed = true
Initialize the SDK
// FGA_ENVIRONMENT can be "us" (default if not set) for Developer Community Preview or "playground" for the Playground API
// import the SDK
const { Auth0FgaApi } = require('@auth0/fga');

// Initialize the SDK
const fgaClient = new Auth0FgaApi({
environment: process.env.FGA_ENVIRONMENT,
storeId: process.env.FGA_STORE_ID,
clientId: process.env.FGA_CLIENT_ID,
clientSecret: process.env.FGA_CLIENT_SECRET,
});

// Run a check
const { allowed } = await fgaClient.check({
tuple_key: {
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 relation to the document type.

The authorization model becomes this:

type document
relations
define blocked as self
define editor as self
type team
relations
define member as self

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:

type document
relations
define blocked as self
define editor as self but not blocked
type team
relations
define member as self

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 relationship tuple.

Initialize the SDK
// FGA_ENVIRONMENT can be "us" (default if not set) for Developer Community Preview or "playground" for the Playground API
// import the SDK
const { Auth0FgaApi } = require('@auth0/fga');

// Initialize the SDK
const fgaClient = new Auth0FgaApi({
environment: process.env.FGA_ENVIRONMENT,
storeId: process.env.FGA_STORE_ID,
clientId: process.env.FGA_CLIENT_ID,
clientSecret: process.env.FGA_CLIENT_SECRET,
});

await fgaClient.write({
writes: {
tuple_keys: [
// Carl is blocked from editing the planning document
{ 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.

Initialize the SDK
// FGA_ENVIRONMENT can be "us" (default if not set) for Developer Community Preview or "playground" for the Playground API
// import the SDK
const { Auth0FgaApi } = require('@auth0/fga');

// Initialize the SDK
const fgaClient = new Auth0FgaApi({
environment: process.env.FGA_ENVIRONMENT,
storeId: process.env.FGA_STORE_ID,
clientId: process.env.FGA_CLIENT_ID,
clientSecret: process.env.FGA_CLIENT_SECRET,
});

// Run a check
const { allowed } = await fgaClient.check({
tuple_key: {
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.

Initialize the SDK
// FGA_ENVIRONMENT can be "us" (default if not set) for Developer Community Preview or "playground" for the Playground API
// import the SDK
const { Auth0FgaApi } = require('@auth0/fga');

// Initialize the SDK
const fgaClient = new Auth0FgaApi({
environment: process.env.FGA_ENVIRONMENT,
storeId: process.env.FGA_STORE_ID,
clientId: process.env.FGA_CLIENT_ID,
clientSecret: process.env.FGA_CLIENT_SECRET,
});

// Run a check
const { allowed } = await fgaClient.check({
tuple_key: {
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 Auth0 Fine Grained Authorization (FGA) 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.

Modeling: Getting Started

Learn about how to get started with modeling.

Configuration Language

Learn about Auth0 FGA Configuration Language.

Public Access

Learn about model public access.

Have Feedback?

Join us on the Discord community if you have any questions or suggestions.