Enabling multi-tenancy in Dgraph Cloud
In order to enable multi-tenancy you need to do the following --
Enable ACL
- If you are launching a dedicated cluster for the first time, you need to
click the checkbox for ACLs under
Additional Settings
. - For existing dedicated cluster, you need to go to Settings > Modify Backend
and click the checkbox for ACLs under
Additional Settings
. Note - This restarts your backend hence causing some downtime.
- If you are launching a dedicated cluster for the first time, you need to
click the checkbox for ACLs under
-
Create namespaces
- Go to
Namespaces
page underAdmin
section on the sidebar to the left. - Click on
Create New
button, enter the description of the namespace and clickCreate
. - You can view the created namespaces on the
Namespaces
page. - Please note that Tenant 0 can’t be deleted.
- Go to
-
Toggle namespaces
- Now you should be able to see a select box next to selected backend in the top navigation.
- You can switch between namespaces with the selection.
- Also, each namespace has its own Schema, ACLs & Lambdas. Also has its own view of Dgraph Studio, API Explorer, DQL Page.
- After switching namespaces, you can update view/update the namespace’s
schema and query/mutate as well.
Accessing namespaces via client
Namespaces are protected via ACLs. You need to create a user with username & password in the namespace. This can be done usingACLs
page under Admin
section on the sidebar to the left.
In the following example, we show how to give all read access to a user for
namespace:
-
First, you should create an ACL group and select all predicates that you want
to provision read access.
-
Next, create a user with access to the created group. While creating the
user, you are asked to provide with a username & password. Keep it handy.
-
You can go to the API Explorer and user the login mutation to fetch the API
access token. Click on admin radio button at the top to query the admin
endpoint. Use the mutation shown below to get the access token. (Note -
NamespaceID can be found on the namespace page)
-
You have the access token which you need to pass it in
X-Dgraph-AccessToken
header. - On client side you need to use this mutation to programmatically generate the access token for your namespace.
- If you are using a Dgraph client you need to set the username & password and the client handles fetching the token & refresh logic for you. Most of the clients have a special method to login to a specific namespace.