CREATE SESSION POLICY

statementsupportedGovernance (policies, tags, data quality)

docs.snowflake.com ↗

Object: SESSION POLICY

Creates a new session policy or replaces an existing session policy. A session policy defines the idle session timeout period in minutes. Administrators can optionally set different timeout values for the Snowflake web interface and other Snowflake clients, and can set a privilege ceiling for agents with AGENT_RESTRICTED_SESSION_SCOPE. For that property, see Restricted Session Scope for agents. After creating a session policy, apply the session policy to your Snowflake account using an ALTER ACCOUNT statement or a user using an ALTER USER statement.

Syntax

supportedpartialnot supportednot scored

CREATE [OR REPLACE] SESSION POLICY [IF NOT EXISTS] <name>
  [ SESSION_IDLE_TIMEOUT_MINS = <integer> ]
  [ SESSION_UI_IDLE_TIMEOUT_MINS = <integer> ]
  [ SESSION_MAX_LIFESPAN_MINS = <integer> ]
  [ SESSION_UI_MAX_LIFESPAN_MINS = <integer> ]
  [ ALLOWED_SECONDARY_ROLES = ( [ { 'ALL' | <role_name> [ , <role_name> ... ] } ] ) ]
  [ BLOCKED_SECONDARY_ROLES = ( [ { 'ALL' | <role_name> [ , <role_name> ... ] } ] ) ]
  [ AGENT_RESTRICTED_SESSION_SCOPE = { '<predefined_scope>' | '<rss_object_name>' | $$ <yaml_definition> $$ } ]
  [ COMMENT = '<string_literal>' ]

Parameters

NameRequiredDescription
namerequiredIdentifier for the session policy; must be unique for your account. The identifier value must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (e.g. "My object"). Identifiers enclosed in double quotes are also case-sensitive. For more details, see Identifier requirements.
SESSION_IDLE_TIMEOUT_MINS = integeroptionalFor Snowflake clients and programmatic clients, the number of minutes in which a session can be idle before users must authenticate to Snowflake again. If a value is not specified, Snowflake uses the default value. The number of minutes can be any integer between 5 and 1440, inclusive. Default: 240 (4 hours)
SESSION_UI_IDLE_TIMEOUT_MINS = integeroptionalFor Snowsight, the number of minutes in which a session can be idle before a user must authenticate to Snowflake again. If a value is not specified, Snowflake uses the default value. The number of minutes can be any integer between 5 and 1440, inclusive. Default: 1080 (18 hours)
SESSION_MAX_LIFESPAN_MINS = integeroptionalFor Snowflake clients and programmatic clients, the maximum number of minutes a session can remain active before users must authenticate to Snowflake again, regardless of activity. If a value is not specified, Snowflake uses the default value. The number of minutes can be any integer between 0 and 43200 (30 days), inclusive. A value of 0 means no maximum lifespan is enforced. Default: 0 (no maximum lifespan enforcement)
SESSION_UI_MAX_LIFESPAN_MINS = integeroptionalFor Snowsight, the maximum number of minutes a session can remain active before users must authenticate to Snowflake again, regardless of activity. If a value is not specified, Snowflake uses the default value. The number of minutes can be any integer between 0 and 43200 (30 days), inclusive. A value of 0 means no maximum lifespan is enforced. Default: 0 (no maximum lifespan enforcement)
ALLOWED_SECONDARY_ROLES = ( [ { 'ALL' | role_name [ , role_name ... ] } ] )optionalSpecifies the allowed secondary roles for a session policy, if any. The possible values for the property are: Default: ('ALL'). If you do not set the property when you create a new session policy, all secondary roles are allowed.
  • ('ALL') — Allows all secondary roles.
  • ( role_name [ , role_name ... ] ) — Allows the specified roles as secondary roles. The secondary roles can be user-defined account roles or system roles. Specify the role name as it is stored in Snowflake. For details, see Identifier requirements.
()Disallows secondary roles.
BLOCKED_SECONDARY_ROLES = ( [ { 'ALL' | role_name [ , role_name ... ] } ] )optionalSpecifies the blocked secondary roles for a session policy, if any. Blocked secondary roles take precedence over allowed secondary roles. The possible values for the property are: Default: (). If you do not set the property when you create a new session policy, all secondary roles are allowed.
  • ('ALL') — Disallows secondary roles.
  • ( role_name [ , role_name ... ] ) — Blocks the specified roles as secondary roles. The specified roles, and the roles granted to those roles, cannot be activated as secondary roles. These blocked roles can be user-defined account roles or system roles. Specify the role name as it is stored in Snowflake. For details, see Identifier requirements.
()Allows all secondary roles.
AGENT_RESTRICTED_SESSION_SCOPE = { '<predefined_scope>' | '<rss_object_name>' | $$ <yaml_definition> $$ }optionalPrivilege ceiling that Snowflake applies when an agent is active in the session (SYS_CONTEXT('SNOWFLAKE$CURRENT', 'IS_AGENT_ACTIVATED') returns TRUE). When no agent is active, this property is ignored. Specify one of the following: A Snowflake predefined scope name, such as 'SNOWFLAKE$DATA_READ'. The fully qualified name of a restricted session scope object. An inline YAML document that defines the privilege ceiling. For predefined scopes, YAML structure, and examples, see Restricted Session Scope for agents. Default: null. If you do not set the property, no agent scope is applied.
COMMENT = 'string_literal'optionalAdds a comment or overwrites an existing comment for the session policy.

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE SESSION POLICY | Schema | Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control. For additional details on session policy DDL and privileges, see Managing session policies.

See also