-
Notifications
You must be signed in to change notification settings - Fork 415
feat(storage): add support for bucket ip filter #15250
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
Open
ddelgrosso1
wants to merge
10
commits into
googleapis:main
Choose a base branch
from
ddelgrosso1:bucket-ip-filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+888
−1
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
79eae24
feat(storage): add support for bucket ip filter
ddelgrosso1 8947c1f
fix unit tests
ddelgrosso1 a021089
bump testbench version
ddelgrosso1 605bc4c
fix comment
ddelgrosso1 f84d2c5
checkers
ddelgrosso1 497136d
use emplace_back
ddelgrosso1 c46f083
fix vpc name format
ddelgrosso1 c24e0b3
address feedback
ddelgrosso1 ba10fa3
fix test
ddelgrosso1 7b8b0e3
add new test
ddelgrosso1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/storage/bucket_ip_filter.h" | ||
#include "google/cloud/internal/absl_str_join_quiet.h" | ||
#include "google/cloud/internal/ios_flags_saver.h" | ||
#include <iostream> | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace storage { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
bool operator==(BucketIpFilterPublicNetworkSource const& lhs, | ||
BucketIpFilterPublicNetworkSource const& rhs) { | ||
return lhs.allowed_ip_cidr_ranges == rhs.allowed_ip_cidr_ranges; | ||
} | ||
|
||
bool operator!=(BucketIpFilterPublicNetworkSource const& lhs, | ||
BucketIpFilterPublicNetworkSource const& rhs) { | ||
return !(lhs == rhs); | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, | ||
BucketIpFilterPublicNetworkSource const& rhs) { | ||
return os << "BucketIpFilterPublicNetworkSource={allowed_ip_cidr_ranges=[" | ||
<< absl::StrJoin(rhs.allowed_ip_cidr_ranges, ", ") << "]}"; | ||
} | ||
|
||
bool operator==(BucketIpFilterVpcNetworkSource const& lhs, | ||
BucketIpFilterVpcNetworkSource const& rhs) { | ||
return std::tie(lhs.network, lhs.allowed_ip_cidr_ranges) == | ||
std::tie(rhs.network, rhs.allowed_ip_cidr_ranges); | ||
} | ||
|
||
bool operator!=(BucketIpFilterVpcNetworkSource const& lhs, | ||
BucketIpFilterVpcNetworkSource const& rhs) { | ||
return !(lhs == rhs); | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, | ||
BucketIpFilterVpcNetworkSource const& rhs) { | ||
return os << "BucketIpFilterVpcNetworkSource={network=" << rhs.network | ||
<< ", allowed_ip_cidr_ranges=[" | ||
<< absl::StrJoin(rhs.allowed_ip_cidr_ranges, ", ") << "]}"; | ||
} | ||
|
||
bool operator==(BucketIpFilter const& lhs, BucketIpFilter const& rhs) { | ||
return std::tie(lhs.allow_all_service_agent_access, lhs.allow_cross_org_vpcs, | ||
lhs.mode, lhs.public_network_source, | ||
lhs.vpc_network_sources) == | ||
std::tie(rhs.allow_all_service_agent_access, rhs.allow_cross_org_vpcs, | ||
rhs.mode, rhs.public_network_source, rhs.vpc_network_sources); | ||
} | ||
|
||
bool operator!=(BucketIpFilter const& lhs, BucketIpFilter const& rhs) { | ||
return !(lhs == rhs); | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, BucketIpFilter const& rhs) { | ||
google::cloud::internal::IosFlagsSaver save_format(os); | ||
os << "BucketIpFilter={mode=" << rhs.mode.value_or(""); | ||
if (rhs.allow_all_service_agent_access) { | ||
os << ", allow_all_service_agent_access=" << std::boolalpha | ||
<< *rhs.allow_all_service_agent_access; | ||
} | ||
if (rhs.allow_cross_org_vpcs) { | ||
os << ", allow_cross_org_vpcs=" << std::boolalpha | ||
<< *rhs.allow_cross_org_vpcs; | ||
} | ||
if (rhs.public_network_source) { | ||
os << ", public_network_source=" << *rhs.public_network_source; | ||
} | ||
if (rhs.vpc_network_sources) { | ||
os << ", vpc_network_sources=[" | ||
<< absl::StrJoin(*rhs.vpc_network_sources, ", ", absl::StreamFormatter()) | ||
<< "]"; | ||
} | ||
return os << "}"; | ||
} | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace storage | ||
} // namespace cloud | ||
} // namespace google |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_BUCKET_IP_FILTER_H | ||
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_BUCKET_IP_FILTER_H | ||
|
||
#include "google/cloud/storage/version.h" | ||
#include "absl/types/optional.h" | ||
#include <iosfwd> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace storage { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
/** | ||
* Defines a public network source for the bucket IP filter. | ||
*/ | ||
struct BucketIpFilterPublicNetworkSource { | ||
std::vector<std::string> allowed_ip_cidr_ranges; | ||
}; | ||
|
||
bool operator==(BucketIpFilterPublicNetworkSource const& lhs, | ||
BucketIpFilterPublicNetworkSource const& rhs); | ||
bool operator!=(BucketIpFilterPublicNetworkSource const& lhs, | ||
BucketIpFilterPublicNetworkSource const& rhs); | ||
|
||
std::ostream& operator<<(std::ostream& os, | ||
BucketIpFilterPublicNetworkSource const& rhs); | ||
|
||
/** | ||
* Defines a VPC network source for the bucket IP filter. | ||
*/ | ||
struct BucketIpFilterVpcNetworkSource { | ||
std::string network; | ||
std::vector<std::string> allowed_ip_cidr_ranges; | ||
}; | ||
|
||
bool operator==(BucketIpFilterVpcNetworkSource const& lhs, | ||
BucketIpFilterVpcNetworkSource const& rhs); | ||
bool operator!=(BucketIpFilterVpcNetworkSource const& lhs, | ||
BucketIpFilterVpcNetworkSource const& rhs); | ||
|
||
std::ostream& operator<<(std::ostream& os, | ||
BucketIpFilterVpcNetworkSource const& rhs); | ||
|
||
/** | ||
* The IP filtering configuration for a Bucket. | ||
*/ | ||
struct BucketIpFilter { | ||
absl::optional<bool> allow_all_service_agent_access; | ||
absl::optional<bool> allow_cross_org_vpcs; | ||
absl::optional<std::string> mode; | ||
absl::optional<BucketIpFilterPublicNetworkSource> public_network_source; | ||
absl::optional<std::vector<BucketIpFilterVpcNetworkSource>> | ||
vpc_network_sources; | ||
}; | ||
|
||
bool operator==(BucketIpFilter const& lhs, BucketIpFilter const& rhs); | ||
bool operator!=(BucketIpFilter const& lhs, BucketIpFilter const& rhs); | ||
|
||
std::ostream& operator<<(std::ostream& os, BucketIpFilter const& rhs); | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace storage | ||
} // namespace cloud | ||
} // namespace google | ||
|
||
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_BUCKET_IP_FILTER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/storage/bucket_ip_filter.h" | ||
#include <gmock/gmock.h> | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace storage { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
namespace { | ||
|
||
TEST(BucketIpFilterTest, PublicNetworkSource) { | ||
BucketIpFilterPublicNetworkSource source; | ||
source.allowed_ip_cidr_ranges.emplace_back("1.2.3.4/32"); | ||
source.allowed_ip_cidr_ranges.emplace_back("5.6.7.8/32"); | ||
|
||
BucketIpFilterPublicNetworkSource copy = source; | ||
EXPECT_EQ(source, copy); | ||
|
||
copy.allowed_ip_cidr_ranges.pop_back(); | ||
EXPECT_NE(source, copy); | ||
} | ||
|
||
TEST(BucketIpFilterTest, PublicNetworkSourceOrderMatters) { | ||
BucketIpFilterPublicNetworkSource const source1{{"1.2.3.4/32", "5.6.7.8/32"}}; | ||
BucketIpFilterPublicNetworkSource const source2{{"5.6.7.8/32", "1.2.3.4/32"}}; | ||
|
||
// The two sources have the same elements but in a different order. | ||
// They should NOT be equal. | ||
EXPECT_NE(source1, source2); | ||
} | ||
|
||
TEST(BucketIpFilterTest, VpcNetworkSource) { | ||
BucketIpFilterVpcNetworkSource source; | ||
source.network = "projects/p/global/networks/n"; | ||
source.allowed_ip_cidr_ranges.emplace_back("1.2.3.4/32"); | ||
source.allowed_ip_cidr_ranges.emplace_back("5.6.7.8/32"); | ||
|
||
BucketIpFilterVpcNetworkSource copy = source; | ||
EXPECT_EQ(source, copy); | ||
|
||
copy.network = "changed"; | ||
EXPECT_NE(source, copy); | ||
} | ||
|
||
TEST(BucketIpFilterTest, VpcNetworkSourceOrderMatters) { | ||
BucketIpFilterVpcNetworkSource const source1{"projects/p/global/networks/n", | ||
{"1.2.3.4/32", "5.6.7.8/32"}}; | ||
BucketIpFilterVpcNetworkSource const source2{"projects/p/global/networks/n", | ||
{"5.6.7.8/32", "1.2.3.4/32"}}; | ||
|
||
// The two sources have the same elements but in a different order. | ||
// They should NOT be equal. | ||
EXPECT_NE(source1, source2); | ||
} | ||
|
||
TEST(BucketIpFilterTest, IpFilter) { | ||
BucketIpFilter filter; | ||
filter.mode = "Enabled"; | ||
filter.allow_all_service_agent_access = true; | ||
filter.allow_cross_org_vpcs = true; | ||
filter.public_network_source = | ||
BucketIpFilterPublicNetworkSource{{"1.2.3.4/32"}}; | ||
filter.vpc_network_sources = | ||
absl::make_optional<std::vector<BucketIpFilterVpcNetworkSource>>( | ||
{BucketIpFilterVpcNetworkSource{"projects/p/global/networks/n", | ||
{"5.6.7.8/32"}}, | ||
BucketIpFilterVpcNetworkSource{"projects/p/global/networks/m", | ||
{"9.0.1.2/32"}}}); | ||
|
||
BucketIpFilter copy = filter; | ||
EXPECT_EQ(filter, copy); | ||
|
||
copy.mode = "Disabled"; | ||
EXPECT_NE(filter, copy); | ||
} | ||
|
||
TEST(BucketIpFilterTest, IpFilterOrderMatters) { | ||
BucketIpFilter filter1; | ||
filter1.vpc_network_sources = | ||
absl::make_optional<std::vector<BucketIpFilterVpcNetworkSource>>( | ||
{BucketIpFilterVpcNetworkSource{"projects/p/global/networks/n", | ||
{"1.2.3.4/32"}}, | ||
BucketIpFilterVpcNetworkSource{"projects/p/global/networks/m", | ||
{"5.6.7.8/32"}}}); | ||
|
||
BucketIpFilter filter2; | ||
filter2.vpc_network_sources = | ||
absl::make_optional<std::vector<BucketIpFilterVpcNetworkSource>>( | ||
{BucketIpFilterVpcNetworkSource{"projects/p/global/networks/m", | ||
{"5.6.7.8/32"}}, | ||
BucketIpFilterVpcNetworkSource{"projects/p/global/networks/n", | ||
{"1.2.3.4/32"}}}); | ||
|
||
// The two filters have the same elements but in a different order. | ||
// They should NOT be equal. | ||
EXPECT_NE(filter1, filter2); | ||
} | ||
|
||
} // namespace | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace storage | ||
} // namespace cloud | ||
} // namespace google |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.