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

checks if universal_ssl is set in resource configuration to avoid permission issues with strictly scoped API tokens #663

Conversation

cehrig
Copy link
Contributor

@cehrig cehrig commented Apr 22, 2020

@jacobbednarz we came across backwards compatibility issues with strictly scoped API tokens, causing Reads to fail when the token has no permissions reading from the Universal SSL API.

I'm checking if unviersal_ssl is set in the current configuration and skipping API calls if that's not the case

@ghost ghost added the size/XS label Apr 22, 2020
Christian Ehrig added 2 commits April 22, 2020 21:41
@cehrig cehrig changed the title checks if universal_ssl is set in schema before making API calls checks if universal_ssl is set in resource configuration to avoid permission issues with strictly scoped API tokens Apr 22, 2020
@cehrig
Copy link
Contributor Author

cehrig commented Apr 22, 2020

That should be it.

_, err := client.EditUniversalSSLSetting(zoneID, cloudflare.UniversalSSLSetting{Enabled: boolFromString(setting.Value.(string))})
if err != nil {
return zoneSettings, err
if setting.Value.(string) != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why we can't have the if above this as if setting.ID == "universal_ssl && setting.Value.(string) != "" to avoid the extra nesting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case universal_ssl is an empty string in initial_settings we would not remove the element from the slice, passing it to client.UpdateZoneSettings where it's unknown. That could happen when the resource is removed and we did not have initial_settings for this

@jacobbednarz
Copy link
Member

As this identified a regression, we should add a test case to ensure that the scenario encountered is covered going forward.

@patryk patryk added the kind/regression Categorizes issue or PR as related to a regression from a prior release. label Apr 23, 2020
@cehrig
Copy link
Contributor Author

cehrig commented Apr 23, 2020

As this identified a regression, we should add a test case to ensure that the scenario encountered is covered going forward.

I've added to TestAccCloudflareZoneSettingsOverride_Empty checking if initial_settings.0.universal_ssl is an empty string, since we won't make the API call when settings.0.universal_ssl is not provided

@jacobbednarz
Copy link
Member

This has introduced a new failure in the CI suite.

------- Stdout: -------
=== RUN   TestAccCloudflareZoneSettingsOverride_Full
--- FAIL: TestAccCloudflareZoneSettingsOverride_Full (15.07s)
    testing.go:734: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.
        
        Error: Check failed: Final setting for "universal_ssl": off not equal to initial setting: on
        
        State: <no state>
FAIL

@cehrig
Copy link
Contributor Author

cehrig commented Apr 23, 2020

This has introduced a new failure in the CI suite.

------- Stdout: -------
=== RUN   TestAccCloudflareZoneSettingsOverride_Full
--- FAIL: TestAccCloudflareZoneSettingsOverride_Full (15.07s)
    testing.go:734: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.
        
        Error: Check failed: Final setting for "universal_ssl": off not equal to initial setting: on
        
        State: <no state>
FAIL

Can you share how you executed them? This is me running the tests for zone settings override:

cehrig@che-box ~/dev/cf/terraform-provider-cloudflare/cloudflare $ go test -v -timeout 120s github.com/terraform-providers/terraform-provider-cloudflare/cloudflare -run TestAccCloudflareZoneSettingsOverride
=== RUN   TestAccCloudflareZoneSettingsOverride_Empty
--- PASS: TestAccCloudflareZoneSettingsOverride_Empty (26.63s)
=== RUN   TestAccCloudflareZoneSettingsOverride_Full
--- PASS: TestAccCloudflareZoneSettingsOverride_Full (47.68s)
=== RUN   TestAccCloudflareZoneSettingsOverride_RemoveAttributes
--- PASS: TestAccCloudflareZoneSettingsOverride_RemoveAttributes (42.83s)
PASS
ok      github.com/terraform-providers/terraform-provider-cloudflare/cloudflare 117.151s

@jacobbednarz
Copy link
Member

This is coming from our CI suite which piggy backs off make testacc. From your command, it looks like you are missing at least TF_ACC=1 and the credentials to actually perform these tests.

@cehrig
Copy link
Contributor Author

cehrig commented Apr 23, 2020

I have them exported and can see the test making API calls. I can't reproduce right now but will investigate. I'm actually wondering because this part of the existing test wasn't touched.

@cehrig
Copy link
Contributor Author

cehrig commented Apr 23, 2020

Okay, that one happens when the initial setting of the zone the test is running against has universal SSL enabled.

@ghost ghost added size/S and removed size/XS labels Apr 24, 2020
@cehrig
Copy link
Contributor Author

cehrig commented Apr 24, 2020

This should fix the test. We won't pull from the Universal SSL API when we did not have an initial setting. Furthermore we don't know to which initial setting to revert when the resource is deleted. That's actually the scenario that is covered in the Full test. If the universal_ssl setting was set to off is covered by the second step of the test. So I'm just skipping the validation in the final test step testAccCheckInitialZoneSettings.

…form-provider-cloudflare into cehrig/universal-ssl-backwards-compatibility-with-scoped-api-tokens
@jacobbednarz
Copy link
Member

Thanks, we're all good on the integration tests ⭐

@jacobbednarz jacobbednarz merged commit ce747cf into cloudflare:master Apr 27, 2020
boekkooi-lengoo pushed a commit to boekkooi-lengoo/terraform-provider-cloudflare that referenced this pull request Feb 28, 2022
…or-waf-specifics

rulesets: add more WAF coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/regression Categorizes issue or PR as related to a regression from a prior release. size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants