Specify users in scope for a per-user quota¶
A quota’s user scope determines which users the quota monitors. You define the scope in three parts: which users to include, which groups of users to exclude, and which individual users to always include or exclude by name. This topic explains how Snowflake combines those parts, how to select users by role, and how to set, change, and verify the scope.
How user scope works¶
The following table describes the three parts of a quota’s user scope. Each part corresponds to a section of the payload that you pass to the scope methods:
| Part | Payload section | What it defines |
|---|---|---|
| Include | applies_to | All users in the account (ALL_USERS, the default), or a group of users (GROUP_OF_USERS) selected by user tags, roles, or both. In a group, one operator combines every tag and role: UNION (the default) includes users who match at least one, and INTERSECTION includes users who match all of them. |
| Exclude | excluded_by | User tags and roles whose users are removed from the scope. A user who matches any listed tag or role is excluded. Exclusions apply to either include type. |
| Named users | usernames | Individual users who are always in scope (included) or always out of scope (excluded), regardless of the include and exclude parts. |
Snowflake resolves the users in scope in the following order:
- Start with the users selected by the include part.
- Remove users who match any excluded tag or role.
- Remove users named in
usernames.excluded. - Add users named in
usernames.included.
Because named users are applied last, a user in usernames.included is in scope even when an excluded
role or tag matches them, and a user in usernames.excluded is out of scope even when they match the
include part.
Snowflake resolves users at evaluation time, so changes to tag assignments and role grants are reflected in the quota without any reconfiguration. A user can belong to more than one quota. Each quota evaluates that user’s spending against its own limit independently.
How role-based selection works¶
Selecting users by role determines who is in scope, not which usage counts toward the limit. The quota monitors each user in scope individually; it doesn’t set a shared limit for everyone with a role.
Only roles granted directly to a user count when including or excluding that user by role.
Inherited roles don’t count. For example, if ANALYST is granted to TEAM_ROLE and TEAM_ROLE is
granted to a user, selecting ANALYST doesn’t select that user through the inherited grant.
Once a user is in scope, all of their usage of the quota’s monitored domains and resources counts
toward their per-user limit, regardless of the primary and secondary roles active when they run a
request. For example, if a quota includes ALICE through a direct grant of ANALYST, their usage
still counts when DATA_ENG is the primary role and ANALYST is only a secondary role or isn’t
active at all. Switching roles doesn’t move the user out of scope or give them a separate usage
counter.
The following restrictions also apply:
- Some roles can’t be used. You can’t specify the
PUBLICrole or a role that doesn’t exist. A role that is dropped after you add it selects no users. - Unquoted role names aren’t case-sensitive. Snowflake stores each role name as the role it
resolves to and removes duplicates. A role created with a quoted name, such as
"finance_analyst", is case-sensitive, so include its double quotes, escaped, in the role name.
For example, the following call selects users who are granted the role "finance_analyst". The
dollar-quoted string passes the escaped quotes to PARSE_JSON unchanged:
When you grant or revoke a role, the quota reflects the change after a short delay. For more information, see Verify the user scope.
Users that quotas cover¶
A quota that covers all users includes service users, both those you create (TYPE = SERVICE) and
Snowflake-managed ones (TYPE = SNOWFLAKE_SERVICE), such as Snowpark Container Services identities. You
can tag, include, and exclude SERVICE users like any other user, but you can’t tag or name
SNOWFLAKE_SERVICE users.
Quotas don’t cover the system user, which runs tasks and dynamic table refreshes by default. To count
that usage toward a quota, run them with EXECUTE AS USER.
Set the user scope¶
To set the user scope, call SET_QUOTA_USER_SCOPE with a payload that contains one or more of the
applies_to, excluded_by, and usernames sections. The method replaces each list that you pass
and leaves the lists that you omit unchanged. To clear a list, pass an empty array. To call the scope
methods, use a role granted the quota’s ADMIN instance role, with the USAGE privilege on the
quota’s database and schema.
Snowflake applies the sections in a fixed order, regardless of their order in the payload:
applies_to, excluded_by.user_tags, excluded_by.roles, and then usernames. Lists that you
pass in the same call as a new include type are written after the include type changes, so the
change doesn’t clear them. ADD_QUOTA_USER_SCOPE and REMOVE_QUOTA_USER_SCOPE use the same order.
The following rules apply to the applies_to section:
typeis required. PassALL_USERSorGROUP_OF_USERS.ALL_USERSdoesn’t acceptoperator,user_tags, orroles. SettingALL_USERSclears the include roles, and also clears the include tags when the quota was scoped to a group of users. Exclusions and named users are kept.GROUP_OF_USERSrequiresuser_tags,roles, or both, but either or both can be empty arrays. If you omitoperator, the operator is set toUNION, even if it wasINTERSECTIONbefore.- Each entry in
user_tagsis a pair of a tag reference and a value, in the form[SYSTEM$REFERENCE('TAG', '<db>.<schema>.<tag>', 'SESSION', 'APPLYBUDGET'), '<value>']. The role that sets the scope must have theAPPLYBUDGETprivilege on each tag.
SET_QUOTA_USER_SCOPE accepts up to 250 roles per call, counting roles already on the quota. A call
over the limit fails without changing the scope. To work with more roles, use
ADD_QUOTA_USER_SCOPE, which has no role limit.
The method returns the quota’s resulting user scope as a JSON string, in the same format as the
users object that GET_QUOTA_SCOPE_V2 returns.
Example: Users who hold either of two roles, excluding account administrators
Note
A user who holds ACCOUNTADMIN and ANALYST is out of scope in this example, because exclusions
remove matching users from the include part. To keep a specific administrator in scope, add them to
usernames.included.
Example: All users except administrators and one named user
Example: Users who hold a role and carry a tag
To select users who match a tag and also hold a role, use INTERSECTION. Because SYSTEM$REFERENCE
is a SQL expression rather than a JSON string literal, build the payload with OBJECT_CONSTRUCT
instead of PARSE_JSON:
One operator applies to every include tag and role, so a scope such as “users tagged finance or
analytics, who also hold ANALYST” can’t be expressed in one quota.
Example: Only named users
To cover only the users that you name, pass empty user_tags and roles arrays. The include part
then selects no users, so only the users in usernames.included are in scope:
Example: Replace the list of excluded users
This sets usernames.excluded to BOB and CAROL, and removes them from usernames.included if
they were listed there. The applies_to and excluded_by sections don’t change.
Add to or remove from the user scope¶
To change a list without resending it, call ADD_QUOTA_USER_SCOPE or REMOVE_QUOTA_USER_SCOPE
with the entries to add or remove. Both methods accept the same sections as SET_QUOTA_USER_SCOPE,
with the following differences:
- Neither method accepts
typeoroperator. To change them, useSET_QUOTA_USER_SCOPE. - Each list that you pass must contain at least one entry, and the payload must contain at least one list.
ADD_QUOTA_USER_SCOPEaccepts up to 20 tags per call. It has no limit on roles.- You can’t add include tags or roles while the include type is
ALL_USERS.
Like SET_QUOTA_USER_SCOPE, both methods return the quota’s resulting user scope as a JSON string.
Adding a user to usernames.included removes them from usernames.excluded, and the reverse is
also true. Removing a user from one username list doesn’t add them to the other list. Removing an
entry that isn’t on the list leaves the list unchanged.
Example: Add a role to the exclusions
Example: Add a role to the include part
The include tags and the operator don’t change:
Example: Add a tag value to the exclusions
Example: Remove a role and a user from the exclusions
Rejected scope changes¶
Snowflake validates each call before it writes anything. A rejected call returns an error and leaves the stored scope unchanged. The scope methods reject the following payloads:
- An empty payload, or a section with no fields.
- Unknown fields, including
shared_resources. To change monitored domains, useADD_SHARED_RESOURCEandREMOVE_SHARED_RESOURCE. NULLvalues or values of the wrong type.- In
SET_QUOTA_USER_SCOPE, anapplies_tosection withouttype, or with atypeother thanALL_USERSorGROUP_OF_USERS. ALL_USERSwithoperator,user_tags, orroles.GROUP_OF_USERSwith neitheruser_tagsnorroles.- A tag passed by name instead of by
SYSTEM$REFERENCE. - The
PUBLICrole, or a role that doesn’t exist. - The same user in both
usernames.includedandusernames.excluded, inSET_QUOTA_USER_SCOPEorADD_QUOTA_USER_SCOPE. typeoroperatorinADD_QUOTA_USER_SCOPEorREMOVE_QUOTA_USER_SCOPE.applies_to.user_tagsorapplies_to.rolesinADD_QUOTA_USER_SCOPEwhile the include type isALL_USERS.- More than 250 roles in
SET_QUOTA_USER_SCOPE, counting roles already on the quota.
Verify the user scope¶
To view the quota’s full scope, call GET_QUOTA_SCOPE_V2:
A role granted the quota’s ADMIN or VIEWER instance role can call this method.
The method returns a JSON string that contains a users object, in the same format as the scope
payload, and the monitored domains in shared_resources. To query the result as JSON, parse it with
PARSE_JSON:
For example, the method returns the following scope:
When the include type is ALL_USERS, applies_to contains only {"type": "ALL_USERS"}.
To list the users currently resolved into the quota’s scope:
Note
GET_USERS reflects tag changes and role grants and revokes after approximately 10 to 15 minutes.
Automate user roles and tags with SCIM¶
If you provision users through a SCIM identity provider, you can map identity provider groups to
Snowflake roles that are granted directly to users, or use the snowflakeTags attribute to apply user
tags automatically when users are created or updated. For more information about SCIM user tags, see
Automating user tags with SCIM. For provider-specific setup steps, see
the following topics:
Legacy scope methods¶
The SET_USER_TAGS, INCLUDE_USERS, and EXCLUDE_USERS methods and the GET_QUOTA_SCOPE method
still work, but they can’t select or exclude users by role. Snowflake recommends using
SET_QUOTA_USER_SCOPE, ADD_QUOTA_USER_SCOPE, REMOVE_QUOTA_USER_SCOPE, and
GET_QUOTA_SCOPE_V2 instead.
SET_ USER_ TAGS¶
SET_USER_TAGS replaces the include tags and sets the operator: UNION, INTERSECTION, or
ALL_USERS. The operator argument is required, even when you pass a single tag.
SET_USER_TAGS doesn’t change include or exclude roles. Its other effects depend on the operator:
- With
UNIONorINTERSECTION, it changes only the include tags and the operator. - With
ALL_USERS, it clears the include tags and the tag exclusions. When the quota was scoped to a group of users, it also clears both username lists. - Don’t pass tags with
ALL_USERSto exclude users. To exclude users by tag, useEXCLUDE_USERS('TAG', ...)orexcluded_by.user_tags.
EXCLUDE_ USERS with tags¶
EXCLUDE_USERS('TAG', ...) replaces the tag exclusions. It doesn’t change the include part. To
clear the tag exclusions, pass an empty array.
INCLUDE_ USERS and EXCLUDE_ USERS with user names¶
INCLUDE_USERS and EXCLUDE_USERS('USER', ...) add names to the username lists. Calling either one
again adds to the existing list rather than replacing it, and adding a user to one list removes them
from the other. To clear a list, pass an empty array.
GET_ QUOTA_ SCOPE¶
GET_QUOTA_SCOPE returns the monitored domains, the users included and excluded by name, and the
include and exclude tags and the operator. It doesn’t return roles. To see the full scope, including
roles, use GET_QUOTA_SCOPE_V2.
Migrate to the new scope methods¶
The following table maps each legacy call to its replacement:
| Legacy call | Replacement |
|---|---|
SET_USER_TAGS(<tags>, 'UNION') or 'INTERSECTION' | SET_QUOTA_USER_SCOPE with applies_to set to GROUP_OF_USERS, the operator, and user_tags. |
SET_USER_TAGS([], 'ALL_USERS') | SET_QUOTA_USER_SCOPE with applies_to set to ALL_USERS. Unlike the legacy call, this clears the include roles and keeps the tag exclusions and named users. To also clear those, pass an empty excluded_by.user_tags list and empty usernames lists in the same call. |
SET_USER_TAGS(<tags>, 'ALL_USERS') | SET_QUOTA_USER_SCOPE with applies_to set to ALL_USERS and the tags in excluded_by.user_tags. Unlike the legacy call, this clears the include roles and keeps both username lists. |
EXCLUDE_USERS('TAG', <tags>) | SET_QUOTA_USER_SCOPE with excluded_by.user_tags. To add or remove one tag, use ADD_QUOTA_USER_SCOPE or REMOVE_QUOTA_USER_SCOPE. |
INCLUDE_USERS(<names>) | ADD_QUOTA_USER_SCOPE with usernames.included. To replace the list, use SET_QUOTA_USER_SCOPE. |
EXCLUDE_USERS('USER', <names>) | ADD_QUOTA_USER_SCOPE with usernames.excluded. To replace the list, use SET_QUOTA_USER_SCOPE. |
INCLUDE_USERS([]) or EXCLUDE_USERS('USER', []) | SET_QUOTA_USER_SCOPE with an empty usernames.included or usernames.excluded list. |
GET_QUOTA_SCOPE() | GET_QUOTA_SCOPE_V2() |