Snowflake SQL Tutorial 163 - Snowflake Let Me Point A User At A Role That Does Not Exist

Snowflake SQL · Episode 163

In this post we are going to cover users in Snowflake.

A user in Snowflake is two names and forty-four properties. The two names are the one you look the user up by and the one the user signs in with, and they are not interchangeable. Most of the properties you will never set.

We will start with the smallest user it is possible to make, read every property it has, and build up from there. Along the way Snowflake will let us point a user at a role that does not exist and tell us the statement succeeded.

No passwords are set anywhere in this post. Every user below is created disabled and dropped again at the end, so none of them can sign in.

Every query below was run on a real Snowflake account, and every result you see is the output it gave back, refusals included.

Episode 163 of the Snowflake SQL: Zero to Hero series on TechBrothersIT.

Let's start by reading the user that is already there

Before making anything, it is worth reading the user we are signed in as, so we know what state we have to leave it in.

Setup
-- Setup for this post.
-- No passwords anywhere in this episode. Every user below is created
-- DISABLED and dropped again at the end, so none of them can sign in.
USE ROLE ACCOUNTADMIN;
USE DATABASE DEMO_DB;

-- A role for one of them to point a DEFAULT_ROLE at.
CREATE OR REPLACE ROLE RDEF_T163
  COMMENT = 'episode 163 - a role to point a DEFAULT_ROLE at';
Query
SHOW USERS;

DESCRIBE USER YOUR_USER;

Those two grids are not on this page. Every row of them carries the account's own user name, its login name and its email address, and the builder here cannot leave a column out of a grid, so the whole grid is left out instead. Run them on your own account and read your own.

Everything from here on is a user this post created and dropped again.

Now let's make the smallest user we can

A name, a comment, and disabled. That is all.

Query
CREATE OR REPLACE USER U_T163
  DISABLED = TRUE
  COMMENT  = 'episode 163 - the smallest user, disabled, no password';
Result1 row · 1 column
status
User U_T163 successfully created.

And here it is in the catalogue.

Query
SELECT "name", "login_name", "display_name", "disabled", "default_role",
       "default_warehouse", "has_password", "has_rsa_public_key", "comment"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 9 columns · scroll →
namelogin_namedisplay_namedisableddefault_roledefault_warehousehas_passwordhas_rsa_public_keycomment
U_T163U_T163U_T163trueNULLNULLfalsefalseepisode 163 - the smallest user, disabled, no password

Disabled true, no default role, no default warehouse, no password, and the login name has been filled in for us from the name.

The grey NULL cells in that grid are real SQL nulls, because that grid came from SHOW USERS. Keep that in mind for the next section, where the same information is written a different way.

Now let's describe it and count what comes back

DESCRIBE USER gives one row per property, with the value and the default side by side.

Query
DESCRIBE USER U_T163;
Result44 rows · 4 columns
Every property a user has, on a user defined in three lines
propertyvaluedefaultdescription
NAMEU_T163nullName
COMMENTepisode 163 - the smallest user, disabled, no passwordnulluser comment associated to an object in the dictionary
DISPLAY_NAMEU_T163nullDisplay name of the associated object
TYPEPERSONnullType of the account, application package, data exchange, data exchange listing, replication group, secret, network rule, user, or cortex extension.
LOGIN_NAMEU_T163nullLogin name of the user
FIRST_NAMEnullnullFirst name of the user
MIDDLE_NAMEnullnullMiddle name of the user
LAST_NAMEnullnullLast name of the user
EMAILnullnullEmail address of the user
PASSWORDnullnullPassword of the user
MUST_CHANGE_PASSWORDfalsefalseUser must change the password
DISABLEDtruefalseWhether the entity is disabled
SNOWFLAKE_LOCKfalsefalseWhether the user, account, or organization is locked by Snowflake
SNOWFLAKE_SUPPORTfalsefalseSnowflake Support is allowed to use the user or account
DAYS_TO_EXPIRYnullnullUser record will be treated as expired after specified number of days
MINS_TO_UNLOCKnullnullTemporary lock on the user will be removed after specified number of minutes
DEFAULT_WAREHOUSEnullnullDefault warehouse
DEFAULT_NAMESPACEnullnullDefault database namespace prefix for this user
DEFAULT_ROLEnullnullPrimary principal of user session will be set to this role
DEFAULT_SECONDARY_ROLES["ALL"][ALL]The secondary roles will be set to all roles provided here.
EXT_AUTHN_DUOfalsefalseWhether Duo Security is enabled as second factor authentication
EXT_AUTHN_UIDnullnullExternal authentication ID of the user
DEFAULT_MFA_METHODnullnullDefault MFA method for the user
HAS_MFAfalsefalseWhether the user is enrolled in multi-factor authentication
HAS_PATfalsefalseWhether the user has a programmatic access token
HAS_WORKLOAD_IDENTITYfalsefalseWhether the user has workload identity defined
HAS_KEYPAIRfalsefalseWhether the user has a key pair
IS_EMAIL_VERIFIEDfalsefalseWhether the user's email address has been verified
MINS_TO_BYPASS_MFAnullnullTemporary bypass MFA for the user for a specified number of minutes
MINS_TO_BYPASS_NETWORK_POLICYnullnullTemporary bypass network policy on the user for a specified number of minutes
RSA_PUBLIC_KEYnullnullRSA public key of the user
RSA_PUBLIC_KEY_FPnullnullFingerprint of user's RSA public key.
RSA_PUBLIC_KEY_LAST_SET_TIMEnullnullThe timestamp at which the RSA public key was last set for the user. Defaults to null if no RSA public key has been set yet.
RSA_PUBLIC_KEY_2nullnullSecond RSA public key of the user
RSA_PUBLIC_KEY_2_FPnullnullFingerprint of user's second RSA public key.
RSA_PUBLIC_KEY_2_LAST_SET_TIMEnullnullThe timestamp at which the second RSA public key was last set for the user. Defaults to null if no second RSA public key has been set yet.
SCIM_USER_NAMEnullnullUser name of an user (required for SCIM provisioning)
PASSWORD_LAST_SET_TIMEnullnullThe timestamp on which the last non-null password was set for the user. Default to null if no password has been set yet.
MINS_TO_BYPASS_SESSION_POLICYnullnullTemporarily bypass session policy for the given number of minutes.
CUSTOM_LANDING_PAGE_URLnullnullCustom Landing Page of the user
CUSTOM_LANDING_PAGE_URL_FLUSH_NEXT_UI_LOADfalsefalseWhether or not to flush the custom landing page of the user on next UI load
IS_FROM_ORGANIZATION_USERfalsefalseWhether the user is imported from an organization user.
ALLOWED_INTERFACES[ALL]nullList of interfaces this user is allowed to access. Must be provided as a list: ('ALL'), ('SNOWFLAKE_INTELLIGENCE', 'STREAMLIT')
LOCK_DETAILS{"isAdminLocked":false,"isMfaLocked":false,"isMfaOTPLocked":false,"isMfaTOTPLocked":false,"isPasswordLocked":false,"isSnowflakeLocked":false}nullDetails about why the user is locked, if the user is locked.

Let's have Snowflake count that grid rather than counting it by eye.

Query
SELECT COUNT(*) AS PROPERTY_COUNT
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
PROPERTY_COUNT
44

Forty-four properties. And here is how many of them are still sitting at their default value.

Query
SELECT COUNT(*) AS AT_DEFAULT
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "value" = "default";
Result1 row · 1 column
AT_DEFAULT
35

Thirty-five. So most of what a user is, we did not write, on a user we defined in three lines.

That null is a word, not a NULL

Look carefully at the lower-case null in that grid, in both the value and the default column. That is not a SQL NULL rendered in lower case. DESCRIBE USER puts the four characters null into a property that has no value, as text. The grids on this page are full of those cells, and they are shown here as the text they are rather than as the grey NULL you saw in the SHOW USERS grid above. Compare the two and the difference is on screen.

Let's pull out the identity properties on their own.

Query
SELECT "property", "value", "default"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "property" IN ('NAME','LOGIN_NAME','DISPLAY_NAME','FIRST_NAME',
                      'LAST_NAME','EMAIL','COMMENT')
 ORDER BY "property";
Result7 rows · 3 columns
propertyvaluedefault
COMMENTepisode 163 - the smallest user, disabled, no passwordnull
DISPLAY_NAMEU_T163null
EMAILnullnull
FIRST_NAMEnullnull
LAST_NAMEnullnull
LOGIN_NAMEU_T163null
NAMEU_T163null

Email, first name and last name are all the text null, because we set none of them. The display name and the login name were filled in from the name.

And now the group that decides what the user can actually do.

Query
SELECT "property", "value", "default"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "property" IN ('DISABLED','DEFAULT_ROLE','DEFAULT_WAREHOUSE',
                      'DEFAULT_NAMESPACE','DEFAULT_SECONDARY_ROLES',
                      'MUST_CHANGE_PASSWORD','TYPE')
 ORDER BY "property";
Result7 rows · 3 columns
propertyvaluedefault
DEFAULT_NAMESPACEnullnull
DEFAULT_ROLEnullnull
DEFAULT_SECONDARY_ROLES["ALL"][ALL]
DEFAULT_WAREHOUSEnullnull
DISABLEDtruefalse
MUST_CHANGE_PASSWORDfalsefalse
TYPEPERSONnull

No default role, no default warehouse, no default namespace, type PERSON, and disabled true against a default of false.

Then look at the third row. DEFAULT_SECONDARY_ROLES comes back as ["ALL"] on a brand new user, without our asking for it, and the default column agrees.

The default that catches tests out

That setting is why every role test in this part of the course has to switch the secondary roles off before it proves anything. A user arrives with all of their roles enabled, so USE ROLE on its own never narrows a session down to one role. It invalidated three earlier tests in this level before anybody noticed.

Now a user whose login name is not its name

The name and the login name are two different properties doing two different jobs. Let's set them deliberately apart.

Query
CREATE OR REPLACE USER UMIN_T163
  DISABLED   = TRUE
  LOGIN_NAME = 'signs_in_as_this_T163'
  COMMENT    = 'episode 163 - name and login name are different things';
Result1 row · 1 column
status
User UMIN_T163 successfully created.
Query
SELECT "name", "login_name", "display_name", "disabled"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
namelogin_namedisplay_namedisabled
UMIN_T163SIGNS_IN_AS_THIS_T163UMIN_T163true

Two different strings, and both of them real. The user is called one thing and signs in as the other.

So let's look it up by the string it signs in with

Query
SHOW USERS LIKE 'signs\\_in\\_as\\_this\\_T163';
Result0 rows · 32 columns · scroll →
namecreated_onlogin_namedisplay_namefirst_namelast_nameemailmins_to_unlockdays_to_expirycommentdisabledmust_change_passwordsnowflake_lockdefault_warehousedefault_namespacedefault_roledefault_secondary_rolesext_authn_duoext_authn_uidmins_to_bypass_mfaownerlast_success_loginexpires_at_timelocked_until_timehas_passwordhas_rsa_public_keytypehas_mfahas_pathas_workload_identityallowed_interfacesis_from_organization_user

No rows. Counted, to be sure:

Query
SELECT COUNT(*) AS MATCHED_BY_LOGIN_NAME
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
MATCHED_BY_LOGIN_NAME
0

Zero. The user exists, and that really is the string it authenticates with, and the catalogue cannot find it that way.

SHOW USERS LIKE matches the name. So if somebody hands you a login that is not working, searching for it finds nothing at all, and nothing tells you that you searched the wrong column.

Here are the three name properties side by side, which is the clearest way to keep them straight.

Query
SELECT "property", "value", "default"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "property" IN ('NAME','LOGIN_NAME','DISPLAY_NAME')
 ORDER BY "property";
Result3 rows · 3 columns
propertyvaluedefault
DISPLAY_NAMEUMIN_T163null
LOGIN_NAMESIGNS_IN_AS_THIS_T163null
NAMEUMIN_T163null

And what does a rename move?

There are two names. Let's rename the user and see which one follows.

Query
ALTER USER UMIN_T163 RENAME TO UMIN2_T163;
Result1 row · 1 column
status
Statement executed successfully.

First, is the old name gone?

Query
SELECT COUNT(*) AS OLD_NAME_ROWS
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
OLD_NAME_ROWS
0

Zero. Nothing answers to the old name any more. And the new one?

Query
SELECT "name", "login_name", "display_name", "disabled"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
namelogin_namedisplay_namedisabled
UMIN2_T163SIGNS_IN_AS_THIS_T163UMIN_T163true

The name moved. The login name did not.

So renaming a user does not change how they sign in. That is either a relief or a trap, depending entirely on why you renamed them. Let's put the name back and carry on.

Query
ALTER USER UMIN2_T163 RENAME TO UMIN_T163;
Result1 row · 1 column
status
Statement executed successfully.

Now let's point a user at things that are not there

This is the part of the episode I would put on a poster. Let's set the default role to a role name I have just invented.

Query
ALTER USER U_T163 SET DEFAULT_ROLE = ROLE_THAT_DOES_NOT_EXIST_T163;
Result1 row · 1 column
status
Statement executed successfully.

Statement executed successfully. Let's read it back.

Query
SELECT "name", "default_role", "disabled"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
namedefault_roledisabled
U_T163ROLE_THAT_DOES_NOT_EXIST_T163true

The user is carrying it. The string went in exactly as it was typed, with no warning and no check.

And the same for a warehouse.

Query
ALTER USER U_T163 SET DEFAULT_WAREHOUSE = WH_THAT_DOES_NOT_EXIST_T163;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "name", "default_role", "default_warehouse"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
namedefault_roledefault_warehouse
U_T163ROLE_THAT_DOES_NOT_EXIST_T163WH_THAT_DOES_NOT_EXIST_T163

So that user now names two things, and neither of them exists on the account.

Here is why that is allowed, and it is not a bug

Let's make one more user, this time with every property we are willing to set, including a DEFAULT_ROLE that really does exist.

Query
CREATE OR REPLACE USER UFULL_T163
  DISABLED          = TRUE
  LOGIN_NAME        = 'ufull_login_T163'
  DISPLAY_NAME      = 'Episode 163 Demo User'
  FIRST_NAME        = 'Demo'
  LAST_NAME         = 'User'
  EMAIL             = 'demo.user@example.com'
  DEFAULT_ROLE      = RDEF_T163
  DEFAULT_NAMESPACE = 'DEMO_DB.PUBLIC'
  COMMENT           = 'episode 163 - every property I am willing to set';
Result1 row · 1 column
status
User UFULL_T163 successfully created.
Query
SHOW USERS LIKE 'UFULL\\_T163';
Result1 row · 32 columns · scroll →
Created with a default role that really is there
namecreated_onlogin_namedisplay_namefirst_namelast_nameemailmins_to_unlockdays_to_expirycommentdisabledmust_change_passwordsnowflake_lockdefault_warehousedefault_namespacedefault_roledefault_secondary_rolesext_authn_duoext_authn_uidmins_to_bypass_mfaownerlast_success_loginexpires_at_timelocked_until_timehas_passwordhas_rsa_public_keytypehas_mfahas_pathas_workload_identityallowed_interfacesis_from_organization_user
UFULL_T1632026-10-06 12:21:30.137000-07:00UFULL_LOGIN_T163Episode 163 Demo UserDemoUserdemo.user@example.comNULLNULLepisode 163 - every property I am willing to settruefalsefalseNULLDEMO_DB.PUBLICRDEF_T163["ALL"]falseNULLNULLACCOUNTADMINNULLNULLNULLfalsefalsePERSONfalsefalsefalse[ALL]false

Nine properties set, all of them in that one statement, and still disabled with no password. Now let's ask what roles that user actually holds.

Query
SHOW GRANTS TO USER UFULL_T163;
Result0 rows · 9 columns · scroll →
created_onprivilegegranted_onnamerolegranted_tograntee_namegrant_optiongranted_by

No rows. A default role is not a grant. It is a preference about which role to put on when the user arrives, and writing it down gives the user nothing.

The grant is a separate statement.

Query
GRANT ROLE RDEF_T163 TO USER UFULL_T163;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "role", "granted_to", "grantee_name", "granted_by"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
rolegranted_tograntee_namegranted_by
RDEF_T163USERUFULL_T163ACCOUNTADMIN

One row now: the role, granted to a user, the user it was granted to, and who granted it.

And that user is disabled the whole time. Those two facts sit in different columns and neither one affects the other.

Query
SELECT "name", "disabled", "default_role"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
namedisableddefault_role
UFULL_T163trueRDEF_T163
A preference, not a grant

So DEFAULT_ROLE accepting a name that does not exist is consistent: it is a preference, not an authorisation, and preferences are not checked against the catalogue. It is still worth knowing, because the user who cannot log in properly next month will have this written on them and nothing will say it is the reason.

Now let's set some properties and unset them again

First, put that user back to something real and clear the warehouse out entirely.

Query
ALTER USER U_T163 SET DEFAULT_ROLE = PUBLIC;
Result1 row · 1 column
status
Statement executed successfully.
Query
ALTER USER U_T163 UNSET DEFAULT_WAREHOUSE;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "name", "default_role", "default_warehouse", "disabled"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
namedefault_roledefault_warehousedisabled
U_T163PUBLICNULLtrue

Default role PUBLIC, default warehouse back to a real SQL null, still disabled. Tidy again.

Now let's set two properties in one statement and read both back.

Query
ALTER USER U_T163 SET
  COMMENT = 'episode 163 - altered once',
  EMAIL   = 'altered@example.com';
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "name", "email", "comment", "disabled"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 4 columns
nameemailcommentdisabled
U_T163altered@example.comepisode 163 - altered oncetrue

Both landed. Now let's unset just the email.

Query
ALTER USER U_T163 UNSET EMAIL;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "name", "email", "comment"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
nameemailcomment
U_T163NULLepisode 163 - altered once

The email is back to null and the comment is untouched. UNSET takes exactly what you name and nothing else.

And after all that, is the user still disabled?

Query
SELECT "property", "value", "default"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "property" = 'DISABLED';
Result1 row · 3 columns
propertyvaluedefault
DISABLEDtruefalse

true, against a default of false. Nothing we did woke that user up.

What happens when a name clashes?

Two ways a name goes wrong, and they are two different errors.

A name that already exists

Query
CREATE USER U_T163 DISABLED = TRUE;
Query failed — Snowflake returned an error
002002 (42710): SQL compilation error:
Object 'U_T163' already exists.

002002, naming the object. Now the same statement with IF NOT EXISTS, and a comment in it that we have not used before.

Query
CREATE USER IF NOT EXISTS U_T163 DISABLED = TRUE
  COMMENT = 'episode 163 - this comment should NOT appear';
Result1 row · 1 column
status
U_T163 already exists, statement succeeded.

Already exists, statement succeeded. So let's see what happened to the comment.

Query
SELECT "name", "comment", "disabled"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 3 columns
namecommentdisabled
U_T163episode 163 - altered oncetrue

It is still the comment the earlier ALTER set. The comment in the CREATE USER IF NOT EXISTS was ignored, silently.

That is the useful half of this. IF NOT EXISTS does not mean create or update. If the object is there, the whole statement is skipped and every option in it goes with it.

A login name that belongs to somebody else

Query
CREATE OR REPLACE USER UCLASH_T163
  DISABLED   = TRUE
  LOGIN_NAME = 'ufull_login_T163';
Query failed — Snowflake returned an error
003006 (42710): SQL compilation error:
User with login name 'UFULL_LOGIN_T163' already exists.

A different code, 003006, and a different sentence: a user with that login name already exists. So login names are unique across the account, the same as names are, and the two clashes are reported separately.

And dropping a user that is not there

A plain DROP USER on a name that does not exist is refused. That refusal is not on this page: its message quotes the account locator, and an error pane here is printed exactly as it was captured and never edited, so it is left out rather than trimmed.

Query
DROP USER NO_SUCH_USER_T163;

With IF EXISTS it is a no-op, and the status line says so in a nice way.

Query
DROP USER IF EXISTS NO_SUCH_USER_T163;
Result1 row · 1 column
status
Drop statement executed successfully (NO_SUCH_USER_T163 already dropped).

A user has parameters as well as properties

Properties are what the user is. Parameters are session settings that apply to it, and there are rather a lot of them.

Query
SHOW PARAMETERS IN USER U_T163;
Query
SELECT COUNT(*) AS PARAMETER_COUNT
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
Result1 row · 1 column
PARAMETER_COUNT
180

A hundred and eighty. Let's look at five of them, and read the level column.

Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "key" IN ('TIMEZONE','WEEK_START','QUERY_TAG','AUTOCOMMIT',
                 'STATEMENT_TIMEOUT_IN_SECONDS')
 ORDER BY "key";
Result5 rows · 4 columns
keyvaluedefaultlevel
AUTOCOMMITtruetrue
QUERY_TAG
STATEMENT_TIMEOUT_IN_SECONDS172800172800
TIMEZONEAmerica/Los_AngelesAmerica/Los_Angeles
WEEK_START00

The level column is empty on all five, and the value matches the default in every row. Empty level means nobody set it here. Every parameter on that user is inherited from above it.

Now let's set one on the user and look again.

Query
ALTER USER U_T163 SET TIMEZONE = 'Asia/Karachi';
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "key" = 'TIMEZONE';
Result1 row · 4 columns
keyvaluedefaultlevel
TIMEZONEAsia/KarachiAmerica/Los_AngelesUSER

The value is ours, the default is still the account's, and level now reads USER. Same column and same meaning as on a warehouse, several levels back in this course.

And unset it.

Query
ALTER USER U_T163 UNSET TIMEZONE;
Result1 row · 1 column
status
Statement executed successfully.
Query
SELECT "key", "value", "default", "level"
  FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()))
 WHERE "key" = 'TIMEZONE';
Result1 row · 4 columns
keyvaluedefaultlevel
TIMEZONEAmerica/Los_AngelesAmerica/Los_Angeles

Back to the default, empty level, and no record anywhere that we were ever there.

One last thing: authentication policies

How a user is allowed to authenticate is a separate object with its own properties. Let's make one with a single method.

Query
CREATE OR REPLACE AUTHENTICATION POLICY AUTHPOL_T163
  AUTHENTICATION_METHODS = ('PASSWORD')
  MFA_ENROLLMENT         = 'OPTIONAL'
  COMMENT                = 'episode 163 - created, read, dropped, APPLIED TO NOTHING';
Result1 row · 1 column
status
Authentication policy 'AUTHPOL_T163' created successfully

And describe it.

Query
DESCRIBE AUTHENTICATION POLICY AUTHPOL_T163;
Result11 rows · 4 columns
propertyvaluedefaultdescription
NAMEAUTHPOL_T163nullName of authentication policy.
OWNERACCOUNTADMINnullOwner of authentication policy.
COMMENTepisode 163 - created, read, dropped, APPLIED TO NOTHINGnullComment associated with authentication policy.
AUTHENTICATION_METHODS[PASSWORD][ALL]Authentication methods that are allowed for usage.
CLIENT_TYPES[ALL][ALL]Client types that are allowed for access.
CLIENT_POLICY{}nullClient policy for the authentication policy.
SECURITY_INTEGRATIONS[ALL][ALL]Security integrations that are allowed for authentication.
MFA_ENROLLMENTOPTIONALOPTIONALWhen set to REQUIRED, force a user to enroll in MFA according to the MFA_AUTHENTICATION_METHODS. Allowed values are REQUIRED | OPTIONAL
MFA_POLICY{ALLOWED_METHODS=[ALL], ENFORCE_MFA_ON_EXTERNAL_AUTHENTICATION=NONE}{ALLOWED_METHODS=[ALL], ENFORCE_MFA_ON_EXTERNAL_AUTHENTICATION=NONE}MFA-specific configuration for the authentication policy.
PAT_POLICY{DEFAULT_EXPIRY_IN_DAYS=15, MAX_EXPIRY_IN_DAYS=365, NETWORK_POLICY_EVALUATION=ENFORCED_REQUIRED, REQUIRE_ROLE_RESTRICTION_FOR_SERVICE_USERS=true, REQUIRE_ROLE_RESTRICTION_FOR_PERSON_USERS=false, BLOCKED_ROLES_LIST=[]}nullPAT-specific configuration for the authentication policy.
WORKLOAD_IDENTITY_POLICY{ALLOWED_PROVIDERS=[ALL], ALLOWED_AWS_ACCOUNTS=[ALL], ALLOWED_AWS_PARTITIONS=[ALL], ALLOWED_AZURE_ISSUERS=[ALL], ALLOWED_OIDC_ISSUERS=[ALL]}nullWorkload identity-specific configuration for the authentication policy.

Eleven properties. The method list is ours, the MFA enrolment is optional, and look at the PAT_POLICY row: a programmatic access token policy arrives fully filled in, with its own default expiry and its own rules, without our writing a word of it.

This policy was applied to nothing. It was created, read and dropped.

And a method that is not a method

Query
CREATE OR REPLACE AUTHENTICATION POLICY BADPOL_T163
  AUTHENTICATION_METHODS = ('TELEPATHY');
Query failed — Snowflake returned an error
003618 (22023): SQL Compilation Error: TELEPATHY invalid for Authentication Methods.

003618, and it names exactly what it did not like. A closed list, and the refusal quotes the word we got wrong back at us.

Query
SHOW AUTHENTICATION POLICIES LIKE 'BADPOL\\_T163';
Result0 rows · 9 columns · scroll →
created_onnamedatabase_nameschema_namekindownercommentowner_role_typeoptions

No rows, so nothing was half made.

Everything above was created by this post and dropped again afterwards.

Teardown
-- Putting the account back.
USE ROLE ACCOUNTADMIN;

DROP USER IF EXISTS U_T163;
DROP USER IF EXISTS UMIN_T163;
DROP USER IF EXISTS UFULL_T163;
DROP ROLE IF EXISTS RDEF_T163;
DROP AUTHENTICATION POLICY IF EXISTS AUTHPOL_T163;

-- And then the real account user is described once more, read and never
-- written, to prove nothing here touched it.
DESCRIBE USER YOUR_USER;

That last DESCRIBE USER is the account's real user, read and never written, and its grid is not on this page for the same reason as the one at the top.

Key points

  • DESCRIBE USER gives forty-four properties, and on a user defined in three lines, thirty-five of them were still at their default.
  • An unset property comes back as the text null, not as a SQL NULL. SHOW USERS gives real nulls for the same information.
  • DEFAULT_SECONDARY_ROLES is ["ALL"] on a brand new user, which is why role tests have to switch the secondary roles off.
  • A user has a name and a login name, and SHOW USERS LIKE matches the name.
  • So looking a user up by the string it signs in with finds nothing, and nothing says you searched the wrong column.
  • RENAME moves the name only. The login name is untouched.
  • DEFAULT_ROLE will accept a role that does not exist, and the statement succeeds.
  • Because a default role is a preference, not a grant. SHOW GRANTS TO USER was empty until a separate GRANT ROLE ran.
  • A user can hold a role and be disabled at the same time. Different columns, no interaction.
  • CREATE USER IF NOT EXISTS skips the whole statement, so every option in it is ignored, silently.
  • A name clash is 002002. A login name clash is 003006.
  • A user also has a hundred and eighty parameters, and the level column tells you whether anybody set one here.
Next in this series

In the next post we will look at network policies: the difference between a rule and the list that uses it, and what happens when you point a policy at an address range that does not do what you think.

Every query and every result grid on this page was captured from a live Snowflake account (version 10.36.101) running the demo script for this episode. The three users it creates are all created DISABLED, no password or key is set on any of them, and all three are dropped at the end. The authentication policy was created, read and applied to nothing. The account's own user is read and never written, and every grid that carries that user's details, or the account locator, is left off the page rather than edited, with the statement shown instead. Nothing is timed and no performance claims are made anywhere in this series. Behaviour follows the Snowflake CREATE USER documentation.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.