Vertex-Level Access Control (Beta)
Vertex-level Access Control (VLAC) allows database administrators to control data access on the vertex level by attaching tags to individual vertices on a graph (the base graph) and creating tag-based graphs. Tag-based graphs share the underlying data with the base graph but have their own sets of roles and privileges, which allows administrators to exercise fine-grained data access control without the vertex type boundary.
Figure 1 below illustrates two tag-based graphs built upon a base graph. The base graph contains vertices of person type, and vertices of post type. Two tags (A and B) are used to tag them. For example, vertex 1 and vertex 9 both have tag A. Vertex 3 and vertex 11 both have tag A and B. A tag-based graph named tagA will only present to its users those base graph vertices that have tag A (the bottom-left graph). The other tag-based graph named tagB will only present to its users those base graph vertices that have tag B (the bottom-right graph).
Figure 1. Tag-based graphs as subgraphs of a Base graph
For users operating on a tag-based graph, tags are an invisible aspect that silently filters how they load and query data. A tag-based graph defines its view, and all data outside its view is invisible to it.

Prerequisites

Sufficient privileges on the base graph or on the global scope are required to perform the steps described on this page.
  • ACCESS_TAG
    • Any operation involving tags
  • WRITE_SCHEMA
    • Create/run schema change jobs
    • Create tag-based graphs
  • READ_DATA, WRITE_DATA
    • Run queries that modify the graph
  • WRITE_LOADINGJOB, EXECUTE_LOADINGJOB
    • Create/run loading jobs

Workflow - Using Vertex Level Access Control

Below is the basic workflow on using the VLAC to control data access for a database administrator:

1. Create a tag-based graph

2. Manage users of the tag-based graph

  • Grant built-in roles to users on a tag-based graph
  • Define roles and grant them to users on a tag-based graph

3. Load and tag data

There are three main options for tagging vertices.
  1. 1.
    Explicitly add/modify tags on existing data: A user with the privilege ACCESS_TAG and WRITE_DATA privileges on the base graph can create and run a DML query that sets tags on selected individual vertices.
  2. 2.
    Explicitly set tags when loading data into to a base graph: A user with EXECUTE_LOADINGJOB , WRITE_LOADINGJOB and ACCESS_TAG privileges on the base graph can create and run a loading job that explicitly sets tags on the newly loaded base graph vertices.
  3. 3.
    Implicitly set tags when loading into a tag-based graph: A user with tag-based graph loading or insert privilege (e.g., a designer or querywriter) can create an ordinary loading or upsert job which inserts new vertices. The new vertices will be automatically tagged according to the tag-based graph's schema definition.

4. Query and update Data

Users with data read and write privileges (e.g., the querywriter and queryreader built-in roles) can query and update the tag-based graph as they would do any other graph. The data filtering for querying or data tagging for insertion is applied automatically.
The rest of this tutorial will first describe tag management: creating and dropping tags, making vertex type taggable, and using tags to define tag-based graphs. Next, the three ways to tag vertices are described and illustrated. We summarize the privilege scheme of tag-based graphs in terms of GSQL's predefined roles. Finally, we give some use cases that can be solved by VLAC.
Features not yet supported:
  • DDL tag operations can only be done in GSQL. They are not yet supported in GraphStudio. This includes create/drop tags, create/alter vertices that are taggable, define a tag-based graph.
  • The privilege control for DDL operations (only admin and designer users should be able to explicitly manage tags) is not fully functional.
In summary, all necessary operations to set up VLAC graphs and users are supported in GSQL. Due to a known bug, standard users (with querywriter and queryreader roles) can run some DDL operations which they should not be able to.
We’ll use the graph socialNet as an example in the following sections.

Tag Management

A tag is a special attribute of a vertex, which appears as a string for input and output purposes. If a vertex type is declared to be taggable, then each vertex of that type can have one or more tags. The maximum number of different tags in a global graph is 64. All operations involving tags requires the user to have the ACCESS_TAG privilege.

Define a tag

A tag name has to be defined via ADD TAG before it can be used. Each base graph defines its own set of tags. However, there is a global maximum number of different tags, currently set at 64.
Syntax for ADD TAG
1
ADD TAG <tag_name> [DESCRIPTION <tag_description>]
Copied!
ADD TAG can only be used inside a SCHEMA_CHANGE JOB. An example is below:
1
USE GRAPH socialNet
2
3
CREATE SCHEMA_CHANGE JOB add_tags {
4
ADD TAG public DESCRIPTION "Open for public";
5
ADD TAG tech DESCRIPTION "All about technology";
6
ADD TAG vip DESCRIPTION "Very Important Person";
7
ADD TAG dummy DESCRIPTION "Yeah, just a dummy";
8
}
9
RUN SCHEMA_CHANGE JOB add_tags
Copied!

List tags

Run ls to see a list of defined tags:
1
...
2
3
Tags:
4
- TAG public DESCRIPTION "Open for public"
5
- TAG tech DESCRIPTION "All about technology"
6
- TAG vip DESCRIPTION "Very Important Person"
7
- TAG dummy DESCRIPTION "Yeah, just a dummy"
Copied!

Drop a tag

The DROP TAG command not only removes the given tag(s) from the catalog of available tags, but also deletes them from each vertex to which it is attached. You can drop multiple tags in one statement.
Syntax for DROP TAG
1
DROP TAG <tag_name> ["," <tag_name>]*
Copied!
Like ADD TAG, DROP TAG also needs to be inside a SCHEMA_CHANGE JOB:
1
USE GRAPH socialNet
2
3
CREATE SCHEMA_CHANGE JOB drop_dummy_tag {
4
DROP TAG dummy;
5
}
6
RUN SCHEMA_CHANGE JOB drop_dummy_tag
Copied!
  1. 1.
    You cannot drop a tag if it is used in the definition of a tag-based graph. You must drop the graph first.
  2. 2.
    When DROP TAG is executed, the specified tags will be made invalid, and then the foreground process will complete. A background process will continue to run to remove the tags from all data. In the meantime, each dropped tag still takes up one of the 64 slots for tags. The slot(s) will become available once the background process finishes.

Create a tag-based graph

A tag-based graph is a filtered view of a base graph, where a base graph is a simple collection of vertex types and edge types, without any tag specifiers. A tag-based graph must include at least one taggable vertex type from the base graph.

Mark vertex types as taggable

A vertex type has to be taggable to accept tags. TAGGABLE is a boolean property of a vertex type that can be set with CREATE VERTEX initially or with ALTER VERTEX in a schema change job:
1
USE GRAPH socialNet
2
3
# in general, this would be a local schema change job, but in socialNet, the
4
# vertex types are global, so this needs to be a global schema change job
5
CREATE GLOBAL SCHEMA_CHANGE JOB make_taggable {
6
ALTER VERTEX person WITH TAGGABLE="true";
7
ALTER VERTEX post WITH TAGGABLE="true";
8
}
9
10
RUN GLOBAL SCHEMA_CHANGE JOB make_taggable
Copied!
The property TAGGABLE is false by default. To change this default, use the WITH clause below when creating a vertex type:
1
CREATE VERTEX v2(PRIMARY_ID id UINT, name STRING) WITH TAGGABLE="true"
Copied!
  1. 1.
    To change a vertex type from taggable to untaggable, use WITH TAGGABLE="false".
  2. 2.
    You cannot make a vertex type untaggable if it is used in the definition of a tag-based graph.
  3. 3.
    Edge types are never tagged. See the next section to see how we determine which edges to include in the tag-based graph.

Create a Tag-Based Graph

After a tag set and taggable vertex types have been created, we can use the tags to define a tag-based graph. For each vertex type we want to include, we may also specify a tag expression which must be satisfied for an individual vertex to be included.
Examples
Here is an example of creating a tag-based graph from the base graph socialNet.
1
USE GRAPH socialNet
2
CREATE GRAPH vipNet AS socialNet(person:vip, post, friend, posted, liked)
Copied!
The interpretation is "Starting from the socialNet graph, create a tag-based graph called vipNet which includes person vertices which are tagged 'vip'. Also include all post vertices and all friend, posted and liked edges."
Edges do not have tag expressions. An edge will be included when both of its vertex endpoints are included (and its edge type is included in the tag graph schema).
To describe a combination of tags, use the & operator to combine the tags:
1
USE GRAPH socialNet
2
CREATE GRAPH mixedNet AS socialNet(person:public&vip, post:public&tech&dummy, friend, posted, liked)
Copied!
The graph mixedNet will only include the person vertices having both the public and viptags, and posts having all three of the public , tech and dummy tags.
Same tag for all vertex types
If the desired tag-based graph is "anything in the base graph that has these tags", there is a convenient shortcut:
1
USE GRAPH socialNet
2
CREATE GRAPH publicNet2 AS socialNet:public
Copied!
is the same as
1
USE GRAPH socialNet
2
CREATE GRAPH publicNet1 AS socialNet(person:public, post:public, friend, posted, liked)
Copied!
General Syntax
The formal syntax for both the general form and the simplified form of creating a tag-based graph is shown below:
Syntax for CREATE GRAPH for a tag-based graph
1
<create_tag_graph> :=
2
CREATE GRAPH <tag_graph_name> AS <base_graph_name>
3
( "(" <tagged_element_name> ("," <tagged_element_name>)* ")" | ":" <tag_expr> )
4
5
<tagged_element_name> := <tagged_vertex_name> | <edge_name>
6
7
<tagged_vertex_name> := <vertex_name> [":" <tag_expr>]
8
9
<tag_expr> := <tag> ("&" <tag_expr>)*
Copied!

How To Tag Vertices

There are three main options for tagging vertices in the base graph.
  • Add tags on existing data with DML queries. For existing data, a user with base graph tagging privilege (e.g., an admin or designer) can create and run a DML query that sets tags on selected individual vertices.
  • Explicitly set tags when loading/inserting to a base graph. For new data, a user with base graph loading and tagging privilege (e.g., an admin or designer) can create and run a loading job that explicitly sets tags on the newly loaded vertices.
  • Implicitly set tags when loading/inserting into a tag-based graph. For new data, a user with tag-based graph loading or insert privilege (e.g., a designer or querywriter) can create an ordinary Loading or Upsert Job which inserts new vertices. The new vertices will be automatically tagged according to the tag-based graph's schema definition.

Add tags on existing data

In GSQL, special vertex methods are provided to access and modify the tags of a vertex in a DML query (full list available on page Vertex Functions). These functions are only available for vertex aliases (defined in the FROM clause of a SELECT statement); they cannot be applied to vertex variables in other contexts.
There are 8 DML-level tag-access functions in the vertex-query block or edge-query block. Use the v.addTags() function to tag a vertex.

Required privilege

READ_DATA, WRITE_DATA, WRITE_QUERY , ACCESS_TAG
To add or modify tags, you should work at the base graph level.
Examples
addTags() is shown below. This query will add tags to person vertices to achieve the same effect as a base graph loading job example in the previous section.
1
CREATE QUERY addTagsToPerson() {
2
Seed = { any };
3
# person1 ~ person5 will be tagged as public.
4
vSet = SELECT s
5
FROM Seed:s
6
WHERE s.id IN ("person1","person2","person3","person4","person5")
7
ACCUM s.addTags("public");
8
9
# person6 and person7 will be tagged as public and vip.
10
vSet = SELECT s
11
FROM Seed:s
12
WHERE s.id IN ("person6","person7")
13
ACCUM s.addTags("vip", "public");
14
15
# person8 will be tagged as vip
16
vSet = SELECT s
17
FROM Seed:s
18
WHERE s.id == "person8"
19
ACCUM s.addTags("vip");
20
}
Copied!
Use removeTags() and removeAllTags() to remove tags from vertices:
1
// remove tagvipandpublicfrom all person vertices.
2
CREATE QUERY removetagsFromPerson() {
3
vSet = { person.* };
4
# remove tag vip and public from all person vertices
5
vSet = SELECT s
6
FROM vSet:s
7
ACCUM s.removeTags("vip", "public");
8
}
9
10
// remove all tags from all person vertices.
11
CREATE QUERY removealltagsFromPerson() {
12
vSet = { person.* };
13
# remove all tags from all person vertices
14
vSet = SELECT s
15
FROM vSet:s
16
ACCUM s.removeAllTags();
17
}
Copied!

Set tags explicitly with TAGS clause

Tags can be added to vertices at their loading time using a base graph loading job.
The LOAD statement has an optional clause for explicit tagging of loaded data. The tagging clause has two keywords, TAGS and BY:
  • TAGS(<tag_list>) specifies the tags to be set.
  • BY specifies how to merge tags if the targeted vertex exists in the graph
    • BY OR:Add the given tags to the existing set of tags.
    • BY OVERWRITE: Replace the existing tags with the given ones.

Required privilege

WRITE_LOADINGJOB , EXECUTE_LOADINGJOB, ACCESS_TAG
Example 1
Suppose we want to put the tags vip and public on the person vertex data coming from a certain file. We have three files: persons1, persons2, persons3.
1
$ cat persons1
2
person1,Male
3
person2,Female
4
person3,Male
5
person4,Female
6
person5,Female
7
8
$ cat persons2
9
person6,Male
10
person7,Male
11
12
$ cat persons3
13
id,gender,label
14
person8,Male,vip
Copied!
Create and run three loading jobs:
1
USE GRAPH socialNet
2
3
# person1 - person5 will be tagged as public.
4
CREATE LOADING JOB loadPersonPublic {
5
DEFINE filename f;
6
LOAD f TO VERTEX person VALUES($0, $0, $1) TAGS("public") BY OR;
7
}
8
RUN LOADING JOB loadPersonPublic USING f="./persons1"
9
10
# person6 and person7 will be tagged as public and vip.
11
CREATE LOADING JOB loadPersonPublicVip {
12
DEFINE filename f;
13
LOAD f TO VERTEX person VALUES($0, $0, $1) TAGS("public", "vip") BY OR;
14
}
15
RUN LOADING JOB loadPersonPublicVip USING f="./persons2"
16
17
# person8 will be tagged as vip which is derived from the file.
18
CREATE LOADING JOB loadPerson {
19
DEFINE filename f;
20
LOAD f TO VERTEX person VALUES($0, $0, $1) TAGS($2) BY OR USING HEADER="true";
21
}
22
RUN LOADING JOB loadPerson USING f="./persons3"
Copied!
Note that the TAGS clause can specify a tag with a string literal ("vip") so every vertex gets the same tag, or with a token reference by position ($2) or by name (quot;label") from the source file, so each vertex gets a data-dependent tag. If the tag clause refers to a non-existent tag, the loading job will still run, but the data will not be loaded at runtime. The loading job log will report these non-loaded vertices.
Example 2
We have three post files: posts1, posts2, and posts3.
1
$ cat posts1
2
3,cats,2011-02-05 01:02:44
3
8,cats,2011-02-03 17:05:52
4
9,cats,2011-02-05 23:12:42
5
10,cats,2011-02-04 03:02:31
6
11,cats,2011-02-03 01:02:21
7
8
$ cat posts2
9
4,coffee,2011-02-07 05:02:51
10
11
$ cat posts3
12
0,Graphs,2010-01-12 11:22:05
13
1,tigergraph,2011-03-03 23:02:00
14
2,query languages,2011-02-03 01:02:42
15
5,tigergraph,2011-02-06 01:02:02
16
6,tigergraph,2011-02-05 02:02:05
17
7,Graphs,2011-02-04 17:02:41
Copied!
We create and run the following loading jobs:
1
USE GRAPH socialNet
2
3
# posts 3, 8, 9, 10, and 11 will be tagged as public.
4
CREATE LOADING JOB loadPostPublic {
5
DEFINE filename f;
6
LOAD f TO VERTEX post VALUES($0, $1, $2) TAGS("public") BY OR ;
7
}
8
RUN LOADING JOB loadPostPublic USING f="./posts1"
9
10
# posts 0, 1, 2, 5, 6, and 7 will be tagged as both public and tech.
11
CREATE LOADING JOB loadPostPublicTech {
12
DEFINE filename f;
13
LOAD f TO VERTEX post VALUES($0, $1, $2) TAGS("public", "tech") BY OR;
14
}
15
RUN LOADING JOB loadPostPublicTech USING f="./posts3"
16
17
# post 4 will remain untagged.
Copied!

Set tags implicitly by inserting into a tag-based graph

Loading data to a tag-based graph automatically tags each vertex with the tags specified in the graph's definition. For example, when loading to vipNet, the person vertices will automatically be tagged with vip.
If you load data into a tag-based graph, these vertices are actually being added to the parent base graph. If two tag-based graphs have overlapping views (e.g. if the graph vipNet2 also includes person:vip), then when one adds a vertex via the tag-based graph, the other tag-based graph may also see it.
1
USE GRAPH vipNet
2
3
CREATE LOADING JOB loadMember {
4
DEFINE filename f;
5
// TAGS("vip") BY OR will be applied implicitly
6
// since vipNet is defined based on person:vip
7
LOAD f TO VERTEX person VALUES($0, $0, $1);
8
}
9
RUN LOADING JOB loadMember USING f="./persons3"
Copied!
  • Portability and Reusability: The same loading job works for socialNet or any graph derived from socialNet which contains person. The difference is in the effect: running it with vipNet will apply the vip tag. Running it with a different tag-based graph would apply different tags. Users of a given tag-based graph automatically insert and query data for that tag-based graph.
  • Tagging Shared Data: The default behavior of GSQL loading is upsert: if you attempt to insert a vertex or edge which already exists (e.g., uses an existing ID), you will instead update the existing element with the new attribute values. If the attribute is a list or set, the new values will be added to the existing list/set. This applies to tags. If you attempt to load an existing vertex, the new tag(s) will be added to any existing tags. Loading a vertex that already exists extends the tag set with the guidance of the tag-graph schema.

Query a Tag-based Graph

The graph vipNet only includes vertices with the tag vip. We can verify this by running a simple query to return all person vertices in vipNet:
1
USE GRAPH vipNet
2
3
CREATE QUERY findAll() {
4
seed = {person.*};
5
result =
6
SELECT v
7
FROM seed:v
8
ORDER BY v.id;
9
10
PRINT result;
11
}
12
INSTALL QUERY findAll
13
RUN QUERY findAll()
Copied!
The output of the query would be:
1
{
2
"error": false,
3
"message": "",
4
"version": {
5
"schema": 2,
6
"edition": "enterprise",
7
"api": "v2"
8
},
9
"results": [{"res": [
10
{
11
"v_id": "person6",
12
"attributes": {
13
"gender": "Male",
14
"id": "person6"
15
},
16
"v_type": "person"
17
},
18
{
19
"v_id": "person7",
20
"attributes": {
21
"gender": "Male",
22
"id": "person7"
23
},
24
"v_type": "person"
25
},
26
{
27
"v_id": "person8",
28
"attributes": {
29
"gender": "Male",
30
"id": "person8"
31
},
32
"v_type": "person"
33
}
34
]}]
35
}
Copied!

Access Control

Users with global WRITE_SCHEMA and ACCESS_TAG privileges can create, modify and drop tags, as well as create tag-based graphs for all graphs.

On the base graph

Users with roles on the base graph that have the ACCESS_TAG privilege (e.g.admin and designer roles) can create/drop tags, and tag vertices. Users that have both the ACCESS_TAG privilege and WRITE_SCHEMA privilege (e.g. admin and designer roles) can create/drop tag-based graphs of the base graph.
Users with roles that don't have the ACCESS_TAG privilege on the base graph are able to access the base graph as their roles allow, but they do not have access to the tags on the base graph. They cannot see whether any vertex type on the graph is taggable or if there are tag-based graphs of the base graph.
Users with roles on the tag-based graphs of the base graph cannot access the base graph if they don't have a role with privileges for the base graph.

On tag-based graphs

When a new tag-based graph is created, users with admin or designer roles will inherit their base graph role on the tag-based graph. Additionally, the creator of the tag-based graph becomes an admin of the tag-based graph.
Users who are given roles on a tag-based graph have the privileges on the tag-based graph that correspond to their roles, except they are not allowed to edit the tag-based graph's graph schema.

Sample Use Cases

Scenario I

Problem
A user with admin role on a graph wants to grant a group of users access to a selective set of vertices.
Solution
The base graph admin can do the following security setup.
  1. 1.
    Define a tag. In a schema change job, declare a tag T for this application.
  2. 2.
    Mark vertex types as taggable. Identify the vertex types you want to give selective access for, and mark those vertex types as taggable in a schema change job.
  3. 3.
    Define a tag-based graph. Define a tag-based graph B with the taggable vertex types, with T as their tag expression.
  4. 4.
    Tag vertices. Write a DML query on the base graph and use the tag functions in the query to tag the vertices you want to include in the tag-based graph, and run the query.
  5. 5.
    Grant users permission to the tag-based graph. On the tag-based graph B, grant roles that have the appropriate privileges for graph B to the target users.

Scenario II

Problem
You have a source file containing class annotations (tags) on vertex data. You want to grant users access to the vertices that have the annotation T1. In the future, you also want the ability to give other users access to vertices based on the vertex class.
Solution
The base graph admin user can do the following setup.
  1. 1.
    Define tags. Declare tags T1, T2, … Tn for all the classes in your source file in a schema change job.
  2. 2.
    Mark vertex types as taggable. Identify the vertex types of the vertices in your source file that have class annotations, and mark those vertex types as taggable in a schema change job.
  3. 3.
    Define a tag-based graph. Define a tag-based graph B with T1 as the tag expression.
  4. 4.
    Explicitly tag vertices during data loading. Write a base graph loading job, and in the loading job, use a TAGS() BY clause to explicitly add tags to the ingested vertices.
  5. 5.
    Grant roles on the tag-based graph. On the tag-based graph B, grant roles that have the appropriate privileges for the graph B to target users.

Scenario III

Problem
An admin user on a graph wants to give a group of users read/write access for a specific class of vertices. The users would be able to insert new vertices into the graph and query the data, and all the data they insert into the graph are tagged as the same class.
Solution
The base graph admin can do the following setup.
  • Define a tag. Declare a tag T for this application in a schema change job.
  • Mark vertex types as taggable. Identify the vertex types to give selective access to, and mark the relevant vertex types as taggable in a schema change job.
  • Define a tag-based graph. Define a tag-based graph B with T as the tag expression.
  • Grant roles on the tag-based graph. On the tag-based graph, grant roles with the appropriate privileges to target users.
These group users operate (including delete/update/insert) on graph B as if it is a normal graph. They can ingest new data, as well as operate on those vertices from the base graph that have the tag T.
Last modified 2mo ago