Connect to a Git repository over a public network

You can set up Snowflake to access your Git repository over a public network. If your Git server uses IP-based allowlisting, see Securing ingress of Snowflake requests with egress IP addresses to configure stable egress IPs for Snowflake Git traffic.

To connect to a Git repository over a public network, complete the following steps:

  1. Configure an API integration for one of the following authentication methods:

    • Authenticate through an OAuth flow.

      Configure an API integration to allow for an OAuth2 flow.

    • Authenticate with a token, such as a personal access token.

      Configure a secret containing the username and token to use, then configure an API integration that allows Snowflake to use the secret when authenticating.

    • No authentication.

      Configure an API integration with details about the Git repository server.

  2. Create a Git workspace connected to the repository. In a Git workspace, you can create and edit files, manage branches, pull changes, and commit and push changes to the remote repository.

If Snowflake code such as tasks or stored procedures needs to reference repository files, you can also create a Git repository clone. A Git repository clone is a read-only object that’s owned by a role.

Configure for authenticating with OAuth

Diagram showing components needed to configure Git connection with OAuth authentication

You can configure Snowflake to authenticate with the remote Git repository using an OAuth2 flow.

The Snowflake GitHub App is a pre-configured OAuth2 application that simplifies authentication. You don’t need to register an OAuth application or a redirect URI.

Note

The Snowflake GitHub App works with github.com, including standard GitHub Enterprise Cloud organizations hosted there. GitHub Enterprise Cloud with data residency (*.ghe.com) and GitHub Enterprise Server require OAuth2 instead.

  1. Create an API integration that specifies the Snowflake GitHub App:

    CREATE OR REPLACE API INTEGRATION my_git_api_integration
      API_PROVIDER = git_https_api
      API_ALLOWED_PREFIXES = ('https://github.com')
      API_USER_AUTHENTICATION = (TYPE = SNOWFLAKE_GITHUB_APP)
      ENABLED = TRUE;
    
  2. Create a Git workspace as described in Create a Git workspace.

Configure for authenticating with a token

Diagram showing components needed to configure Git connection with token authentication

To have Snowflake authenticate with the Git repository by using a username and token such as a personal access token (PAT), follow these steps:

  1. Provide credentials in a basic authentication secret.

    To provide the credentials that Snowflake uses to authenticate with the repository, create a secret that contains the following:

    • A TYPE value of password

    • A username and token, such as a personal access token (PAT)

      If your Git repository is hosted on Bitbucket, specify x-token-auth as the username value.

      Note

      For information about creating a personal access token in GitHub, see Managing your personal access tokens in the GitHub documentation.

    For more information on the SQL command for creating a secret, see the CREATE SECRET.

    Code in the following example creates a secret called my_git_secret with a username and the user’s personal access token to use as credentials:

    CREATE OR REPLACE SECRET db.schema.my_git_secret
      TYPE = password
      USERNAME = 'gladyskravitz'
      PASSWORD = 'ghp_token';
    
  2. Create an API integration that supports authenticating with a token.

    To create an API integration for access to a Git repository with a token, specify the following details:

    • git_https_api as the value of the API_PROVIDER parameter
    • HTTPS endpoints to which requests must be limited as values of the API_ALLOWED_PREFIXES parameter

    For more information, see CREATE API INTEGRATION.

    CREATE OR REPLACE API INTEGRATION my_git_api_integration
      API_PROVIDER = git_https_api
      API_ALLOWED_PREFIXES = ('https://github.com/my-account')
      ALLOWED_AUTHENTICATION_SECRETS = (my_git_secret)
      ENABLED = TRUE;
    
  3. Create a Git workspace as described in Create a Git workspace.

Configure for no authentication

Diagram showing components needed to configure Git connection requiring no authentication

To set up Snowflake to use a Git repository without authenticating, follow these steps:

  1. Create an API integration that supports access without authenticating, and specify the following details:

    • git_https_api as the value of the API_PROVIDER parameter
    • HTTPS endpoints to which requests must be limited as values of the API_ALLOWED_PREFIXES parameter

    For more information, see CREATE API INTEGRATION.

    CREATE OR REPLACE API INTEGRATION my_git_api_integration
      API_PROVIDER = git_https_api
      API_ALLOWED_PREFIXES = ('https://example.com/my-account')
      ENABLED = TRUE;
    
  2. Create a Git workspace as described in Create a Git workspace.

Create a Git workspace

After you configure the API integration, create a workspace connected to the remote repository. The Git workspace belongs to the user who creates it. The role selected in your Snowsight user menu determines which API integrations and secrets you can select. That role must have the USAGE privilege on the API integration.

  1. Sign in to Snowsight.

  2. In the navigation menu, select Projects » Workspaces.

  3. In the Workspaces menu, select From Git repository.

  4. For Repository URL, paste the HTTPS URL of the remote repository.

  5. From the API Integration menu, select the API integration that you configured.

  6. Select the authentication method that matches your API integration:

    • OAuth2: Select Sign in, and then authorize Snowflake with your Git provider.
    • Personal access token: Select the secret that contains your token.
    • Public repository: Select this option for a repository that doesn’t require authentication. You can’t push changes from the workspace to a public repository.
  7. Select Create.

For details on each option, including the GitHub authorization steps and how to open the dialog with pre-filled fields, see Create a Git workspace.

Create a Git repository clone for Snowflake code

A Git repository clone is a read-only, schema-level object that’s owned by a role. Create one when Snowflake code such as tasks, stored procedures, or UDFs needs to reference repository files, for example as handler code or with EXECUTE IMMEDIATE FROM. You can’t create, edit, commit, or push files through a clone. For more information, see How a Git repository clone works.

A Git repository clone in Snowflake specifies the following details:

  • The remote repository’s origin

    In Git, origin is the remote repository’s URL. Use that URL when setting up Snowflake to use a remote Git repository. The URL must use HTTPS. For example, you can retrieve the origin URL in the following ways:

    • In the GitHub user interface, you can get the origin URL from the repository home page. Select the Code button, and then copy the HTTPS URL from the box displayed beneath the button.

    • From the command line, use the git config command from within your local repository, as in the following example:

      $ git config --get remote.origin.url
      

      The command produces output such as the following:

      https://github.com/my-account/snowflake-extensions.git
      

      For reference information about git config, see the git documentation.

  • Credentials, if needed, for Snowflake to use when authenticating with the repository

    For the GIT_CREDENTIALS parameter, specify a Snowflake secret you created.

  • An API integration specifying details for Snowflake interaction with the repository API

You can create a Git repository clone by using either Snowsight or SQL.

Note

Before creating a Git repository clone, you’ll need to create a secret (if the remote repository requires authentication) and an API integration.

Code in the following example creates a Git repository clone called snowflake_extensions. The clone specifies the my_git_api_integration API integration and the my_git_secret secret with credentials for authenticating.

USE ROLE ACCOUNTADMIN;
GRANT CREATE GIT REPOSITORY ON SCHEMA myco_db.integrations TO ROLE myco_git_admin;
GRANT USAGE ON INTEGRATION my_git_api_integration TO ROLE myco_git_admin;
GRANT USAGE ON SECRET db.schema.my_git_secret TO ROLE myco_git_admin;

USE ROLE myco_git_admin;

CREATE OR REPLACE GIT REPOSITORY snowflake_extensions
  API_INTEGRATION = my_git_api_integration
  GIT_CREDENTIALS = my_git_secret
  ORIGIN = 'https://github.com/my-account/snowflake-extensions.git';