Skip to main content

Grants and roles

Grant and revoke privileges, roles, membership, and fine-grained data access. See the permissions documentation for what each privilege and role allows.

Every method names one principal with principal_type ("USER", "GROUP", "SERVICE_PRINCIPAL") and principal (the user's email, or the group or service principal name). Object names are dotted: "lake", "lake.database", "lake.database.table".

These methods do not take unsafe_raw; keyword values are always validated.

note

A group must hold a project role before it can be granted privileges on tables. Grant the role first with grant_role; otherwise the server returns Entity of type: GROUP not found.

Methods​

MethodDescription
grant_privilege / revoke_privilegeGrant or revoke privileges on one object
grant_privilege_on_all / revoke_privilege_on_allGrant or revoke privileges on every child of a container
grant_role / revoke_roleGrant or revoke a project or account role
grant_member / revoke_memberAdd or remove a member of a group or service principal
grant_row_filter / revoke_row_filterRestrict which rows of a table the principal sees
grant_column_mask / revoke_column_maskMask a column of a table for the principal
grant_column_access / revoke_column_accessRestrict which columns of a table the principal sees
grant_data_admin / revoke_data_adminMake the principal a data admin for the organization
show_grantsList the grants on an object
show_rolesList the roles a type of principal holds on a project

grant_privilege​

grant_privilege(
privileges: str | Sequence[str],
*,
on: str,
name: str,
principal_type: str,
principal: str,
timeout: float | None = None,
poll_interval: float | None = None,
)

revoke_privilege takes the same arguments.

ParameterRequiredType / values
privilegesyesOne privilege or a list: "VIEWER", "EDITOR", "USER", "MANAGER", "ALL_PRIVILEGES", "MANAGE", "DESCRIBE", "CREATE", "SELECT", "INSERT", "UPDATE", "DELETE", "CANCEL", "ALTER", "DROP", "INVOKE", "CALL", "READ", "WRITE"
onyes"TABLE", "DATABASE", "CLUSTER", "LAKE", "JOB", "AI_MODEL", "MCP_TOOL", "URL"
nameyesstr — name of the object
principal_typeyes"USER", "GROUP", "SERVICE_PRINCIPAL"
principalyesstr

The grade privileges VIEWER, EDITOR, USER, and MANAGER must be granted on their own. Passing one of them in a list with other privileges raises ValueError.

Example​

client.grant_privilege(
["SELECT", "DESCRIBE"],
on="TABLE",
name="prod_lake.sales.orders",
principal_type="GROUP",
principal="analysts",
)
# GRANT PRIVILEGE SELECT, DESCRIBE ON TABLE 'prod_lake.sales.orders' TO GROUP 'analysts'

grant_privilege_on_all​

grant_privilege_on_all(
privileges: str | Sequence[str],
*,
children: str,
container_type: str,
container: str,
principal_type: str,
principal: str,
timeout: float | None = None,
poll_interval: float | None = None,
)

revoke_privilege_on_all takes the same arguments. The grant covers every current and future child of the container.

ParameterRequiredType / values
privilegesyesSame values and rules as grant_privilege
childrenyes"TABLES", "DATABASES"
container_typeyes"DATABASE", "LAKE"
containeryesstr — name of the container
principal_typeyes"USER", "GROUP", "SERVICE_PRINCIPAL"
principalyesstr

Only two children / container_type pairs are accepted: TABLES in DATABASE, and DATABASES in LAKE. Any other pair raises ValueError.

Example​

client.grant_privilege_on_all(
"SELECT",
children="TABLES",
container_type="DATABASE",
container="prod_lake.sales",
principal_type="GROUP",
principal="analysts",
)
# GRANT PRIVILEGE SELECT ON ALL TABLES IN DATABASE 'prod_lake.sales' TO GROUP 'analysts'

grant_role​

grant_role(
role: str,
*,
on: str,
name: str,
principal_type: str,
principal: str,
timeout: float | None = None,
poll_interval: float | None = None,
)
ParameterRequiredType / values
roleyes"ADMIN", "MEMBER", "READER"
onyes"PROJECT", "ACCOUNT"
nameyesstr — project or account name
principal_typeyes"USER", "GROUP", "SERVICE_PRINCIPAL"
principalyesstr

on="ACCOUNT" works only with principal_type="SERVICE_PRINCIPAL"; any other principal type raises ValueError. For account roles the server ignores name.

Example​

client.grant_role(
"MEMBER", on="PROJECT", name="my_project",
principal_type="GROUP", principal="analysts",
)
# GRANT ROLE MEMBER ON PROJECT 'my_project' TO GROUP 'analysts'

revoke_role​

Same signature as grant_role, but on accepts only "PROJECT": account roles cannot be revoked through SQL.

caution

revoke_role removes the principal from the project entirely. The server ignores role, so revoke_role("ADMIN", ...) does not downgrade an admin to a member; it removes every role the principal holds on the project. To change a principal's role, revoke it and then grant the new role.

Example​

client.revoke_role(
"MEMBER", on="PROJECT", name="my_project",
principal_type="GROUP", principal="analysts",
)

grant_member​

grant_member(
*,
on: str,
name: str,
principal_type: str,
principal: str,
role: str = "MEMBER",
timeout: float | None = None,
poll_interval: float | None = None,
)

revoke_member takes the same arguments. It removes the membership whatever role is given; it never downgrades a manager to a member.

ParameterRequiredType / values
onyes"GROUP", "SERVICE_PRINCIPAL"
nameyesstr — the group or service principal
principal_typeyesFor a group: "USER", "SERVICE_PRINCIPAL". For a service principal: "USER", "GROUP".
principalyesstr
roleno"MEMBER" (default), "MANAGER"

Any other principal type for the chosen on raises ValueError.

Example​

client.grant_member(
on="GROUP", name="analysts",
principal_type="USER", principal="jane@example.com",
)
# GRANT ROLE MEMBER ON GROUP 'analysts' TO USER 'jane@example.com'

grant_row_filter​

grant_row_filter(
expression: str,
*,
table: str,
principal_type: str,
principal: str,
timeout: float | None = None,
poll_interval: float | None = None,
)

The principal sees only the rows of table that match expression.

Example​

client.grant_row_filter(
"region = 'US'",
table="prod_lake.sales.orders",
principal_type="GROUP",
principal="analysts",
)
# GRANT ROW FILTER 'region = ''US''' ON TABLE 'prod_lake.sales.orders' TO GROUP 'analysts'

revoke_row_filter​

revoke_row_filter(
*,
table: str,
principal_type: str,
principal: str,
expression: str | None = None,
timeout: float | None = None,
poll_interval: float | None = None,
)

Without expression, revokes every row filter on the table for the principal.

Example​

client.revoke_row_filter(
table="prod_lake.sales.orders", principal_type="GROUP", principal="analysts",
)

grant_column_mask​

grant_column_mask(
column: str,
*,
table: str,
principal_type: str,
principal: str,
mask_type: str | None = None,
custom_expression: str | None = None,
timeout: float | None = None,
poll_interval: float | None = None,
)

Pass exactly one of mask_type or custom_expression.

ParameterRequiredType / values
columnyesstr
tableyesstr
mask_typeone of"MASK", "MASK_SHOW_LAST_4", "MASK_SHOW_FIRST_4", "MASK_HASH", "MASK_NULL", "MASK_DATE_SHOW_YEAR"
custom_expressionone ofstr — custom mask expression

Examples​

client.grant_column_mask(
"email", table="prod_lake.sales.orders",
principal_type="GROUP", principal="analysts", mask_type="MASK_HASH",
)
# GRANT COLUMN MASK 'email' USING 'MASK_HASH' ON TABLE 'prod_lake.sales.orders' TO GROUP 'analysts'

client.grant_column_mask(
"ssn", table="prod_lake.sales.orders",
principal_type="GROUP", principal="analysts",
custom_expression="concat('***', substr(ssn, -4))",
)

revoke_column_mask​

revoke_column_mask(
column: str,
*,
table: str,
principal_type: str,
principal: str,
timeout: float | None = None,
poll_interval: float | None = None,
)

Example​

client.revoke_column_mask(
"email", table="prod_lake.sales.orders", principal_type="GROUP", principal="analysts",
)

grant_column_access​

grant_column_access(
columns: str | Sequence[str],
*,
table: str,
principal_type: str,
principal: str,
timeout: float | None = None,
poll_interval: float | None = None,
)

The principal sees only these columns of table. Column names must be non-empty and must not contain commas.

Example​

client.grant_column_access(
["id", "region"], table="prod_lake.sales.orders",
principal_type="GROUP", principal="analysts",
)
# GRANT COLUMN ACCESS 'id,region' ON TABLE 'prod_lake.sales.orders' TO GROUP 'analysts'

revoke_column_access​

revoke_column_access(
*,
table: str,
principal_type: str,
principal: str,
timeout: float | None = None,
poll_interval: float | None = None,
)

Removes the column-access restriction on the table for the principal.

Example​

client.revoke_column_access(
table="prod_lake.sales.orders", principal_type="GROUP", principal="analysts",
)

grant_data_admin​

grant_data_admin(
*,
principal_type: str,
principal: str,
timeout: float | None = None,
poll_interval: float | None = None,
)

revoke_data_admin takes the same arguments. Data admin is organization-wide and takes no object. See GRANT DATA_ADMIN.

Example​

client.grant_data_admin(principal_type="USER", principal="jane@example.com")
# GRANT DATA_ADMIN TO USER 'jane@example.com'

show_grants​

show_grants(
*,
on: str,
name: str,
timeout: float | None = None,
poll_interval: float | None = None,
)

on takes the same eight values as in grant_privilege: TABLE, DATABASE, CLUSTER, LAKE, JOB, AI_MODEL, MCP_TOOL, URL. Any other value raises ValueError. SHOW GRANTS itself also accepts ACCOUNT, PROJECT, GROUP, SERVICE_PRINCIPAL, SOURCE, CATALOG, and FLOW; run those through client.execute(), for example client.execute("SHOW GRANTS ON FLOW 'my_flow'").

Example​

result = client.show_grants(on="TABLE", name="prod_lake.sales.orders")

show_roles​

show_roles(
principal_type: str,
*,
name: str,
on: str = "PROJECT",
timeout: float | None = None,
poll_interval: float | None = None,
)

Lists the roles that users, groups, or service principals hold on the project name. on accepts only "PROJECT".

Example​

result = client.show_roles("GROUP", name="my_project")
# SHOW GROUP ROLES ON PROJECT 'my_project'