Repository navigation
fix(sources/snowflake)!: leave an empty role out of the DSN - #4601
dendyramdhan wants to merge 1 commit into
Conversation
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
|
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. |
There was a problem hiding this comment.
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.
| // 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 | ||
| } |
There was a problem hiding this comment.
Exporting snowflakeDSN as SnowflakeDSN allows us to reuse it in the integration tests, avoiding code duplication of the DSN building logic.
| // 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) |
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
Update the test to use the exported SnowflakeDSN function.
| 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) | |
| } | |
| } |
Summary
An empty Snowflake
rolewas rewritten toACCOUNTADMINbefore the DSN was built. That is the highest-privilege role in an account, and it is not Snowflake's own default for routine work. Whenroleis omitted, the DSN now leaves it out so Snowflake applies the user's default role.warehousestill defaults toCOMPUTE_WH.This is a behavior change for anyone who relied on the silent
ACCOUNTADMINdefault. Setrole: ACCOUNTADMINexplicitly to keep the old behavior.Fixes #4090
Test
go test ./internal/sources/snowflake/ -count=1passed, including the new DSN cases (empty role omitted, empty warehouse still becomesCOMPUTE_WH) and the existing YAML parse tests.