8000 fix(sources/snowflake)!: leave an empty role out of the DSN by dendyramdhan · Pull Request #4601 · googleapis/mcp-toolbox · GitHub
[go: up one dir, main page]

Skip to content

fix(sources/snowflake)!: leave an empty role out of the DSN - #4601

Open
dendyramdhan wants to merge 1 commit into
googleapis:mainfrom
dendyramdhan:fix/snowflake-omit-empty-role
Open

dendyramdhan wants to merge 1 commit into
googleapis:mainfrom
dendyramdhan:fix/snowflake-omit-empty-role

Conversation

@dendyramdhan
Copy link
Copy Markdown

Summary

An empty Snowflake role was rewritten to ACCOUNTADMIN before the DSN was built. That is the highest-privilege role in an account, and it is not Snowflake's own default for routine work. When role is omitted, the DSN now leaves it out so Snowflake applies the user's default role. warehouse still defaults to COMPUTE_WH.

This is a behavior change for anyone who relied on the silent ACCOUNTADMIN default. Set role: ACCOUNTADMIN explicitly to keep the old behavior.

Fixes #4090

Test

go test ./internal/sources/snowflake/ -count=1 passed, including the new DSN cases (empty role omitted, empty warehouse still becomes COMPUTE_WH) and the existing YAML parse tests.

An omitted role was filled in as ACCOUNTADMIN, so a config that expected
the user's Snowflake default role ran every tool as the account admin.
Omit the role parameter instead. Warehouse still defaults to COMPUTE_WH.

Fixes googleapis#4090
@dendyramdhan
dendyramdhan requested a review from a team as a code owner November 25, 2026 05:07
@google-cla
google-cla Bot commented Nov 25, 2026
Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the Snowflake integration to omit the role parameter from the DSN when it is empty, allowing Snowflake to fall back to the user's default role instead of defaulting to ACCOUNTADMIN. This change is applied to the Snowflake source, configuration samples, and integration tests, and a new unit test is added. The reviewer suggests exporting the helper function snowflakeDSN as SnowflakeDSN so that it can be reused in the integration tests, thereby eliminating duplicated DSN construction logic.

Comment on lines +143 to +155
8000
// snowflakeDSN builds a gosnowflake DSN. An empty warehouse falls back to
// COMPUTE_WH. An empty role is omitted so Snowflake uses the user's own
// default role instead of ACCOUNTADMIN.
func snowflakeDSN(user, password, account, database, schema, warehouse, role string) string {
if warehouse == "" {
warehouse = "COMPUTE_WH"
}
if role == "" {
role = "ACCOUNTADMIN"
dsn := fmt.Sprintf("%s:%s@%s/%s/%s?warehouse=%s", user, password, account, database, schema, warehouse)
if role != "" {
dsn += "&role=" + role
}
return dsn
}
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.

medium

Exporting snowflakeDSN as SnowflakeDSN allows us to reuse it in the integration tests, avoiding code duplication of the DSN building logic.

Suggested change
// snowflakeDSN builds a gosnowflake DSN. An empty warehouse falls back to
// COMPUTE_WH. An empty role is omitted so Snowflake uses the user's own
// default role instead of ACCOUNTADMIN.
func snowflakeDSN(user, password, account, database, schema, warehouse, role string) string {
if warehouse == "" {
warehouse = "COMPUTE_WH"
}
if role == "" {
role = "ACCOUNTADMIN"
dsn := fmt.Sprintf("%s:%s@%s/%s/%s?warehouse=%s", user, password, account, database, schema, warehouse)
if role != "" {
dsn += "&role=" + role
}
return dsn
}
// SnowflakeDSN builds a gosnowflake DSN. An empty warehouse falls back to
// COMPUTE_WH. An empty role is omitted so Snowflake uses the user's own
// default role instead of ACCOUNTADMIN.
func SnowflakeDSN(user, password, account, database, schema, warehouse, role string) string {
if warehouse == "" {
warehouse = "COMPUTE_WH"
}
dsn := fmt.Sprintf("%s:%s@%s/%s/%s?warehouse=%s", user, password, account, database, schema, warehouse)
if role != "" {
dsn += "&role=" + role
}
return dsn
}


// Snowflake DSN format: user:password@account/database/schema?warehouse=warehouse&role=role
dsn := fmt.Sprintf("%s:%s@%s/%s/%s?warehouse=%s&role=%s", user, password, account, database, schema, warehouse, role)
dsn := snowflakeDSN(user, password, account, database, schema, warehouse, role)
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.

medium

Update the call to use the exported SnowflakeDSN function.

Suggested change
dsn := snowflakeDSN(user, password, account, database, schema, warehouse, role)
dsn := SnowflakeDSN(user, password, account, database, schema, warehouse, role)

Comment on lines +19 to +31
func TestSnowflakeDSNOmitsEmptyRole(t *testing.T) {
got := snowflakeDSN("user", "pw", "acct", "db", "PUBLIC", "WH", "")
want := "user:pw@acct/db/PUBLIC?warehouse=WH"
if got != want {
t.Fatalf("empty role: got %q want %q", got, want)
}

got = snowflakeDSN("user", "pw", "acct", "db", "PUBLIC", "", "ANALYST")
want = "user:pw@acct/db/PUBLIC?warehouse=COMPUTE_WH&role=ANALYST"
if got != want {
t.Fatalf("default warehouse: got %q want %q", got, want)
}
}
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.

medium

Update the test to use the exported SnowflakeDSN function.

8000
Suggested change
func TestSnowflakeDSNOmitsEmptyRole(t *testing.T) {
got := snowflakeDSN("user", "pw", "acct", "db", "PUBLIC", "WH", "")
want := "user:pw@acct/db/PUBLIC?warehouse=WH"
if got != want {
t.Fatalf("empty role: got %q want %q", got, want)
}
got = snowflakeDSN("user", "pw", "acct", "db", "PUBLIC", "", "ANALYST")
want = "user:pw@acct/db/PUBLIC?warehouse=COMPUTE_WH&role=ANALYST"
if got != want {
t.Fatalf("default warehouse: got %q want %q", got, want)
}
}
func TestSnowflakeDSNOmitsEmptyRole(t *testing.T) {
got := SnowflakeDSN("user", "pw", "acct", "db", "PUBLIC", "WH", "")
want := "user:pw@acct/db/PUBLIC?warehouse=WH"
if got != want {
t.Fatalf("empty role: got %q want %q", got, want)
}
got = SnowflakeDSN("user", "pw", "acct", "db", "PUBLIC", "", "ANALYST")
want = "user:pw@acct/db/PUBLIC?warehouse=COMPUTE_WH&role=ANALYST"
if got != want {
t.Fatalf("default warehouse: got %q want %q", got, want)
}
}

This branch has not been deployed

No deployments
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.

Snowflake source silently defaults role to ACCOUNTADMIN

2 participants

0