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

feat: OAuth security integration for partner applications #763

Merged
merged 19 commits into from
Dec 1, 2021
Merged

feat: OAuth security integration for partner applications #763

merged 19 commits into from
Dec 1, 2021

Conversation

gouline
Copy link
Contributor

@gouline gouline commented Nov 19, 2021

Implementing OAuth security integration, largely based on the existing SCIM security integration that's quite similar.

This one only covers the partner applications (i.e. Tableau Desktop, Tableau Server and Looker), however extending it to support custom OAuth clients would just involve adding required and optional parameters.

Test Plan

  • acceptance tests

References

@gouline gouline marked this pull request as ready for review November 19, 2021 12:27
@alldoami alldoami requested a review from edulop91 November 19, 2021 19:59
Copy link

@edulop91 edulop91 left a comment

Choose a reason for hiding this comment

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

just a couple of quick comments, thank you!

"oauth_refresh_token_validity": {
Type: schema.TypeInt,
Optional: true,
Description: "Specifies how long refresh tokens should be valid (in seconds). OAUTH_ISSUE_REFRESH_TOKENS must be set to TRUE.",

Choose a reason for hiding this comment

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

do we need oauth_issue_refresh_tokens or would the presence/absence of oauth_refresh_token_validity give us enough information?

Choose a reason for hiding this comment

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

I see that keeping both would more closely match Snowflake's api, so we might want to keep as is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like oauth_issue_refresh_tokens is true by default, so you need it here if you want to set it to false. However, oauth_refresh_token_validity is optional too, it defaults to various values depending on the client (10 hours for Tableau Desktop, 90 days for Tableau Server, etc) - there will be cases where people omit both or specify only one.

pkg/resources/oauth_integration.go Outdated Show resolved Hide resolved
stmt.SetString(`OAUTH_USE_SECONDARY_ROLES`, d.Get("oauth_use_secondary_roles").(string))
}
if _, ok := d.GetOk("blocked_roles_list"); ok {
stmt.SetStringList(`BLOCKED_ROLES_LIST`, expandStringList(d.Get("blocked_roles_list").([]interface{})))

Choose a reason for hiding this comment

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

I think this'll now panic because blocked_roles_list is a set, not []interface{}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't get acceptance tests to run locally, so hopefully this fixes it. Found a similar instance in network policies and copied it:

expandStringList(d.Get("blocked_roles_list").(*schema.Set).List())

@edulop91
Copy link

/ok-to-test sha=d10af87

@github-actions
Copy link

Integration tests failure for d10af87

@edulop91
Copy link

Integration tests failure for d10af87

Looks like there might be a panic here: https://github.com/chanzuckerberg/terraform-provider-snowflake/runs/4301715646?check_suite_focus=true#step:9:1050 (not sure if this log is hidden behind GitHub access controls)

@alldoami
Copy link
Contributor

/ok-to-test sha=3eb42aa

@github-actions
Copy link

Integration tests failure for 3eb42aa

@gouline
Copy link
Contributor Author

gouline commented Nov 25, 2021

CI step integration-trusted failed but I have no access to it, so cannot see what is causing it.

@alldoami
Copy link
Contributor

=== CONT  TestAcc_OAuthIntegration
panic: interface conversion: interface {} is nil, not bool

goroutine 60401 [running]:
github.com/chanzuckerberg/terraform-provider-snowflake/pkg/resources.CreateOAuthIntegration(0x0, {0x14b1940, 0xc002a0c680})
	/home/runner/work/terraform-provider-snowflake/terraform-provider-snowflake/pkg/resources/oauth_integration.go:99 +0x7c5
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x1330a20, {0x17f2748, 0xc000f6ce80}, 0x2, {0x14b1940, 0xc002a0c680})
	/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:318 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00073cb60, {0x17f2748, 0xc000f6ce80}, 0xc00053c270, 0xc003091580, {0x14b1940, 0xc002a0c680})
	/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:456 +0x871
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc003b0c1b0, {0x17f2748, 0xc000f6ce80}, 0xc003e37900)
	/home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:977 +0xd8a
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0026ff4e0, {0x17f27f0, 0xc001833b60}, 0x4423e0)
	/home/runner/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:332 +0x6c
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x14722e0, 0xc0026ff4e0}, {0x17f27f0, 0xc001833b60}, 0xc002634e40, 0x0)
	/home/runner/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00217e540, {0x180adc8, 0xc0025a7b00}, 0xc00299ca20, 0xc0036934a0, 0x2152ee0, 0x0)
	/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1279 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc00217e540, {0x180adc8, 0xc0025a7b00}, 0xc00299ca20, 0x0)
	/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1608 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
	/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:923 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
	/home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:921 +0x294
FAIL	github.com/chanzuckerberg/terraform-provider-snowflake/pkg/resources	356.529s

When you click on the link in this comment, what does it say? #763 (comment)

@gouline
Copy link
Contributor Author

gouline commented Nov 30, 2021

When you click on the link in this comment, what does it say? #763 (comment)

Sorry, this works. I was previously clicking on 'integration-trusted' in the footer (force of habit).

@gouline
Copy link
Contributor Author

gouline commented Nov 30, 2021

Found the problem! Silly copy-paste typo 🤦

@alldoami
Copy link
Contributor

/ok-to-test sha=ba75402

@github-actions
Copy link

Integration tests failure for ba75402

@gouline
Copy link
Contributor Author

gouline commented Nov 30, 2021

Hmm, are these all meant to be treated as strings and parsed to booleans/integers? https://github.com/gouline/terraform-provider-snowflake/blob/161f112/pkg/resources/oauth_integration.go#L186-L201

case "OAUTH_ISSUE_REFRESH_TOKENS":
	if err = d.Set("oauth_issue_refresh_tokens", v.(bool)); err != nil {
		return errors.Wrap(err, "unable to set OAuth issue refresh tokens for security integration")
	}
case "OAUTH_REFRESH_TOKEN_VALIDITY":
	if err = d.Set("oauth_refresh_token_validity", v.(int64)); err != nil {
		return errors.Wrap(err, "unable to set OAuth refresh token validity for security integration")
	}
case "OAUTH_USE_SECONDARY_ROLES":
	if err = d.Set("oauth_use_secondary_roles", v.(string)); err != nil {
		return errors.Wrap(err, "unable to set OAuth use secondary roles for security integration")
	}
case "BLOCKED_ROLES_LIST":
	if err = d.Set("blocked_roles_list", strings.Split(v.(string), ",")); err != nil {
		return errors.Wrap(err, "unable to set blocked roles list for security integration")
	}

I assumed from the ENABLED parameter fed as a boolean in all unit tests, they should be treated as booleans/integers, but ENABLED is always ignored in the switch statement so it might just be copy-pasted mistake that nobody picked up?

descRows := sqlmock.NewRows([]string{
		"property", "property_type", "property_value", "property_default",
	}).AddRow("ENABLED", "Boolean", true, false)

Latest commit treats them as strings, so hopefully that works 🤷

@alldoami
Copy link
Contributor

/ok-to-test sha=c165355

@github-actions
Copy link

Integration tests failure for c165355

@gouline
Copy link
Contributor Author

gouline commented Nov 30, 2021

Previous error looks fixed now, latest commit should fix the new error.

@alldoami
Copy link
Contributor

alldoami commented Dec 1, 2021

/ok-to-test sha=e09bf36

@github-actions
Copy link

github-actions bot commented Dec 1, 2021

Integration tests failure for e09bf36

@gouline
Copy link
Contributor Author

gouline commented Dec 1, 2021

Should be fixed again.

@alldoami
Copy link
Contributor

alldoami commented Dec 1, 2021

/ok-to-test sha=c2634c8

@github-actions
Copy link

github-actions bot commented Dec 1, 2021

Integration tests failure for c2634c8

@gouline
Copy link
Contributor Author

gouline commented Dec 1, 2021

This one was interesting: blocked_roles_list should only include roles not already implicitly enforced (ACCOUNTADMIN, ORGADMIN, SECURITYADMIN) on create, so I had to filter them out from the read. Should work now.

@alldoami
Copy link
Contributor

alldoami commented Dec 1, 2021

/ok-to-test sha=e40332d

@github-actions
Copy link

github-actions bot commented Dec 1, 2021

Integration tests success for e40332d

@alldoami alldoami merged commit 0ec5f4e into Snowflake-Labs:main Dec 1, 2021
daniepett pushed a commit to daniepett/terraform-provider-snowflake that referenced this pull request Feb 9, 2022
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.

3 participants