Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Use service user for ci #3228

Merged
merged 26 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
374b51f
Adjust config hierarchy test
sfc-gh-asawicki Nov 20, 2024
5f24aed
Progress with next tests
sfc-gh-asawicki Nov 21, 2024
9bb2347
Progress with next tests part 2
sfc-gh-asawicki Nov 21, 2024
27746eb
Remove unused asserts
sfc-gh-asawicki Nov 22, 2024
b49ef2d
Use tmp user for toml config test
sfc-gh-asawicki Nov 22, 2024
ec59063
Use tmp service user for env config test
sfc-gh-asawicki Nov 22, 2024
158d13f
Use tmp service user for tfconfig test
sfc-gh-asawicki Nov 22, 2024
b5b3048
Use tmp service user for the config hierarchy test
sfc-gh-asawicki Nov 25, 2024
4500654
Move user setup functions
sfc-gh-asawicki Nov 25, 2024
44c6c35
Get rid of only account details profile
sfc-gh-asawicki Nov 26, 2024
e3d10d8
Simplify the test set up
sfc-gh-asawicki Nov 26, 2024
ba06037
Persist toml file as part of the setup
sfc-gh-asawicki Nov 26, 2024
ecb4ed8
Use tmp service user in tests (WIP)
sfc-gh-asawicki Nov 26, 2024
68c9311
Use tmp service user in tests part 2
sfc-gh-asawicki Nov 26, 2024
660822c
Test user+pass login
sfc-gh-asawicki Nov 26, 2024
895c8e3
Test jwt login
sfc-gh-asawicki Nov 26, 2024
3227e38
Get rid of unused profiles
sfc-gh-asawicki Nov 26, 2024
f27fa3a
Clean up tmp user setup helpers
sfc-gh-asawicki Nov 26, 2024
fccf25e
Extract empty auth type
sfc-gh-asawicki Nov 26, 2024
ddbcee9
Add issue numbers
sfc-gh-asawicki Nov 26, 2024
816eaf9
Set config file temporarily
sfc-gh-asawicki Nov 26, 2024
9111355
Run pre-push
sfc-gh-asawicki Nov 26, 2024
7a59c2e
Uncomment assertions
sfc-gh-asawicki Nov 26, 2024
1526af7
Fix tests
sfc-gh-asawicki Nov 27, 2024
5253a50
Merge branch 'main' into use-service-user-for-ci
sfc-gh-asawicki Nov 28, 2024
87ef844
Fix after review
sfc-gh-asawicki Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Create and populate .snowflake/config file
id: create_config
run: mkdir -p $HOME/.snowflake && echo "${{ secrets.SNOWFLAKE_CONFIG_FILE }}" > $HOME/.snowflake/config
run: mkdir -p $HOME/.snowflake && echo "${{ secrets.ASW_TMP_SNOWFLAKE_CONFIG_FILE }}" > $HOME/.snowflake/config
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: will be removed before merging


- name: Create and populate .snowflake/config_v097_compatible file
id: create_config_v097_compatible
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sweep: ## destroy the whole architecture; USE ONLY FOR DEVELOPMENT ACCOUNTS
@echo "Are you sure? [y/n]" >&2
@read -r REPLY; \
if echo "$$REPLY" | grep -qG "^[yY]$$"; then \
TEST_SF_TF_ENABLE_SWEEP=1 go test -timeout 300s -run "^(TestSweepAll|Test_Sweeper_NukeStaleObjects)" ./pkg/sdk -v; \
TEST_SF_TF_ENABLE_SWEEP=1 go test -timeout=10m -run "^(TestSweepAll|Test_Sweeper_NukeStaleObjects)" ./pkg/sdk -v; \
else echo "Aborting..."; \
fi;

Expand Down
23 changes: 0 additions & 23 deletions pkg/acceptance/asserts.go

This file was deleted.

73 changes: 0 additions & 73 deletions pkg/acceptance/asserts_test.go

This file was deleted.

162 changes: 162 additions & 0 deletions pkg/acceptance/helpers/config_toml_creator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package helpers

import (
"fmt"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/helpers/random"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

// FullTomlConfigForServiceUser is a temporary function used to test provider configuration
// TODO [SNOW-1827309]: use toml marshaling from "github.com/pelletier/go-toml/v2"
// TODO [SNOW-1827309]: add builders for our toml config struct
func FullTomlConfigForServiceUser(t *testing.T, profile string, userId sdk.AccountObjectIdentifier, roleId sdk.AccountObjectIdentifier, warehouseId sdk.AccountObjectIdentifier, accountIdentifier sdk.AccountIdentifier, privateKey string) string {
t.Helper()

return fmt.Sprintf(`
[%[1]s]
user = '%[2]s'
privatekey = '''%[7]s'''
role = '%[3]s'
organizationname = '%[5]s'
accountname = '%[6]s'
warehouse = '%[4]s'
clientip = '1.2.3.4'
protocol = 'https'
port = 443
oktaurl = 'https://example.com'
clienttimeout = 10
jwtclienttimeout = 20
logintimeout = 30
requesttimeout = 40
jwtexpiretimeout = 50
externalbrowsertimeout = 60
maxretrycount = 1
authenticator = 'SNOWFLAKE_JWT'
insecuremode = true
ocspfailopen = true
token = 'token'
keepsessionalive = true
disabletelemetry = true
validatedefaultparameters = true
clientrequestmfatoken = true
clientstoretemporarycredential = true
tracing = 'warning'
tmpdirpath = '.'
disablequerycontextcache = true
includeretryreason = true
disableconsolelogin = true

[%[1]s.params]
foo = 'bar'
`, profile, userId.Name(), roleId.Name(), warehouseId.Name(), accountIdentifier.OrganizationName(), accountIdentifier.AccountName(), privateKey)
}

// FullInvalidTomlConfigForServiceUser is a temporary function used to test provider configuration
func FullInvalidTomlConfigForServiceUser(t *testing.T, profile string) string {
t.Helper()

privateKey, _, _, _ := random.GenerateRSAKeyPair(t, "")
return fmt.Sprintf(`
[%[1]s]
user = 'invalid'
privatekey = '''%[2]s'''
role = 'invalid'
accountname = 'invalid'
organizationname = 'invalid'
warehouse = 'invalid'
clientip = 'invalid'
protocol = 'invalid'
port = -1
oktaurl = 'invalid'
clienttimeout = -1
jwtclienttimeout = -1
logintimeout = -1
requesttimeout = -1
jwtexpiretimeout = -1
externalbrowsertimeout = -1
maxretrycount = -1
authenticator = 'snowflake'
insecuremode = true
ocspfailopen = true
token = 'token'
keepsessionalive = true
disabletelemetry = true
validatedefaultparameters = false
clientrequestmfatoken = true
clientstoretemporarycredential = true
tracing = 'invalid'
tmpdirpath = '.'
disablequerycontextcache = true
includeretryreason = true
disableconsolelogin = true

[%[1]s.params]
foo = 'bar'`, profile, privateKey)
}

// TomlConfigForServiceUser is a temporary function used to test provider configuration
func TomlConfigForServiceUser(t *testing.T, profile string, userId sdk.AccountObjectIdentifier, roleId sdk.AccountObjectIdentifier, warehouseId sdk.AccountObjectIdentifier, accountIdentifier sdk.AccountIdentifier, privateKey string) string {
t.Helper()

return fmt.Sprintf(`
[%[1]s]
user = '%[2]s'
privatekey = '''%[7]s'''
role = '%[3]s'
organizationname = '%[5]s'
accountname = '%[6]s'
warehouse = '%[4]s'
authenticator = 'SNOWFLAKE_JWT'
`, profile, userId.Name(), roleId.Name(), warehouseId.Name(), accountIdentifier.OrganizationName(), accountIdentifier.AccountName(), privateKey)
}

// TomlConfigForServiceUserWithEncryptedKey is a temporary function used to test provider configuration
func TomlConfigForServiceUserWithEncryptedKey(t *testing.T, profile string, userId sdk.AccountObjectIdentifier, roleId sdk.AccountObjectIdentifier, warehouseId sdk.AccountObjectIdentifier, accountIdentifier sdk.AccountIdentifier, privateKey string, pass string) string {
t.Helper()

return fmt.Sprintf(`
[%[1]s]
user = '%[2]s'
privatekey = '''%[7]s'''
privatekeypassphrase = '%[8]s'
role = '%[3]s'
organizationname = '%[5]s'
accountname = '%[6]s'
warehouse = '%[4]s'
authenticator = 'SNOWFLAKE_JWT'
`, profile, userId.Name(), roleId.Name(), warehouseId.Name(), accountIdentifier.OrganizationName(), accountIdentifier.AccountName(), privateKey, pass)
}

// TomlIncorrectConfigForServiceUser is a temporary function used to test provider configuration
func TomlIncorrectConfigForServiceUser(t *testing.T, profile string, accountIdentifier sdk.AccountIdentifier) string {
t.Helper()

privateKey, _, _, _ := random.GenerateRSAKeyPair(t, "")
return fmt.Sprintf(`
[%[1]s]
user = 'non-existing-user'
privatekey = '''%[4]s'''
role = 'non-existing-role'
organizationname = '%[2]s'
accountname = '%[3]s'
authenticator = 'SNOWFLAKE_JWT'
`, profile, accountIdentifier.OrganizationName(), accountIdentifier.AccountName(), privateKey)
}

// TomlConfigForLegacyServiceUser is a temporary function used to test provider configuration
func TomlConfigForLegacyServiceUser(t *testing.T, profile string, userId sdk.AccountObjectIdentifier, roleId sdk.AccountObjectIdentifier, warehouseId sdk.AccountObjectIdentifier, accountIdentifier sdk.AccountIdentifier, pass string) string {
t.Helper()

return fmt.Sprintf(`
[%[1]s]
user = '%[2]s'
password = '%[7]s'
role = '%[3]s'
organizationname = '%[5]s'
accountname = '%[6]s'
warehouse = '%[4]s'
authenticator = 'SNOWFLAKE'
`, profile, userId.Name(), roleId.Name(), warehouseId.Name(), accountIdentifier.OrganizationName(), accountIdentifier.AccountName(), pass)
}
10 changes: 10 additions & 0 deletions pkg/acceptance/helpers/context_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ func (c *ContextClient) CurrentAccount(t *testing.T) string {
return currentAccount
}

func (c *ContextClient) CurrentAccountId(t *testing.T) sdk.AccountIdentifier {
t.Helper()
ctx := context.Background()

currentSessionDetails, err := c.client().CurrentSessionDetails(ctx)
require.NoError(t, err)

return sdk.NewAccountIdentifier(currentSessionDetails.OrganizationName, currentSessionDetails.AccountName)
}

func (c *ContextClient) CurrentRole(t *testing.T) sdk.AccountObjectIdentifier {
t.Helper()
ctx := context.Background()
Expand Down
56 changes: 56 additions & 0 deletions pkg/acceptance/helpers/grant_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,62 @@ func (c *GrantClient) RevokePrivilegesOnDatabaseFromDatabaseRole(
require.NoError(t, err)
}

func (c *GrantClient) GrantPrivilegesOnDatabaseToAccountRole(
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
t *testing.T,
accountRoleId sdk.AccountObjectIdentifier,
databaseId sdk.AccountObjectIdentifier,
privileges []sdk.AccountObjectPrivilege,
withGrantOption bool,
) {
t.Helper()
ctx := context.Background()

err := c.client().GrantPrivilegesToAccountRole(
ctx,
&sdk.AccountRoleGrantPrivileges{
AccountObjectPrivileges: privileges,
},
&sdk.AccountRoleGrantOn{
AccountObject: &sdk.GrantOnAccountObject{
Database: sdk.Pointer(databaseId),
},
},
accountRoleId,
&sdk.GrantPrivilegesToAccountRoleOptions{
WithGrantOption: sdk.Bool(withGrantOption),
},
)
require.NoError(t, err)
}

func (c *GrantClient) GrantPrivilegesOnWarehouseToAccountRole(
t *testing.T,
accountRoleId sdk.AccountObjectIdentifier,
warehouseId sdk.AccountObjectIdentifier,
privileges []sdk.AccountObjectPrivilege,
withGrantOption bool,
) {
t.Helper()
ctx := context.Background()

err := c.client().GrantPrivilegesToAccountRole(
ctx,
&sdk.AccountRoleGrantPrivileges{
AccountObjectPrivileges: privileges,
},
&sdk.AccountRoleGrantOn{
AccountObject: &sdk.GrantOnAccountObject{
Warehouse: sdk.Pointer(warehouseId),
},
},
accountRoleId,
&sdk.GrantPrivilegesToAccountRoleOptions{
WithGrantOption: sdk.Bool(withGrantOption),
},
)
require.NoError(t, err)
}

func (c *GrantClient) GrantPrivilegesOnDatabaseToDatabaseRole(
t *testing.T,
databaseRoleId sdk.DatabaseObjectIdentifier,
Expand Down
4 changes: 4 additions & 0 deletions pkg/acceptance/helpers/ids_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (c *IdsGenerator) WarehouseId() sdk.AccountObjectIdentifier {
return sdk.NewAccountObjectIdentifier(c.context.warehouse)
}

func (c *IdsGenerator) SnowflakeWarehouseId() sdk.AccountObjectIdentifier {
return sdk.NewAccountObjectIdentifier("SNOWFLAKE")
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
}

func (c *IdsGenerator) AccountIdentifierWithLocator() sdk.AccountIdentifier {
return sdk.NewAccountIdentifierFromAccountLocator(c.context.client.GetAccountLocator())
}
Expand Down
Loading
Loading