- 
                Notifications
    You must be signed in to change notification settings 
- Fork 207
Adding support for Snowflake Workload Identity Federation #1316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            roryjbd
  wants to merge
  19
  commits into
  dbt-labs:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
roryjbd:main
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            19 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      442cca0
              
                added basic snowflake workload identity federation
              
              
                roryjbd f4e1799
              
                addd entra details
              
              
                roryjbd 6c85b3b
              
                add tests
              
              
                roryjbd 20f7f65
              
                added wif aws test
              
              
                roryjbd 53d734c
              
                fix file name
              
              
                roryjbd e273ffe
              
                add role to test
              
              
                roryjbd ac4affb
              
                add OIDC test
              
              
                roryjbd 595d91e
              
                change hatch step
              
              
                roryjbd cd1bf6f
              
                output token
              
              
                roryjbd 8d662e0
              
                add role to test steps
              
              
                roryjbd 5c17e99
              
                add wif oidc test steps
              
              
                roryjbd 126bd8b
              
                update profile template
              
              
                roryjbd f35c86b
              
                add better error handing and messaging for WIF
              
              
                roryjbd fb2005d
              
                Merge branch 'main' into main
              
              
                roryjbd c232493
              
                fix fstring linting issue
              
              
                roryjbd d0da874
              
                add changie entry
              
              
                roryjbd 3286db4
              
                Merge branch 'main' of https://github.com/roryjbd/dbt-adapters
              
              
                roryjbd b323c1f
              
                Merge branch 'main' into main
              
              
                roryjbd c7eb962
              
                don't set platform_detection default to 0 if wif
              
              
                roryjbd File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
  
    
      
          
            6 changes: 6 additions & 0 deletions
          
          6 
        
  dbt-snowflake/.changes/unreleased/Features-20250909-221007.yaml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| kind: Features | ||
| body: Introduction of Workload Identity Federation as a supported method of authentication to Snowflake | ||
| time: 2025-09-09T22:10:07.504016+01:00 | ||
| custom: | ||
| Author: roryjbd,sfc-gh-pmansour | ||
| Issue: "1234" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            87 changes: 87 additions & 0 deletions
          
          87 
        
  dbt-snowflake/tests/functional/auth_tests/test_workload_identity_federation_aws.py
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| """ | ||
| Functional tests for Snowflake Workload Identity Federation (WIF) with AWS authentication. | ||
| Prerequisites for testing WIF with AWS: | ||
| 1. **AWS IAM Configuration:** | ||
| Create an IAM role that can be assumed by the EC2 service. An example trust policy below: | ||
| ``` | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Principal": { | ||
| "Service": "ec2.amazonaws.com" // or your specific service | ||
| }, | ||
| "Action": "sts:AssumeRole" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
| 2. **EC2 Instance:** | ||
| Launch an EC2 instance with the IAM role attached as an instance profile. | ||
| Connect to the EC2 instance and | ||
|  | ||
|  | ||
| 3. **Snowflake User Configuration:** | ||
| Create a service user in Snowflake with WIF enabled: | ||
| ```sql | ||
| CREATE USER <username> | ||
| WORKLOAD_IDENTITY = ( | ||
| TYPE = AWS | ||
| ARN = '<amazon_iam_role_arn>' | ||
| ) | ||
| TYPE = SERVICE | ||
| DEFAULT_ROLE = <role>; | ||
| ``` | ||
| Replace `<username>` with your desired username and `<amazon_iam_role_arn>` | ||
| with the ARN of your AWS IAM role. | ||
| 4. **AWS Environment:** | ||
| This test must run from within the configured EC2 environment. | ||
| Connect to the EC2 instance using SSH or similar. | ||
| Clone this repository, run the setup, and execute this test e.g. | ||
| `hatch run pytest tests/functional/auth_tests/test_workload_identity_federation_aws.py::test_snowflake_wif_basic_functionality` | ||
| 5. **Environment Variables:** | ||
| Set the following environment variables for testing: | ||
| - SNOWFLAKE_TEST_ACCOUNT: Your Snowflake account identifier | ||
| - SNOWFLAKE_TEST_USER: The Snowflake service user created for WIF | ||
| - SNOWFLAKE_TEST_DATABASE: Test database name | ||
| - SNOWFLAKE_TEST_WAREHOUSE: Test warehouse name | ||
| - SNOWFLAKE_TEST_ROLE: Snowflake Role for the user (optional) | ||
| - SNOWFLAKE_TEST_SCHEMA: Schema for testing (optional, defaults to schema in profile) | ||
| Note: WIF authentication relies on being in the AWS environment, so these tests can't be run locally or in the CI/CD pipeline. | ||
| """ | ||
|  | ||
| import os | ||
| from dbt.tests.util import run_dbt | ||
| import pytest | ||
|  | ||
|  | ||
| _MODELS__MODEL_1_SQL = """ | ||
| select 1 as id, 'wif_test' as source | ||
| """ | ||
|  | ||
|  | ||
| class TestSnowflakeWorkloadIdentityFederation: | ||
| @pytest.fixture(scope="class", autouse=True) | ||
| def dbt_profile_target(self): | ||
| return { | ||
| "type": "snowflake", | ||
| "threads": 4, | ||
| "account": os.getenv("SNOWFLAKE_TEST_ACCOUNT"), | ||
| "user": os.getenv("SNOWFLAKE_TEST_USER"), | ||
| "database": os.getenv("SNOWFLAKE_TEST_DATABASE"), | ||
| "warehouse": os.getenv("SNOWFLAKE_TEST_WAREHOUSE"), | ||
| "role": os.getenv("SNOWFLAKE_TEST_ROLE"), | ||
| "authenticator": "workload_identity", | ||
| "workload_identity_provider": "aws", | ||
| } | ||
|  | ||
| @pytest.fixture(scope="class") | ||
| def models(self): | ||
| return { | ||
| "model_1.sql": _MODELS__MODEL_1_SQL, | ||
| } | ||
|  | ||
| def test_snowflake_wif_basic_functionality(self, project): | ||
| """Test basic dbt functionality with WIF authentication""" | ||
| run_dbt() | 
        
          
  
    
      
          
            106 changes: 106 additions & 0 deletions
          
          106 
        
  dbt-snowflake/tests/functional/auth_tests/test_workload_identity_federation_oidc.py
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| """ | ||
| Functional tests for Snowflake Workload Identity Federation (WIF) with OIDC authentication. | ||
| Prerequisites for testing WIF with OIDC: | ||
|  | ||
| 1. **Create a Snowflake User with OIDC Auth** | ||
|  | ||
| Create a service user in Snowflake with WIF enabled: | ||
| ```sql | ||
| CREATE USER <username> | ||
| TYPE = SERVICE | ||
| WORKLOAD_IDENTITY = ( | ||
| TYPE = OIDC, | ||
| ISSUER = 'https://token.actions.githubusercontent.com', | ||
| SUBJECT = 'repo:<REPO_OWNER>/dbt-adapters:ref:refs/heads/main', | ||
| OIDC_AUDIENCE_LIST = ('snowflakecomputing.com') | ||
| ); | ||
| ``` | ||
|  | ||
| 2. **Create a GitHub Actions that generates the OIDC token and runs the test ** | ||
|  | ||
| ```yaml | ||
|  | ||
| name: Run Snowflake Workload Identity Federation (WIF) Test | ||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: [ main ] | ||
|  | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|  | ||
| jobs: | ||
| run-snowflake: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| SNOWFLAKE_TEST_ACCOUNT: <ACCOUNT_ID> | ||
| SNOWFLAKE_TEST_DATABASE: <DB_NAME> | ||
| SNOWFLAKE_TEST_WAREHOUSE: <WH_NAME> | ||
| SNOWFLAKE_TEST_ROLE: <ROLE_NAME> | ||
| SNOWFLAKE_TEST_USER: <USERNAME> | ||
|  | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|  | ||
| - name: Get OIDC token for Snowflake | ||
| id: oidc | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const token = await core.getIDToken('snowflakecomputing.com'); | ||
| core.setOutput('id_token', token); | ||
|  | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|  | ||
| - uses: pypa/hatch@install | ||
|  | ||
| - run: hatch run setup | ||
| working-directory: ./dbt-snowflake | ||
|  | ||
| - run: hatch run python -m pytest tests/functional/auth_tests/test_workload_identity_federation_oidc.py | ||
| working-directory: ./dbt-snowflake | ||
| env: | ||
| ODIC_TOKEN: ${{ steps.oidc.outputs.id_token }} | ||
| ``` | ||
|  | ||
| """ | ||
|  | ||
| import os | ||
| from dbt.tests.util import run_dbt | ||
| import pytest | ||
|  | ||
|  | ||
| _MODELS__MODEL_1_SQL = """ | ||
| select 1 as id, 'wif_test' as source | ||
| """ | ||
|  | ||
|  | ||
| class TestSnowflakeWorkloadIdentityFederation: | ||
| @pytest.fixture(scope="class", autouse=True) | ||
| def dbt_profile_target(self): | ||
| return { | ||
| "type": "snowflake", | ||
| "threads": 4, | ||
| "account": os.getenv("SNOWFLAKE_TEST_ACCOUNT"), | ||
| "user": os.getenv("SNOWFLAKE_TEST_USER"), | ||
| "database": os.getenv("SNOWFLAKE_TEST_DATABASE"), | ||
| "warehouse": os.getenv("SNOWFLAKE_TEST_WAREHOUSE"), | ||
| "role": os.getenv("SNOWFLAKE_TEST_ROLE"), | ||
| "authenticator": "workload_identity", | ||
| "workload_identity_provider": "oidc", | ||
| "token": os.getenv("ODIC_TOKEN"), | ||
| } | ||
|  | ||
| @pytest.fixture(scope="class") | ||
| def models(self): | ||
| return { | ||
| "model_1.sql": _MODELS__MODEL_1_SQL, | ||
| } | ||
|  | ||
| def test_snowflake_wif_basic_functionality(self, project): | ||
| """Test basic dbt functionality with WIF authentication""" | ||
| run_dbt() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.