Skip to content

fix(database-integrations): redact Snowflake dbtServiceToken in integrations file - #423

Merged
tkislan merged 4 commits into
mainfrom
fix/snowflake-dbt-service-token-redaction
Jul 17, 2026
Merged

tkislan merged 4 commits into
mainfrom
fix/snowflake-dbt-service-token-redaction

Conversation

@tkislan

@tkislan tkislan commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

dbtServiceToken — a dbt Cloud service token — was written into integrations.yaml in cleartext instead of being extracted into an env var reference. Since that file is meant to be committed, the token could reach version control.

This was an oversight in the original redaction implementation.

Root cause

dbtServiceToken is declared on commonSnowflakeMetadataSchema, so it is inherited by all six Snowflake auth variants. But SECRET_PATHS.snowflake only listed the credentials belonging to individual auth variants:

snowflake: ['password', 'clientSecret', 'privateKey', 'privateKeyPassphrase'],

updateIntegrationMetadataMap treats that list as an allowlist and writes everything else through untouched:

if (!secretPaths.includes(key)) { metadataMap.set(key, value); continue }

So the field on the shared base was missed while every field on the variants was covered — the token fell straight through to disk.

Impact

Reachable via deepnote integrations pull for any Snowflake integration with dbt enabled. The dbt fields are Omitted from the interactive prompts (integrations-prompts/snowflake.ts), so the API sync path was the only way to populate it — which is why the regression test targets mergeApiIntegrationsIntoDocument rather than the prompts.

Important

Anyone whose integrations.yaml already contains a literal dbtServiceToken should rotate that token in dbt Cloud and scrub it from git history. The fix prevents new writes; it cannot retract tokens already committed.

Changes

  • secret-field-paths.ts — add dbtServiceToken to SECRET_PATHS.snowflake (+ update the doc example).
  • merge-integrations.test.ts — regression test on the API sync path.
  • integrations.test.ts — extend the Snowflake secret-paths assertion.

dbt, dbtPrimaryJobId and dbtProxyServerUrl are not credentials and deliberately remain in the file.

Verification

The test fails without the fix, with the token visible in the emitted YAML:

AssertionError: expected '#yaml-language-server: $schema=https:…' not to contain 'dbtc_super-secret-token'

After the fix:

metadata:
  dbtServiceToken: env:SNOWFLAKE_DBT_ID__DBTSERVICETOKEN   # extracted
  dbtPrimaryJobId: "12345"                                 # unchanged
  dbtProxyServerUrl: https://proxy.example.com             # unchanged

packages/database-integrations + packages/cli/src/commands/integrations.test.ts pass (326 tests); biome clean.

Pre-existing unrelated failures on main

Six packages/cli test files fail to collect with Cannot find package 'zod' imported from packages/cloud/src/cloud-runs.ts, and tsc reports two errors in the same file. Both reproduce on a clean checkout of main (c6fcb8c) and are untouched by this PR.

Audit of the other integrations

All 18 remaining integration types were swept for the same bug class — every field across every union variant, cross-checked against vendor documentation. No other cleartext credential leaks were found. Two candidates were investigated and rejected:

Field Verdict
redshift.roleNonce Not a credential. AWS explicitly documents the sibling External ID as non-secret, and roleNonce is prompted as a plain string and never read by any code.
mongodb.options Not a credential field by design — see below.

Follow-up worth a maintainer decision (not addressed here)

mongodb.options is concatenated into connection_string (integrations-prompts/mongodb.ts:74), and connection_string is redacted — so the same bytes are treated differently depending on which field they land in:

options: tlsCertificateKeyFilePassword=SUPERSECRET&retryWrites=true   # cleartext
connection_string: env:MONGO_1__CONNECTION_STRING                     # redacted

Left alone deliberately: MongoDB documents options as connection tuning (retryWrites, w, readPreference), the prompt code classifies it as non-secret, and adding it to SECRET_PATHS would push benign config into env vars. But tlsCertificateKeyFilePassword, proxyPassword and authMechanismProperties=AWS_SESSION_TOKEN:… are real options that would leak. If worth closing, selective key-level redaction inside options seems better than redacting the whole field.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J1kuzoQrpYv35P7hkNKGHa

Summary by CodeRabbit

  • Bug Fixes
    • Improved Snowflake integration handling so DBT service tokens are securely extracted into the secrets configuration.
    • Ensured Snowflake DBT metadata is preserved in generated configuration files without exposing the raw token.
  • Documentation
    • Updated Snowflake secret-field documentation to include the DBT service token.
  • Tests
    • Expanded Snowflake test coverage to verify secret extraction and correct YAML/env references, including dbtServiceToken.
  • Chores
    • Updated spelling configuration to recognize DBTSERVICETOKEN.

…rations file

`dbtServiceToken` is declared on `commonSnowflakeMetadataSchema`, so it is
shared by all six Snowflake auth variants, but `SECRET_PATHS.snowflake` only
listed the per-variant credentials. `updateIntegrationMetadataMap` writes any
field absent from that list to the YAML verbatim, so the dbt Cloud service
token was persisted in cleartext into a file users are expected to commit.

The token now round-trips through an env var reference like every other
credential. `dbt`, `dbtPrimaryJobId` and `dbtProxyServerUrl` are not
credentials and stay in the file.

The regression test covers `mergeApiIntegrationsIntoDocument` rather than the
prompt path: the dbt fields are omitted from the interactive prompts, so
`deepnote integrations pull` was the only way to reach this.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J1kuzoQrpYv35P7hkNKGHa
@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Snowflake secret-field paths now include dbtServiceToken. Tests verify that the token is extracted into the secrets map and removed from generated YAML, while dbtPrimaryJobId and dbtProxyServerUrl remain preserved. CLI coverage also updates the expected Snowflake secret paths.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Updates Docs ⚠️ Warning Only a test file changed here; no docs/README/roadmap files were updated, and the external docs repo isn’t visible. Update the relevant OSS docs for Snowflake/dbtServiceToken and, if applicable, the landing-page roadmap in deepnote/deepnote-internal.
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: redacting Snowflake dbtServiceToken in integrations files.

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.85%. Comparing base (c6fcb8c) to head (43850a7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #423   +/-   ##
=======================================
  Coverage   86.85%   86.85%           
=======================================
  Files         166      166           
  Lines        8766     8766           
  Branches     2412     2412           
=======================================
  Hits         7614     7614           
  Misses       1151     1151           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/database-integrations/src/loading/merge-integrations.test.ts`:
- Around line 344-345: Strengthen the test assertions around dbtServiceToken to
verify the YAML content references the environment variable
SNOWFLAKE_DBT_ID__DBTSERVICETOKEN, in addition to confirming the secret is
redacted and returned in secrets. Update the test near the existing content and
secrets expectations without changing the production behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7795cb6f-3492-41e5-bf0f-a021d3058d6c

📥 Commits

Reviewing files that changed from the base of the PR and between c6fcb8c and 4ff6b12.

📒 Files selected for processing (3)
  • packages/cli/src/commands/integrations.test.ts
  • packages/database-integrations/src/loading/merge-integrations.test.ts
  • packages/database-integrations/src/secret-field-paths.ts

tkislan and others added 2 commits July 17, 2026 09:25
The fake token value and the hardcoded env var key tripped cspell on `dbtc`
and `DBTSERVICETOKEN`. Assert through `Object.values(secrets)` and an
`env:` prefix check instead, matching the sibling multi-secret test.

The test still fails without the fix, on the cleartext token in the YAML.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J1kuzoQrpYv35P7hkNKGHa
…n YAML

`dbtServiceToken: env:` matched any env var name, so a mismatch between the
reference written to the YAML and the key returned in `secrets` would have
gone unnoticed. Pin both to SNOWFLAKE_DBT_ID__DBTSERVICETOKEN.

This restores the literal name dropped in 5d727d3 and registers the word in
cspell.json instead, matching how CLIENTSECRET, RAWCONNECTIONSTRING and
CACERTIFICATETEXT are already handled for the same generated names.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J1kuzoQrpYv35P7hkNKGHa
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 17, 2026
…tegrations

The string assertions prove a reference appears in the YAML, not that it
resolves. Read the file back through `parseIntegrations`, the parser that
actually consumes it, and assert the token comes out as it went in.

A reference that disagrees with the key returned in `secrets` now fails as an
env_var_not_defined issue rather than slipping through a substring match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J1kuzoQrpYv35P7hkNKGHa
@tkislan
tkislan marked this pull request as ready for review July 17, 2026 10:15
@tkislan
tkislan requested a review from a team as a code owner July 17, 2026 10:15
@tkislan
tkislan merged commit 50a4af7 into main Jul 17, 2026
21 checks passed
@tkislan
tkislan deleted the fix/snowflake-dbt-service-token-redaction branch July 17, 2026 11:48
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.

2 participants