Granting Authorization Access to Namespaces
You can manage permission for users or roles to access namespaces and tables. These are the applicable permissions given to the developers and other users:
Table 1 - Namespace Privileges and Permissions
| Privilege | Description |
|---|---|
|
Grant permission to a user or to a role to create or drop any namespace. |
|
Grant permission to a user or to a role to create, drop or evolve tables in a specific namespace. You can evolve tables to update table definitions, add or remove fields, or change field properties, such as a default value. You may even add a particular kind of column, like an IDENTITY column, to increment some value automatically. Only tables that already exist in the store are candidates for table evolution. For more details, see Alter Table. |
|
Grant permission to a user or to a role to create or drop an index in a specific namespace. |
|
Grant permission to a role to read, insert, or delete items in a specific namespace. |
MODIFY_IN_NAMESPACE |
Helper label for granting or revoking permissions to all DDL privileges for a specific namespace to a user or role. |
Grant privileges on a namespace
You can grant permissions to a role or a user on a namespace. Following is the syntax for granting permissions on a namespace:
GRANT {Namespace-scoped privileges} ON NAMESPACE namespace_name TO <User|Role>
Namespace-scoped privileges ::= namespace_privilege [, namespace_privilege]
where,
-
namespace_privilege
The namespace privilege that can be granted to a user or a role. For more information on the applicable privileges, see the Privilege column in the Namespace Privileges and Permissions table.
-
namespace_name
The namespace that the user wishes to access.
-
<User|Role>The name of the KVStore user or the role of a user.
For example, you can grant read access to a user for all the tables in the namespace.
Example:
GRANT READ_IN_NAMESPACE ON NAMESPACE ns1 TO Kate;
Here, ns1 is the namespace and Kate is the user. Note: The label MODIFY_IN_NAMESPACE can be used as a helper for granting or revoking permissions to all DDL privileges for a specific namespace to a user or role.
Revoke privileges on a namespace
You can revoke the permissions from a role or a user on a namespace. Following is the syntax for revoking the permissions on a namespace.
REVOKE {Namespace-scoped privileges} ON NAMESPACE namespace_name FROM <User|Role>
Namespace-scoped privileges ::= namespace_privilege [, namespace_privilege]
where,
-
namespace_privilege
The namespace privilege that can be revoked from a user or a role. For more information on the applicable privileges, see the Privilege column in the Namespace Privileges and Permissions table.
-
namespace_name
The namespace that the user wishes to access.
-
<User\Role>
The name of the KVStore user or the role of a user.
For example, you can revoke the read access from a user for all the tables in the namespace.
Example:
REVOKE READ_IN_NAMESPACE ON NAMESPACE ns1 FROM Kate;
Here, ns1 is the namespace and Kate is the user.
Note: The label MODIFY_IN_NAMESPACE can be used as a helper for granting or revoking permissions to all DDL privileges for a specific namespace to a user or role.
The following example shows:
-
Creation of a namespace and a table.
-
Revocation of the privilege to create any other new tables in the namespace, but allow the table to be dropped.
Example: Namespace Scoped Privileges
CREATE NAMESPACE IF NOT EXISTS ns1;
GRANT MODIFY_IN_NAMESPACE ON NAMESPACE ns1 TO usersRole;
CREATE TABLE ns1:t (id INTEGER, name STRING, primary key (id));
INSERT INTO ns1:t VALUES (1, 'Smith');
SELECT * FROM ns1:t;
REVOKE CREATE_TABLE_IN_NAMESPACE ON NAMESPACE ns1 FROM usersRole;
DROP NAMESPACE ns1 CASCADE;
Note: You can save all of the above commands as a sql script and execute it in a single command. If you want to execute any of the above commands outside of a SQL prompt, remove the semi colon at the end.