CREATE SECRET¶
Creates a new secret in the current or specified schema or replaces an existing secret.
This command supports the following variants:
- CREATE OR ALTER SECRET: Creates a secret if it doesn’t exist or alters an existing secret.
- DEFINE SECRET: Declarative definition of a secret inside a DCM project.
- See also:
Syntax¶
OAuth with client credentials flow:
OAuth with authorization code grant flow:
Cloud provider:
Basic authentication:
Generic string:
Symmetric key:
Workload identity federation:
Variant syntax¶
CREATE OR ALTER SECRET¶
Creates a new secret if it doesn’t already exist, or transforms an existing secret into the secret defined in the statement. A CREATE OR ALTER SECRET statement follows the syntax rules of a CREATE SECRET statement and has the same limitations as an ALTER SECRET statement.
CREATE OR ALTER SECRET supports the same secret types and properties as CREATE SECRET. For the properties of each type, see
Syntax. Write CREATE OR ALTER SECRET <name> in place of CREATE [ OR REPLACE ] SECRET [ IF NOT EXISTS ] <name>.
For more information, see CREATE OR ALTER SECRET usage notes and CREATE OR ALTER <object>.
DEFINE SECRET¶
DCM Projects uses DEFINE SECRET statements to create and manage secrets declaratively inside a DCM project. A DEFINE SECRET
statement uses the same syntax as CREATE OR ALTER SECRET, with the keyword DEFINE in
place of CREATE OR ALTER, for the following secret types: GENERIC_STRING, PASSWORD, OAUTH2, and CLOUD_PROVIDER_TOKEN.
You can use DEFINE SECRET only inside DCM project definition files, not as standalone SQL.
To learn more about DCM Projects, see Secret.
Supply the values of sensitive properties, such as SECRET_STRING, PASSWORD, and OAUTH_REFRESH_TOKEN, through
environment secrets rather
than as plain-text literals. For example:
OAuth with client credentials flow required parameters¶
nameString that specifies the identifier (that is, the name) for the secret. It must be unique in your schema.
In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example,
"My object"). Identifiers enclosed in double quotes are also case-sensitive.For more details, see Identifier requirements.
TYPE = OAUTH2Specifies a secret to use with an OAuth grant flow.
API_AUTHENTICATION = security_integration_nameSpecifies the
namevalue of the Snowflake security integration that connects Snowflake to an external service.OAUTH_SCOPES = ( 'scope_1' [ , 'scope_2' ... ] )Specifies a comma-separated list of scopes to use when making a request from the OAuth server by a role with USAGE on the integration during the OAuth client credentials flow.
This list must be a subset of the scopes defined in the
OAUTH_ALLOWED_SCOPESproperty of the security integration. If theOAUTH_SCOPESproperty values are not specified, the secret inherits all of the scopes that are specified in the security integration.For the ServiceNow connector, the only possible scope value is
'useraccount'.
OAuth with authorization code grant flow required parameters¶
nameString that specifies the identifier (that is, the name) for the secret. It must be unique in your schema.
In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example,
"My object"). Identifiers enclosed in double quotes are also case-sensitive.For more details, see Identifier requirements.
TYPE = OAUTH2Specifies a secret to use with the OAuth grant flow.
OAUTH_REFRESH_TOKEN = 'string_literal'Specifies the token as a string that is used to obtain a new access token from the OAuth authorization server when the access token expires.
OAUTH_REFRESH_TOKEN_EXPIRY_TIME = 'string_literal'Specifies the timestamp as a string when the OAuth refresh token expires.
API_AUTHENTICATION = security_integration_nameSpecifies the
namevalue of the Snowflake security integration that connects Snowflake to an external service.
AWS IAM required parameters¶
TYPE = CLOUD_PROVIDER_TOKENSpecifies that this is a secret for use with a cloud provider, such as Amazon Web Services (AWS).
API_AUTHENTICATION = 'cloud_provider_security_integration'Specifies the
namevalue of the Snowflake security integration that connects Snowflake to a cloud provider.
Basic authentication required parameters¶
nameString that specifies the identifier (that is, the name) for the secret. It must be unique in your schema.
In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example,
"My object"). Identifiers enclosed in double quotes are also case-sensitive.For more details, see Identifier requirements.
TYPE = PASSWORDSpecifies a secret to use with basic authentication.
When specifying this type you must specify values for the username and password properties.
USERNAME = 'username'Specifies the username value to store in the secret.
Specify this value when setting the
TYPEvalue toPASSWORDfor use with basic authentication.PASSWORD = 'password'Specifies the password value to store in the secret.
Specify this value when setting the
TYPEvalue toPASSWORDfor use with basic authentication.
Generic string parameters¶
nameString that specifies the identifier (that is, the name) for the secret. It must be unique in your schema.
In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example,
"My object"). Identifiers enclosed in double quotes are also case-sensitive.For more details, see Identifier requirements.
TYPE = GENERIC_STRINGSpecifies a secret to store a sensitive string value.
SECRET_STRING = 'string_literal'Specifies the string to store in the secret.
The string can be an API token or a sensitive string value that can be used in the handler code of a UDF or stored procedure. For details, see Creating and using an external access integration.
You should not use this property to store any kind of OAuth token; use one of the other secret types for your OAuth use cases.
Symmetric key parameters¶
Symmetric key secrets generate a cryptographic key that can be used for cryptographic operations. It’s currently used only to generate synthetic data.
ALGORITHMSpecifies which algorithm to use to generate the symmetric key. The only value supported is
GENERIC, which generates a 256-bit key.
Workload identity federation parameters¶
nameString that specifies the identifier (that is, the name) for the secret. It must be unique in your schema.
In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example,
"My object"). Identifiers enclosed in double quotes are also case-sensitive.For more details, see Identifier requirements.
TYPE = WORKLOAD_IDENTITY_FEDERATIONSpecifies a secret that lets a Snowflake workload authenticate to an external service using workload identity federation, with Snowflake acting as the OpenID Connect (OIDC) provider. When you create the secret, Snowflake stores the issuer URL and the subject identifier of the workload as properties of the secret.
For more information, see Workload identity federation for Snowflake workloads that access external services.
Optional parameters¶
COMMENT = 'string_literal'String (literal) that specifies a comment for the secret.
Default: No value
Access control requirements¶
A role used to execute this operation must have the following privileges at a minimum:
| Privilege | Object | Notes |
|---|---|---|
| CREATE SECRET | Schema | |
| USAGE | Database or schema | |
| OWNERSHIP | Secret | Required only when executing a CREATE OR ALTER SECRET statement for an existing secret. |
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.
Usage notes¶
- The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement.
-
CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.
-
Regarding metadata:
Attention
Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.
CREATE OR ALTER SECRET usage notes¶
- All limitations of the ALTER SECRET command apply.
Examples¶
OAuth with client credentials¶
Create a secret for use with the OAuth client credentials flow:
OAuth with authorization code grant¶
Create a secret for use with the OAuth code grant flow:
AWS IAM¶
Create a secret for use with Amazon Web Services (AWS) by including the AWS IAM ARN for authentication:
Basic authentication¶
Create a secret that specifies a username and password to access ServiceNow:
Workload identity federation¶
Create a secret that lets a Snowflake workload authenticate to external services using workload identity federation:
Create and alter a secret using the CREATE OR ALTER SECRET command¶
Create a generic string secret my_api_key:
Alter the secret my_api_key to store a new value and add a comment: