Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now in beta. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. |
Role
Learn: Roles |
---|
We recommend you use FSL to create and update user-defined roles. See FSL role schema. |
Fauna uses secrets for authentication and authorization. Roles determine a secret’s privileges, which control data access.
Role
collection
Fauna stores user-defined roles as documents in the Role
system collection.
These documents are an FQL version of the FSL
role schema.
Role
documents have the following FQL structure:
{
name: "customer",
coll: Role,
ts: Time("2099-07-31T12:37:05.280Z"),
privileges: [
{
resource: "Product",
actions: {
read: true
}
},
{
resource: "Order",
actions: {
read: "(ref) => Query.identity() == ref.customer"
}
},
{
resource: "Customer",
actions: {
read: "(ref) => Query.identity() == ref"
}
},
{
resource: "getOrCreateCart",
actions: {
call: "(id) => Query.identity()?.id == id"
}
},
{
resource: "checkout",
actions: {
call: "(name) => true"
}
}
],
membership: [
{
resource: "Customer"
},
{
resource: "Manager",
predicate: "(user) => user.accessLevel == \"manager\""
}
],
data: {
desc: "End user customer role"
}
}
Field name | Value type | Read-only | Required | Description |
---|---|---|---|---|
|
true |
Unique name for the role in the database. Must begin with a letter. Can only include letters, numbers, and underscores.
|
||
|
true |
Collection name: |
||
|
true |
Last time the document was created or updated. |
||
|
Array of privilege objects. Each object allows one or more actions on a resource. See Privilege definition. |
|||
|
Array of membership objects. Each object assigns the role to tokens based on the token’s identity document. See Membership definition. |
|||
|
|
Arbitrary user-defined metadata for the document. |
Privilege definition
The privileges
field accepts an array of privilege objects.
Privilege objects have the following schema:
Field name | Value type | Description |
---|---|---|
|
Name of a collection or user-defined function (UDF). Supports user-defined collections and the following system collections:
|
|
|
Types of operations allowed on the resource. Each key in the object in an action. Privileges support different actions based
on the Each key’s value is Privilege predicates are passed different arguments based on their action. See Privilege predicate arguments. |
Privilege actions
Privileges support different actions based on their resource type.
Resource type | Action | Allows you to … |
---|---|---|
Collection |
|
Create documents in the collection. To create documents with a custom
|
Collection |
|
Delete documents in the collection. |
Collection |
|
Read documents in the collection. Can also
call the collection’s indexes. To read
historical document snapshots, you must also have the |
Collection |
|
Update or replace documents in the collection. |
Collection |
|
Create documents with a custom |
Collection |
|
Read snapshots for documents in the collection. See Run a temporal query. |
User-defined function (UDF) |
|
Call the function. |
Privilege predicate arguments
Privilege predicates are passed different arguments based on their action.
Action | Predicate function signature |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
Membership definition
The membership
field accepts an array of privilege objects.
Privilege objects have the following schema:
Field name | Value type | Description |
---|---|---|
|
Name of a user-defined collection. Fauna assigns the role to tokens with an identity document in the collection. |
|
|
Predicate used to conditionally
assign the role. If the predicate is not The predicate is passed one argument: an object containing the token’s identity document. The predicate runs with the built-in |
Static methods
You can use the following static methods to manage the Role
collection in FQL.
Method | Description |
---|---|
Get a Set of all user-defined roles. |
|
Get a user-defined role by its name. |
|
Create a user-defined role. |
|
Get the first user-defined role matching a provided predicate. |
|
Get |
|
Get a Set of user-defined roles that match a provided predicate. |
Instance methods
You can use the following instance methods to manage specific Role
documents in FQL.
Method | Description |
---|---|
Delete a user-defined role. |
|
Test if a user-defined role exists. |
|
Replace a user-defined role. |
|
Update a user-defined role. |
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!