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 3-1 Namespace Privileges and Permissions

Privilege Description

CREATE_ANY_NAMESPACE

DROP_ANY_NAMESPACE

Grant permission to a user or to a role to create or drop any namespace.
GRANT CREATE_ANY_NAMESPACE TO <User|Role>;
GRANT DROP_ANY_NAMESPACE TO <User|Role>;

CREATE_TABLE_IN_NAMESPACE

DROP_TABLE_IN_NAMESPACE

EVOLVE_TABLE_IN_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 CREATE_TABLE_IN_NAMESPACE ON NAMESPACE namespace_name TO <User|Role>; 
GRANT DROP_TABLE_IN_NAMESPACE ON NAMESPACE  namespace_name TO <User|Role>;
GRANT EVOLVE_TABLE_IN_NAMESPACE ON NAMESPACE namespace_name TO <User|Role>user_role;

CREATE_INDEX_IN_NAMESPACE

DROP_INDEX_IN_NAMESPACE

Grant permission to a user or to a role to create or drop an index in a specific namespace.
GRANT CREATE_INDEX_IN_NAMESPACE ON NAMESPACE namespace_name TO <User|Role>; 
GRANT DROP_INDEX_IN_NAMESPACE ON NAMESPACE namespace_name TO <User|Role>;

READ_IN_NAMESPACE

INSERT_IN_NAMESPACE

DELETE_IN_NAMESPACE

Grant permission to a role to read, insert, or delete items in a specific namespace.
GRANT READ_IN_NAMESPACE ON NAMESPACE namespace_name TO <User|Role>; 
GRANT INSERT_IN_NAMESPACE ON NAMESPACE  namespace_name TO <User|Role>;
GRANT DELETE_IN_NAMESPACE ON NAMESPACE namespace_name TO <User|Role>;

MODIFY_IN_NAMESPACE

Helper label for granting or revoking permissions to all DDL privileges for a specific namespace to a user or role.
GRANT MODIFY_IN_NAMESPACE ON NAMESPACE namespace_name TO <User|Role>; 
REVOKE MODIFY_IN_NAMESPACE ON NAMESPACE namespace_name TO <User|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.
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.
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:
  1. Creation of a namespace and a table.
  2. 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.