Skip to content

Conversation

malikalrizky
Copy link
Contributor

This commit introduces the ip_filter functionality to the google_storage_bucket resource, allowing for more granular, IP-based access controls.

The changes include:

  • A new ip_filter variable in variables.tf to define the IP filtering rules.
  • A dynamic ip_filter block in main.tf to apply the configuration to the storage buckets.
  • An update to versions.tf to enforce a minimum terraform-provider-google version of 6.37.0, which is required for this feature.

@malikalrizky malikalrizky requested review from a team, ayushmjain and q2w as code owners June 10, 2025 06:03
@malikalrizky
Copy link
Contributor Author

should I create test case?

@nitishchauhan94
Copy link

Any timelines when this feature branch would be reviewed and merged ?

Copy link
Collaborator

@q2w q2w left a comment

Choose a reason for hiding this comment

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

Can you also run ENABLE_BPMETADATA=1 make generate_docs so that the metadata files are also updated!

@q2w
Copy link
Collaborator

q2w commented Jul 8, 2025

/gcbrun

@malikalrizky malikalrizky force-pushed the feat/add-ip-filter-support branch from 7ed9cc0 to 972c1eb Compare August 1, 2025 06:02
@malikalrizky malikalrizky requested a review from q2w August 1, 2025 06:06
@malikalrizky
Copy link
Contributor Author

Can you also run ENABLE_BPMETADATA=1 make generate_docs so that the metadata files are also updated!

done @q2w
can i have a review?

@q2w
Copy link
Collaborator

q2w commented Aug 22, 2025

@malikalrizky The integration tests are failing because the apply is failing for both the examples.

TestMultipleBuckets 2025-08-22T16:55:06Z command.go:206: module.cloud_storage.google_storage_bucket.buckets["two"]: Creation complete after 3s [id=multiple-buckets-1elw-two-1fb0]
TestMultipleBuckets 2025-08-22T16:55:06Z command.go:206: 
TestMultipleBuckets 2025-08-22T16:55:06Z command.go:206: Error: Error reading bucket after creation: googleapi: Error 403: There is an IP filtering condition that is preventing access to the resource., forbidden
TestMultipleBuckets 2025-08-22T16:55:06Z command.go:206: 
TestMultipleBuckets 2025-08-22T16:55:06Z command.go:206:   with module.cloud_storage.google_storage_bucket.buckets["one"],
TestMultipleBuckets 2025-08-22T16:55:06Z command.go:206:   on ../../main.tf line 40, in resource "google_storage_bucket" "buckets":
TestMultipleBuckets 2025-08-22T16:55:06Z command.go:206:   40: resource "google_storage_bucket" "buckets" {
TestMultipleBuckets 2025-08-22T16:55:06Z command.go:206: 
TestMultipleBuckets 2025-08-22T16:55:06Z retry.go:99: Returning due to fatal error: FatalError{Underlying: error while running command: exit status 1; 
Error: Error reading bucket after creation: googleapi: Error 403: There is an IP filtering condition that is preventing access to the resource., forbidden

This commit introduces the `ip_filter` functionality to the `google_storage_bucket` resource, allowing for more granular, IP-based access controls.

The changes include:
- A new `ip_filter` variable in `variables.tf` to define the IP filtering rules.
- A dynamic `ip_filter` block in `main.tf` to apply the configuration to the storage buckets.
- An update to `versions.tf` to enforce a minimum `terraform-provider-google` version of `6.37.0`, which is required for this feature.
This update expands the `ip_filter` functionality by allowing for dynamic configuration of public network sources. The changes include:
- A new `ip_filter` variable in `variables.tf` to define the IP filtering rules.
- An updated dynamic block in `main.tf` to apply the public network source settings for allowed IP CIDR ranges.
…and outputs

This commit enhances the README.md by adding comprehensive sections for module requirements, inputs, and outputs. Key additions include:
- Detailed requirements for Terraform and provider versions.
- A complete list of inputs with descriptions and types.
- An overview of outputs available from the module.
This update enhances the `ip_filter` configuration by adding support for VPC network sources. The changes include:
- A new `vpc_network_sources` variable in `variables.tf` to define VPC-specific IP filtering rules.
- An updated dynamic block in `main.tf` to apply the VPC network source settings for allowed IP CIDR ranges.
This commit enhances the `ip_filter` configuration for storage buckets by:
- Updating the `ip_filter` variable to include detailed descriptions and examples for public and VPC network sources.
- Modifying the minimum required Terraform version to `1.3` and the Google provider version to `6.37.0`.
- Adding an example for the `ip_filter` in the README to illustrate its usage.

These changes improve the clarity and functionality of the IP filtering feature.
This commit updates the `ip_filter` configuration for storage buckets by adding two new optional parameters: `allow_cross_org_vpcs` and `allow_all_service_agent_access`. These enhancements provide greater flexibility in managing access controls. Additionally, the Google provider version requirement is updated to `6.49.2` to ensure compatibility with these changes.
@malikalrizky malikalrizky force-pushed the feat/add-ip-filter-support branch from 55d5e3f to 8a9fefb Compare August 23, 2025 02:15
This commit adds the `allow_all_service_agent_access` option to the bucket module, enhancing the configuration flexibility for service agents.
This commit modifies the source paths for the cloud storage modules in the `multiple_buckets` and `simple_bucket` examples to use relative paths instead of the Terraform Google Modules repository.
@malikalrizky
Copy link
Contributor Author

@q2w got it. i saw allow_all_service_agent_access is only available on newer provider versions so i'll use the latest one available.

I have a question about the example configurations and how they interact with integration tests.

Currently, both examples reference the published registry versions:

  • examples/simple_bucket/main.tf: source = "terraform-google-modules/cloud-storage/google//modules/simple_bucket" with version = "~> 10.0"
  • examples/multiple_buckets/main.tf: source = "terraform-google-modules/cloud-storage/google" with version = "~> 10.0"

Question: For integration tests in CI/CD to work properly with new development features (like the new ip_filter fields), should these examples reference the local module paths instead?

For example:

  • examples/simple_bucket/main.tf: source = "../../modules/simple_bucket"
  • examples/multiple_buckets/main.tf: source = "../.."

Context:

  • I'm adding new fields to the ip_filter variable (allow_cross_org_vpcs and allow_all_service_agent_access)
  • The integration tests use CFT's tft.AutoDiscoverAndTest(t) which runs the examples
  • If examples use registry versions, tests would run against the old published code, not the new development features

My understanding: Integration tests should validate the current development code, so examples should reference local paths during development. But I want to confirm the correct pattern before updating.

What's the recommended approach here? Should I:

  • Update examples to use local paths for integration testing?
  • Keep registry references and handle this differently?
  • Use a different pattern entirely?

Thanks for the guidance!

@malikalrizky malikalrizky requested a review from q2w August 23, 2025 02:28
@q2w
Copy link
Collaborator

q2w commented Aug 25, 2025

…ble formatting

This commit updates the source paths for the cloud storage modules in the `multiple_buckets` and `simple_bucket` examples to use the Terraform Google Modules repository. Additionally, it standardizes the formatting of the `allow_cross_org_vpcs` variable in the `variables.tf` files for consistency.
@malikalrizky
Copy link
Contributor Author

@q2w got it. please help review again

malikalrizky and others added 6 commits September 1, 2025 18:21
…pport newer releases

This commit updates the version constraints for the Google provider in the `metadata.yaml` and `versions.tf` files across the main and simple_bucket modules from `>= 6.49.2, < 7` to `>= 6.9.0, < 8`, ensuring compatibility with newer features and improvements.
…izky/terraform-google-cloud-storage into feat/add-ip-filter-support
This commit updates the formatting of the `allow_cross_org_vpcs` variable in the `metadata.yaml` and `README.md` files across the main and simple_bucket modules for consistency. The change ensures uniformity in the presentation of optional boolean variables.
…google-cloud-storage into feat/add-ip-filter-support
@m0ps m0ps force-pushed the feat/add-ip-filter-support branch from 350a894 to fec647a Compare September 22, 2025 02:57
@m0ps
Copy link
Contributor

m0ps commented Sep 22, 2025

Hey, @q2w!
Could you please help review this PR again? The minimum provider version is updated to match the version where ip_filter support was added. I've also added tests to validate ip_filter configuration. Integration tests have been verified in our local environment, and they have completed successfully. I hope that now this PR is ready to merge.

@q2w
Copy link
Collaborator

q2w commented Sep 24, 2025

Thanks @m0ps! I see that the tests are still failing even after enabling allow_all_service_agent_access. This is happening because tests are run using SA provisioned on the fly and doesn't use any service agent to access the buckets.

Since this change is time critical and has been tested locally, i would recommend making changes to example and tests in a followup PR.

@apeabody What do you think?

@apeabody apeabody changed the title feat(storage): Add support for ip_filter to storage buckets feat(storage)!: Add support for ip_filter to storage buckets Sep 24, 2025
@m0ps
Copy link
Contributor

m0ps commented Sep 25, 2025

Thanks for checking it, @apeabody and @q2w
So... I think I've found the problem... When we were running tests, we were running them from our local machines:

  1. bootstrap test project with make docker_test_prepare
  2. run integration tests with make docker_test_integration

I've tried to replicate the Cloud Build setup in our env, and I finally managed to replicate this issue. See the details below.
There are 2 types of ip_sources:

  1. public_network_source
  2. vpc_network_sources
    Examples (which are validated by integration tests) utilize the first option, and that's why it works if we run tests from local machines. But, since Cloud Run is running inside GCP, in a Google-managed VPC, it can't access the bucket after its creation. I've checked IP filtering docs (https://cloud.google.com/storage/docs/ip-filtering-overview#limitations) and didn't find any mentions of Cloud Build, so it's not clear if it is supported at all. But, even if so, I think it makes the test env setup too complicated. Maybe we should skip adding this feature to examples (to avoid its validation by integration tests)?

I'm looking forward to your reply, since this feature is really crucial for us.

@apeabody
Copy link
Contributor

Thanks for checking it, @apeabody and @q2w So... I think I've found the problem... When we were running tests, we were running them from our local machines:

  1. bootstrap test project with make docker_test_prepare
  2. run integration tests with make docker_test_integration

I've tried to replicate the Cloud Build setup in our env, and I finally managed to replicate this issue. See the details below. There are 2 types of ip_sources:

  1. public_network_source
  2. vpc_network_sources
    Examples (which are validated by integration tests) utilize the first option, and that's why it works if we run tests from local machines. But, since Cloud Run is running inside GCP, in a Google-managed VPC, it can't access the bucket after its creation. I've checked IP filtering docs (https://cloud.google.com/storage/docs/ip-filtering-overview#limitations) and didn't find any mentions of Cloud Build, so it's not clear if it is supported at all. But, even if so, I think it makes the test env setup too complicated. Maybe we should skip adding this feature to examples (to avoid its validation by integration tests)?

I'm looking forward to your reply, since this feature is really crucial for us.

Thanks @m0ps - It looks like it should be possible to bypass the bucket IP filtering rules for the test SA: https://cloud.devsite.corp.google.com/storage/docs/bypass-ip-filter#bypass-filtering-rules. That should permit the SA to complete the required storage.buckets.get.

@m0ps
Copy link
Contributor

m0ps commented Sep 26, 2025

Thanks for the hint, @apeabody, but as I mentioned in my prev message, it's not as easy as it looks at a glance. While there is a permission that can allow SA to bypass IP filtering, it allows bypassing only the specific API calls:

However, the simple_bucket example includes IAM roles assignment, which performs a setIamPolicy call, which can't be bypassed. So... I've updated examples to keep the ip_filter feature only for the multiple buckets. I hope you will find this compromise acceptable.

@apeabody
Copy link
Contributor

Thanks for the hint, @apeabody, but as I mentioned in my prev message, it's not as easy as it looks at a glance. While there is a permission that can allow SA to bypass IP filtering, it allows bypassing only the specific API calls:

However, the simple_bucket example includes IAM roles assignment, which performs a setIamPolicy call, which can't be bypassed. So... I've updated examples to keep the ip_filter feature only for the multiple buckets. I hope you will find this compromise acceptable.

Thanks for the deep dive @malikalrizky. Yes, I was focused on the provider's storage.buckets.get, and I think this is acceptable.

@apeabody apeabody changed the title feat(storage)!: Add support for ip_filter to storage buckets feat(TPG>=6.37)!: Add support for ip_filter to storage buckets Sep 26, 2025
Copy link
Contributor

@apeabody apeabody left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @malikalrizky!

@apeabody apeabody merged commit 1b30061 into terraform-google-modules:main Sep 26, 2025
6 checks passed
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.

5 participants