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

Fix sql_database_instance creation to remove root user earlier #6922

Merged
merged 2 commits into from
Dec 16, 2022

Conversation

roaks3
Copy link
Contributor

@roaks3 roaks3 commented Dec 7, 2022

b/254877908

This fixes a bug where a root user without a password would sometimes remain on an sql_database_instance after creation, creating a security risk. The logic in the provider is meant to remove this root user at the end of the creation function, but if there is a failure before then, the instance is still created but the root user remains.

The fix here simply performs the root user removal earlier, so that it is done as soon as it is not longer needed. This eliminates a subset of failure modes that would have left the root user on the instance. I believe this is the best we can do for now, short of more elaborate retry logic.

For testing, it was very difficult to come up with a test that would verify this problem has been resolved, because triggering arbitrary errors is nontrivial, and our test harness does not offer a clean way to check the state of the environment after an error occurs. I've come up with work-arounds to produce a test that I believe is adequate here.

If this PR is for Terraform, I acknowledge that I have:

  • Searched through the issue tracker for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
  • Generated Terraform, and ran make test and make lint to ensure it passes unit and linter tests.
  • Ensured that all new fields I added that can be set by a user appear in at least one example (for generated resources) or third_party test (for handwritten resources or update tests).
  • Ran relevant acceptance tests (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
  • Read the Release Notes Guide before writing my release note below.

Release Note Template for Downstream PRs (will be copied)

sql: fixed `sql_database_instance` leaking root users

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 2 files changed, 159 insertions(+), 27 deletions(-))
Terraform Beta: Diff ( 2 files changed, 159 insertions(+), 27 deletions(-))
TF Validator: Diff ( 2 files changed, 3 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2330
Passed tests 2083
Skipped tests: 245
Failed tests: 2

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccLoggingBucketConfigProject_cmekSettings|TestAccFirebaserulesRelease_BasicRelease

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccLoggingBucketConfigProject_cmekSettings[Debug log]
TestAccFirebaserulesRelease_BasicRelease[Debug log]

All tests passed
View the build log or the debug log for each test

@rileykarson
Copy link
Member

@roaks3: You don't get a reviewer assigned by the Magician anymore, btw! You can assign @GoogleCloudPlatform/terraform-team to roll one.

@roaks3 roaks3 requested review from a team and shuyama1 and removed request for a team December 9, 2022 22:25
Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

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

Comment on lines 2008 to 2011
tier = "db-f1-micro"
backup_configuration {
enabled = false
}
Copy link
Member

Choose a reason for hiding this comment

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

Only nit: spacing is bit off here -- should be spaces instead of tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, thank you!

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 2 files changed, 159 insertions(+), 27 deletions(-))
Terraform Beta: Diff ( 2 files changed, 159 insertions(+), 27 deletions(-))
TF Validator: Diff ( 2 files changed, 3 insertions(+), 3 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2341
Passed tests 2094
Skipped tests: 245
Failed tests: 2

Action taken

Triggering VCR tests in RECORDING mode for the tests that failed during VCR. Click here to see the failed tests
TestAccFirebaserulesRelease_BasicRelease|TestAccLoggingBucketConfigProject_cmekSettings

@modular-magician
Copy link
Collaborator

Tests passed during RECORDING mode:
TestAccFirebaserulesRelease_BasicRelease[Debug log]
TestAccLoggingBucketConfigProject_cmekSettings[Debug log]

All tests passed
View the build log or the debug log for each test

@shuyama1
Copy link
Member

shuyama1 commented Dec 13, 2022

https://ci-oss.hashicorp.engineering/buildConfiguration/GoogleCloudBeta_ProviderGoogleCloudBetaMmUpstream/359847
@roaks3 Test failed on Teamcity. Would you mind taking a look? Were you able to get it pass locally? Change itself looks good to me.

@roaks3
Copy link
Contributor Author

roaks3 commented Dec 13, 2022

Yea, this test passes locally, but we are hitting an issue in CI with a number of these related tests (like TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeReplica and TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone). At first glance, it appears to be having trouble creating the network connection that is a prerequisite of the test.

Copy link
Member

@shuyama1 shuyama1 left a comment

Choose a reason for hiding this comment

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

LGTM!

@roaks3
Copy link
Contributor Author

roaks3 commented Dec 14, 2022

I did some investigating on this test failure and captured my work in hashicorp/terraform-provider-google#12902. I will hold off on merging this momentarily to see if we can resolve the root issue before adding to it with this new test, but if it looks like a long-term fix I will go ahead and move this through.

@roaks3
Copy link
Contributor Author

roaks3 commented Dec 16, 2022

It looks like the other issue could take some time, so merging this change now.

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.

4 participants