Repository navigation
fix(database-integrations): redact Snowflake dbtServiceToken in integrations file - #423
Conversation
…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
📝 WalkthroughWalkthroughSnowflake secret-field paths now include Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
packages/cli/src/commands/integrations.test.tspackages/database-integrations/src/loading/merge-integrations.test.tspackages/database-integrations/src/secret-field-paths.ts
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
…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
Summary
dbtServiceToken— a dbt Cloud service token — was written intointegrations.yamlin 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
dbtServiceTokenis declared oncommonSnowflakeMetadataSchema, so it is inherited by all six Snowflake auth variants. ButSECRET_PATHS.snowflakeonly listed the credentials belonging to individual auth variants:updateIntegrationMetadataMaptreats that list as an allowlist and writes everything else through untouched: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 pullfor any Snowflake integration with dbt enabled. The dbt fields areOmitted 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 targetsmergeApiIntegrationsIntoDocumentrather than the prompts.Important
Anyone whose
integrations.yamlalready contains a literaldbtServiceTokenshould 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— adddbtServiceTokentoSECRET_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,dbtPrimaryJobIdanddbtProxyServerUrlare not credentials and deliberately remain in the file.Verification
The test fails without the fix, with the token visible in the emitted YAML:
After the fix:
packages/database-integrations+packages/cli/src/commands/integrations.test.tspass (326 tests); biome clean.Pre-existing unrelated failures on
mainSix
packages/clitest files fail to collect withCannot find package 'zod' imported from packages/cloud/src/cloud-runs.ts, andtscreports two errors in the same file. Both reproduce on a clean checkout ofmain(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:
redshift.roleNonceroleNonceis prompted as a plain string and never read by any code.mongodb.optionsFollow-up worth a maintainer decision (not addressed here)
mongodb.optionsis concatenated intoconnection_string(integrations-prompts/mongodb.ts:74), andconnection_stringis redacted — so the same bytes are treated differently depending on which field they land in:Left alone deliberately: MongoDB documents
optionsas connection tuning (retryWrites,w,readPreference), the prompt code classifies it as non-secret, and adding it toSECRET_PATHSwould push benign config into env vars. ButtlsCertificateKeyFilePassword,proxyPasswordandauthMechanismProperties=AWS_SESSION_TOKEN:…are real options that would leak. If worth closing, selective key-level redaction insideoptionsseems better than redacting the whole field.🤖 Generated with Claude Code
https://claude.ai/code/session_01J1kuzoQrpYv35P7hkNKGHa
Summary by CodeRabbit
dbtServiceToken.DBTSERVICETOKEN.