September 16, 2024

What Is Snowflake Create User?

Step-by-step guide on creating new users in Snowflake, including roles and access permissions.
Dexter Chu
Head of Marketing

Creating and managing user accounts in Snowflake is a critical task for database administrators. This guide will walk you through the process of creating users in Snowflake, including the necessary syntax, parameters, and best practices to ensure security and efficiency. Whether you are new to Snowflake or looking to refine your user management skills, this tutorial will provide you with the knowledge you need.

What is the Process for Creating a User in Snowflake?

Creating a user in Snowflake involves using the CREATE USER command, which allows administrators to define user accounts with specific properties and parameters. This command can be executed by users with the appropriate privileges, such as user administrators. Understanding the syntax and options available is essential for configuring user accounts to meet organizational requirements.

CREATE [ OR REPLACE ] USER [ IF NOT EXISTS ] <name>
[ objectProperties ]
[ objectParams ]
[ sessionParams ]
[ [ WITH ] TAG ( <tag_name> = ' <tag_value> ' [ , <tag_name> = ' <tag_value> ' , ... ] ) ]

This syntax provides flexibility in user creation, allowing for various configurations through optional properties and parameters. Below, we break down each component of the command:

What are the Required Parameters for Creating a User in Snowflake?

The only required parameter for creating a user in Snowflake is the name. This unique identifier must start with an alphabetic character and cannot contain spaces or special characters unless enclosed in double quotes. The name ensures that each user account is distinct within the Snowflake environment.

  • name: The unique identifier for the user within the Snowflake account. It must be unique and follow specific naming conventions.

What are the Optional Object Properties for Creating a User in Snowflake?

Optional object properties allow for additional customization of the user account. These properties include:

  • PASSWORD: The password for the user. Ensuring strong passwords is crucial for security.
  • LOGIN_NAME: The name that the user enters to log into the system. This can be different from the user name.
  • DISPLAY_NAME: The name displayed for the user in the Snowflake web interface.
  • FIRST_NAME, MIDDLE_NAME, LAST_NAME: User's first, middle, and last names for identification purposes.
  • EMAIL: User’s email address for communication and notifications.
  • MUST_CHANGE_PASSWORD: Specifies if the user must change their password on the next login, enhancing security.
  • DISABLED: Specifies if the user is disabled, useful for managing inactive accounts.
  • DAYS_TO_EXPIRY: Number of days after which the user status is set to “Expired” to enforce regular password changes.
  • MINS_TO_UNLOCK: Number of minutes until the temporary lock on the user login is cleared, useful for security measures.
  • DEFAULT_WAREHOUSE: The default virtual warehouse for the user's session upon login, streamlining user operations.
  • DEFAULT_NAMESPACE: The default namespace (database or database and schema) for the user's session upon login.

What are the Optional Object Parameters for Creating a User in Snowflake?

Optional object parameters control specific settings for the user. These parameters include:

  • ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR: TRUE or FALSE, controlling the visibility of query syntax errors.
  • NETWORK_POLICY: Specifies the network policy to restrict access to trusted networks only.

What are the Optional Session Parameters for Creating a User in Snowflake?

Session parameters control various aspects of the user's session behavior. Some of these parameters include:

  • ABORT_DETACHED_QUERY: Controls the behavior of detached queries.
  • AUTOCOMMIT: Determines if transactions are automatically committed.
  • BINARY_INPUT_FORMAT: Specifies the format for binary input.
  • DATE_INPUT_FORMAT: Specifies the format for date input.
  • TIMEZONE: Sets the user's timezone for session activities.
  • STATEMENT_TIMEOUT_IN_SECONDS: Sets the timeout for statements in seconds.

For a complete list of session parameters, refer to the Snowflake documentation.

Examples of Creating a User in Snowflake

Basic User Creation

CREATE USER john_doe
PASSWORD = 'StrongPassword123'
LOGIN_NAME = 'john_doe'
EMAIL = 'john.doe@example.com'
DISPLAY_NAME = 'John Doe';

This example demonstrates the creation of a basic user with essential properties such as password, login name, email, and display name.

User Creation with Optional Properties

CREATE USER jane_doe
PASSWORD = 'AnotherStrongPassword456'
LOGIN_NAME = 'jane_doe'
EMAIL = 'jane.doe@example.com'
DISPLAY_NAME = 'Jane Doe'
FIRST_NAME = 'Jane'
LAST_NAME = 'Doe'
MUST_CHANGE_PASSWORD = TRUE
DISABLED = FALSE
DEFAULT_WAREHOUSE = 'compute_wh'
DEFAULT_NAMESPACE = 'database.schema';

This example includes additional properties such as the user's first and last names, a requirement to change the password on the next login, and default settings for the warehouse and namespace.

User Creation with Object and Session Parameters

CREATE USER mike_smith
PASSWORD = 'YetAnotherStrongPassword789'
LOGIN_NAME = 'mike_smith'
EMAIL = 'mike.smith@example.com'
DISPLAY_NAME = 'Mike Smith'
FIRST_NAME = 'Mike'
LAST_NAME = 'Smith'
ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR = TRUE
NETWORK_POLICY = 'corp_network_policy'
SESSION TIMEZONE = 'America/Los_Angeles'
AUTOCOMMIT = TRUE;

This example demonstrates the creation of a user with both object and session parameters, providing a comprehensive configuration for the user account.

Best Practices for Creating Users in Snowflake

When creating users in Snowflake, it is essential to follow best practices to ensure security, efficiency, and maintainability.

  • Security Practices:
    • Use Strong Passwords: Ensure that the passwords set for users are strong and complex to prevent unauthorized access.
    • Enable MFA: Multi-Factor Authentication (MFA) adds an additional layer of security.
    • Set Password Expiry: Use the DAYS_TO_EXPIRY parameter to enforce regular password changes.
    • Network Policies: Specify network policies to restrict access to trusted networks only.
  • User Management:
    • Role-Based Access Control (RBAC): Assign roles to users based on their job functions to adhere to the principle of least privilege.
    • Disable Unused Accounts: Use the DISABLED parameter to disable accounts that are no longer in use.
    • Audit and Monitor: Regularly audit user activities and monitor for any suspicious behavior.
  • Efficiency and Maintenance:
    • Default Settings: Configure default settings such as DEFAULT_WAREHOUSE and DEFAULT_NAMESPACE to streamline user sessions.
    • Use Tags: Utilize tags for categorizing and managing users efficiently.

Step-by-Step Tutorial: Creating a User in Snowflake

1. Define the User Name

The first step in creating a user is to define the user name, which must be unique within the Snowflake account. This name serves as the primary identifier for the user.

CREATE USER john_doe;

This command creates a user with the name john_doe. At this stage, no additional properties or parameters are set.

2. Set a Password and Login Name

Next, set a password and login name for the user. These properties are essential for user authentication and access.

CREATE USER john_doe
PASSWORD = 'StrongPassword123'
LOGIN_NAME = 'john_doe';

This command sets a strong password and a login name for the user. The login name can be the same as the user name or different, depending on your preference.

3. Add Optional Properties

To enhance the user account, add optional properties such as email, display name, and default settings.

CREATE USER john_doe
PASSWORD = 'StrongPassword123'
LOGIN_NAME = 'john_doe'
EMAIL = 'john.doe@example.com'
DISPLAY_NAME = 'John Doe'
DEFAULT_WAREHOUSE = 'compute_wh'
DEFAULT_NAMESPACE = 'database.schema';

This command includes additional properties to provide a more comprehensive configuration for the user account.

4. Configure Object and Session Parameters

For advanced user management, configure object and session parameters to control specific settings and behaviors.

CREATE USER john_doe
PASSWORD = 'StrongPassword123'
LOGIN_NAME = 'john_doe'
EMAIL = 'john.doe@example.com'
DISPLAY_NAME = 'John Doe'
ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR = TRUE
NETWORK_POLICY = 'corp_network_policy'
SESSION TIMEZONE = 'America/Los_Angeles'
AUTOCOMMIT = TRUE;

This command demonstrates the inclusion of both object and session parameters, providing a detailed configuration for the user account.

Common Challenges and Solutions

While creating users in Snowflake, administrators may encounter common challenges or errors. Here are some solutions to address these issues:

  • Duplicate User Name: Ensure that the user name is unique within the Snowflake account. Use the IF NOT EXISTS clause to avoid conflicts.
  • Weak Passwords: Enforce strong password policies to enhance security. Use the MUST_CHANGE_PASSWORD parameter to require users to set a new password upon first login.
  • Network Restrictions: Configure network policies to restrict access to trusted networks only, reducing the risk of unauthorized access.

Recap of Creating Users in Snowflake

Creating users in Snowflake is a straightforward yet highly customizable process. Key takeaways from this tutorial include:

  • Understanding the Syntax: Familiarize yourself with the CREATE USER command syntax and its components to effectively create and manage user accounts.
  • Utilizing Optional Properties and Parameters: Leverage optional properties and parameters to tailor user accounts to meet specific requirements and enhance security.
  • Following Best Practices: Adhere to best practices for security, user management, and efficiency to maintain a robust and secure Snowflake environment.

By applying these principles, administrators can ensure that user accounts are configured correctly, securely, and efficiently, contributing to the overall success of their Snowflake implementation.

Keep reading

View all