Overview
A policy is a set of privileges designed for a specific user role, often encompassing multiple privileges and other policies. Effective policy design and usage enable role-based access control.
Showing Policies
To list all policies of the database:
show().policy()
Or retrieves a specific policy, such as the one named manager
:
show().policy("manager")
It returns a table _policy
with the following fields:
Field |
Description |
---|---|
name |
Name of the policy. |
graphPrivileges |
Graph privileges included in the policy. |
systemPrivileges |
System privileges included in the policy. |
propertyPrivileges |
Property privileges included in the policy. |
policies |
Other policies included in the policy. |
Creating a Policy
The create().policy().params()
statement creates a policy for the database.
Syntax
create().policy("<name>").params({
graph_privileges: {
"<graph>": ["<graphPriv>", "<graphPriv>", ...],
...
},
system_privileges: ["<systemPriv>", "<systemPriv>", ...],
property_privileges: {
"node": {
"<propertyPriv>": [
["<graph>", "<schema>", "<property>"],
...
],
...
},
"edge": {
"<propertyPriv>": [
["<graph>", "<schema>", "<property>"],
...
],
...
}
},
policies: ["<policyName>", "<policyName>", ...]
})
Method | Param | Description |
---|---|---|
policy() |
<name> |
The unique name of the policy. Naming conventions are:
|
params() |
graph_privileges |
Specifies graph privileges for each graphset to include in the policy; uses "*" to specify all graphsets. |
system_privileges |
Specifies system privileges to include in the policy. | |
property_privileges |
Specifies node and edge property privileges to include in the policy; uses ["*", "*", "*"] to specify all graphsets, all schemas, or all properties. |
|
policies |
Specifies policies to include in the policy. |
Examples
To create a policy called superADM
that includes all graph and system privileges, along with write
privilege for all properties, without involving any other policies:
create().policy("superADM").params({
graph_privileges: {"*":["READ","INSERT","UPSERT","UPDATE","DELETE","CREATE_SCHEMA","DROP_SCHEMA","ALTER_SCHEMA","SHOW_SCHEMA","RELOAD_SCHEMA","CREATE_PROPERTY","DROP_PROPERTY","ALTER_PROPERTY","SHOW_PROPERTY","CREATE_FULLTEXT","DROP_FULLTEXT","SHOW_FULLTEXT","CREATE_INDEX","DROP_INDEX","SHOW_INDEX","LTE","UFE","CLEAR_JOB","STOP_JOB","SHOW_JOB","ALGO","CREATE_PROJECT","SHOW_PROJECT","DROP_PROJECT","CREATE_HDC_GRAPH","SHOW_HDC_GRAPH","DROP_HDC_GRAPH","COMPACT_HDC_GRAPH"]},
system_privileges: ["TRUNCATE","COMPACT","CREATE_GRAPH","SHOW_GRAPH","DROP_GRAPH","ALTER_GRAPH","TOP","KILL","STAT","SHOW_POLICY","CREATE_POLICY","DROP_POLICY","ALTER_POLICY","SHOW_USER","CREATE_USER","DROP_USER","ALTER_USER","SHOW_PRIVILEGE","SHOW_META","SHOW_SHARD","ADD_SHARD","DELETE_SHARD","SHOW_HDC_SERVER","ADD_HDC_SERVER","DELETE_HDC_SERVER","LICENSE_UPDATE","LICENSE_DUMP"],
property_privileges: {
"node": {"write": [["*", "*", "*"]]},
"edge": {"write": [["*", "*", "*"]]}
}
})
To create a policy called Tester
that includes:
- Graph privileges:
UPDATE
for all graphsets - System privileges:
SHOW_POLICY
,ALTER_GRAPH
- Property privileges:
read
all node properties for all schemas in all graphsetswrite
edge propertiesvalue
andtime
for all schemas in the graphsetTax
deny
(Do not allowread
andwrite
) edge propertyscore
for the schemarate
in the graphsetminiCircle
- Policies:
manager
create().policy("Tester").params({
graph_privileges: {"*": ["UPDATE"]},
system_privileges: ["SHOW_POLICY", "ALTER_GRAPH"],
property_privileges: {
"node": {
"read": [
["*", "*", "*"]
]
},
"edge": {
"write": [
["Tax", "*", "value"],
["Tax", "*", "time"]
],
"deny": [
["miniCircle", "rates", "score"]
]
}
},
policies: ["manager"]
})
Altering a Policy
You can alter the privileges and policies included in a policy using the alter().policy().set()
statement.
Syntax
alter().policy("<name>").set({
graph_privileges: {
"<graph>": ["<graphPriv>", "<graphPriv>", ...],
...
},
system_privileges: ["<systemPriv>", "<systemPriv>", ...],
property_privileges: {
"node": {
"<propertyPriv>": [
["<graph>", "<schema>", "<property>"],
...
],
...
},
"edge": {
"<propertyPriv>": [
["<graph>", "<schema>", "<property>"],
...
],
...
}
},
policies: ["<policyName>", "<policyName>", ...]
})
Method | Param | Description |
---|---|---|
policy() |
<name> |
Name of the policy. |
set() |
graph_privileges |
Specifies new graph privileges for each graphset to include in the policy; uses "*" to specify all graphsets. |
system_privileges |
Specifies new system privileges to include in the policy. | |
property_privileges |
Specifies new node and edge property privileges to include in the policy; uses ["*", "*", "*"] to specify all graphsets, all schemas, or all properties. |
|
policies |
Specifies new policies to include in the policy. |
Examples
To modify graph privileges included in the sales
policy while keeping other types of privileges and policies unchanged:
alter().policy("Tester").set({graph_privileges: {"Tax": ["UPDATE"]}})
To modify the graph and property privileges, and policies included in the manager
policy while keeping the system privileges unchanged:
alter().policy("manager").set({
graph_privileges: {"*": ["UPDATE", "DELETE"]},
property_privileges: {
"node": {
"write": [["miniCircle","*","*"]]
},
"edge": {
"write": [["miniCircle","*","*"]]
}
},
policies: ["sales"]
})
Dropping a Policy
You can drop a policy using the drop().policy()
statement.
To drop the policy manager
:
drop().policy("manager")