Skip to content

Conversation

@costrouc
Copy link

@costrouc costrouc commented Oct 25, 2025

Support Snowflake SPCS OIDC authentication with dual credentials

Intent

Adapts the Snowflake SPCS OIDC authentication changes from
rsconnect-python#715 to the
publisher repository.

Prior to recent changes on the Snowflake side, proxied authentication headers carried
enough information for Connect running in Snowflake SPCS to identify users. With the move
to OIDC, Connect servers no longer trust Snowflake headers for username identification.
This requires users to provide both a Snowflake connection (for proxied authentication)
and a Connect API key (for OIDC authentication).

Type of Change

  • New Feature
  • Breaking Change

Approach

The implementation follows the same pattern as rsconnect-python:

Backend (Go):

  1. Updated credential validation to require both SnowflakeConnection and ApiKey for
    Snowflake SPCS credentials
  2. Modified authentication to send two headers:
    • Authorization: Snowflake token (for proxied authentication)
    • X-RSC-Authorization: Connect API key (for OIDC authentication)
  3. Updated account authentication type detection to prioritize Snowflake connection (most
    specific case)

Frontend (VSCode Extension):

  1. Added a new input step to prompt users for the Connect API key when creating Snowflake
    SPCS credentials
  2. The flow now requests: Server URL → Snowflake Connection → Connect API Key
    Credential Name
  3. Provides clear messaging about why both credentials are needed

Trade-offs:

  • This is a breaking change for existing Snowflake SPCS users who will need to update
    their credentials with a Connect API key
  • We chose to make API key required rather than optional to enforce the new security
    model
  • The credential validation strictly requires both fields to prevent misconfiguration

User Impact

Breaking Change for Snowflake SPCS Users:

  • Users with existing Snowflake SPCS credentials will need to update them to include a
    Connect API key
  • When creating new Snowflake SPCS credentials, users will be prompted for both:
    1. Snowflake connection name (existing)
    2. Connect API key (new)

Benefits:

  • Proper authentication with Connect servers deployed in Snowflake SPCS using OIDC
  • Improved security by using Connect API keys instead of relying solely on proxied
    headers

Automated Tests

  • Updated snowflake_test.go to verify dual-header authentication
  • Updated file_test.go and keyring_test.go to test credential validation with both
    fields
  • Added test case for authenticator without API key to ensure backward compatibility
  • All existing authentication, credential, and account tests pass

The tests verify:

  • API key is properly stored in the authenticator
  • Both Authorization and X-RSC-Authorization headers are set correctly
  • Credential validation requires both Snowflake connection and API key
  • Authentication type detection prioritizes Snowflake correctly

Directions for Reviewers

Backend Review:

  1. Review credential validation logic in internal/credentials/credentials.go:274-278
  2. Verify authentication implementation in internal/api_client/auth/snowflake.go:72-88
  3. Check test coverage in internal/api_client/auth/snowflake_test.go

Frontend Review:

  1. Review the new API key input step in
    extensions/vscode/src/multiStepInputs/newConnectCredential.ts
  2. Verify the validation logic requires both credentials for Snowflake
  3. Test the user flow manually (optional):
    • Create a new credential with a Snowflake SPCS URL
    • Verify you're prompted for Snowflake connection
    • Verify you're prompted for Connect API key
    • Verify credential is created with both fields

Testing:
Run the authentication and credential tests:

go test ./internal/credentials/... ./internal/api_client/auth/... ./internal/accounts/...  -v

Compare with rsconnect-python:

Checklist

  • I have updated the root ../CHANGELOG.md to cover notable changes.

costrouc and others added 3 commits October 25, 2025 09:55
Snowflake SPCS deployments with OIDC now require both a Snowflake connection
name and a Connect API key for authentication. This change updates the
credential validation logic and account authentication type detection to
support this new requirement.

Changes:
- credentials.go: Updated validation to require both SnowflakeConnection and
  ApiKey for ServerTypeSnowflake credentials
- account.go: Modified AuthType() to prioritize Snowflake connection detection
  since it's the most specific case, and added documentation about the dual
  authentication requirement

This aligns with changes in Snowflake SPCS where proxied authentication headers
no longer carry sufficient user identification information, necessitating the
use of Connect API keys in addition to Snowflake tokens.

Related: posit-dev/rsconnect-python#715

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implements the authentication mechanism for Snowflake SPCS with OIDC support
by sending both Snowflake tokens and Connect API keys in separate headers.

Changes:
- snowflake.go:
  - Added apiKey field to snowflakeAuthenticator struct
  - Updated NewSnowflakeAuthenticator to accept apiKey parameter
  - Modified AddAuthHeaders to set both Authorization (Snowflake token) and
    X-RSC-Authorization (Connect API key) headers
  - Enhanced documentation to explain the dual-header OIDC authentication

- auth.go:
  - Updated NewClientAuth to pass the API key when creating Snowflake
    authenticators

The Authorization header contains the Snowflake token for proxied authentication,
while the X-RSC-Authorization header contains the Connect API key for OIDC
authentication. This dual-header approach ensures proper authentication with
Connect servers deployed in Snowflake SPCS.

Related: posit-dev/rsconnect-python#715

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Updates all tests to reflect the new dual-credential requirement for Snowflake
SPCS authentication with OIDC support.

Changes:
- snowflake_test.go:
  - Updated all NewSnowflakeAuthenticator calls to include API key parameter
  - Added assertions to verify API key is properly stored in authenticator
  - Enhanced TestAddAuthHeaders to verify both Authorization and
    X-RSC-Authorization headers are set correctly
  - Added test case for authenticator without API key to ensure the header
    is only set when an API key is provided

- file_test.go & keyring_test.go:
  - Updated Snowflake credential creation tests to include API key
  - Changed expected API key assertions from empty string to test API key

All tests pass, confirming that the OIDC authentication changes work correctly
while maintaining backward compatibility.

Related: posit-dev/rsconnect-python#715

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
costrouc and others added 2 commits October 25, 2025 10:09
… extension

Adds a new input step in the VSCode extension credential creation flow to
prompt users for a Connect API key when creating Snowflake SPCS credentials.

Changes:
- Added INPUT_SNOWFLAKE_API_KEY step to the credential creation flow
- Implemented inputSnowflakeAPIKey() function that:
  - Prompts users for the Connect API key with password masking
  - Validates API key syntax using existing validation logic
  - Provides clear messaging about OIDC authentication requirements
- Updated isValidSnowflakeAuth() to require both snowflakeConnection and apiKey
- Modified inputSnowflakeConnection() to navigate to the API key input step
  before proceeding to credential naming

The new flow for Snowflake SPCS credentials is:
1. Enter server URL
2. Select Snowflake connection
3. Enter Connect API key (NEW)
4. Name the credential

This ensures users provide both authentication components needed for Snowflake
SPCS deployments with OIDC authentication.

Related: posit-dev/rsconnect-python#715

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Documents the Snowflake SPCS OIDC authentication changes in both the main
repository and VSCode extension changelogs.

Changes:
- Added entries to "Unreleased > Fixed" sections explaining that Snowflake
  SPCS authentication now requires both a Snowflake connection name and a
  Connect API key
- Documented the dual-header authentication approach (Authorization for
  Snowflake token, X-RSC-Authorization for Connect API key)
- Explained the reason for the change: proxied authentication headers in
  Snowflake SPCS no longer carry sufficient user identification information
  with the move to OIDC

Related: posit-dev/rsconnect-python#715

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@costrouc costrouc force-pushed the feat-support-snowflake-spcs-oidc branch from 2f6d36c to bb0fc20 Compare October 25, 2025 14:10
@costrouc
Copy link
Author

This PR still requires manual testing which I will start on Monday.

@costrouc costrouc marked this pull request as draft October 26, 2025 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant