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

Vgm vpc subseg #9298

Merged
merged 26 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c5e5fbb
First commit for VPC sub-segmentation feature. All relevant resources…
vmoros Sep 18, 2023
ceec9bc
Merge branch 'GoogleCloudPlatform:main' into vgm_vpc_subseg
vmoros Sep 19, 2023
203cc96
Adding access levels instead of using a fake access level name. Also …
vmoros Sep 19, 2023
dc7c656
Fixing conflict between ip_subnetworks and vpc_ip_subnetworks
vmoros Sep 19, 2023
b932cce
Undoing changes to access level condition test
vmoros Sep 19, 2023
1bf80fa
Undoing changes to access level condition test
vmoros Sep 19, 2023
4345e60
Ran gofmt
vmoros Sep 19, 2023
6bea598
Merge branch 'GoogleCloudPlatform:main' into vgm_vpc_subseg
vmoros Sep 26, 2023
134d0b2
Re-adding access level conditions tests
vmoros Sep 26, 2023
c9c1592
Merge branch 'GoogleCloudPlatform:main' into vgm_vpc_subseg
vmoros Sep 28, 2023
79ea7b9
Changing resource names to camel case to match what the HTTP response…
vmoros Sep 28, 2023
a52ee0d
Parameterizing the names of VPC networks created in tests
vmoros Sep 28, 2023
6c4a2d6
Merge branch 'main' into vgm_vpc_subseg
vmoros Sep 28, 2023
ad1898f
Fixing access level condition test
vmoros Sep 29, 2023
0752940
Merge branch 'GoogleCloudPlatform:main' into vgm_vpc_subseg
vmoros Sep 29, 2023
26e6d76
Fixed formatting with gofmt
vmoros Sep 29, 2023
582b038
Added missing fields in egress_from for service perimeter test.
yifengli2023 Oct 16, 2023
a77f51b
Merge branch 'GoogleCloudPlatform:main' into vgm_vpc_subseg
yifengli2023 Oct 17, 2023
d870bb6
Added "required: true" for AccessLevel.VpcNetworkSource.network field to
yifengli2023 Oct 18, 2023
61f7ea0
Merge branch 'GoogleCloudPlatform:main' into vgm_vpc_subseg
yifengli2023 Oct 18, 2023
0f5ad72
Added egress source changes to test data in: example_access_context_m…
yifengli2023 Oct 19, 2023
2dc709c
Add Egress Source/source restriction changes to example_access_contex…
yifengli2023 Oct 19, 2023
1fe01cd
Attempt to fix example_access_context_manager_service_perimeter.tfpla…
yifengli2023 Oct 19, 2023
bf26306
Add Egress Source to expected tcg test result data
yifengli2023 Oct 20, 2023
4724854
Fixing expected output format in example_access_context_manager_servi…
yifengli2023 Oct 20, 2023
73f1872
Fix Access Level format in expected output in example_access_context_…
yifengli2023 Oct 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions mmv1/products/accesscontextmanager/AccessLevel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,23 @@ properties:
countries/regions.
Format: A valid ISO 3166-1 alpha-2 code.
item_type: Api::Type::String
- !ruby/object:Api::Type::Array
name: 'vpcNetworkSources'
description: 'The request must originate from one of the provided VPC networks in Google Cloud. Cannot specify this field together with `ip_subnetworks`.'
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::NestedObject
name: 'vpcSubnetwork'
description: 'Sub networks within a VPC network.'
properties:
- !ruby/object:Api::Type::String
name: 'network'
required: true
description: 'Required. Network name to be allowed by this Access Level. Networks of foreign organizations requires `compute.network.get` permission to be granted to caller.'
yifengli2023 marked this conversation as resolved.
Show resolved Hide resolved
- !ruby/object:Api::Type::Array
name: 'vpcIpSubnetworks'
description: 'CIDR block IP subnetwork specification. Must be IPv4.'
item_type: Api::Type::String
- !ruby/object:Api::Type::NestedObject
name: 'custom'
description: |
Expand Down
17 changes: 17 additions & 0 deletions mmv1/products/accesscontextmanager/AccessLevelCondition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,20 @@ properties:
countries/regions.
Format: A valid ISO 3166-1 alpha-2 code.
item_type: Api::Type::String
- !ruby/object:Api::Type::Array
name: 'vpcNetworkSources'
description: 'The request must originate from one of the provided VPC networks in Google Cloud. Cannot specify this field together with `ip_subnetworks`.'
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::NestedObject
name: 'vpcSubnetwork'
description: 'Sub networks within a VPC network.'
properties:
- !ruby/object:Api::Type::String
name: 'network'
yifengli2023 marked this conversation as resolved.
Show resolved Hide resolved
required: true
description: 'Required. Network name to be allowed by this Access Level. Networks of foreign organizations requires `compute.network.get` permission to be granted to caller.'
- !ruby/object:Api::Type::Array
name: 'vpcIpSubnetworks'
description: 'CIDR block IP subnetwork specification. Must be IPv4.'
item_type: Api::Type::String
17 changes: 17 additions & 0 deletions mmv1/products/accesscontextmanager/AccessLevels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ properties:
countries/regions.
Format: A valid ISO 3166-1 alpha-2 code.
item_type: Api::Type::String
- !ruby/object:Api::Type::Array
name: 'vpcNetworkSources'
description: 'The request must originate from one of the provided VPC networks in Google Cloud. Cannot specify this field together with `ip_subnetworks`.'
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::NestedObject
name: 'vpcSubnetwork'
description: 'Sub networks within a VPC network.'
properties:
- !ruby/object:Api::Type::String
name: 'network'
yifengli2023 marked this conversation as resolved.
Show resolved Hide resolved
required: true
description: 'Required. Network name to be allowed by this Access Level. Networks of foreign organizations requires `compute.network.get` permission to be granted to caller.'
- !ruby/object:Api::Type::Array
name: 'vpcIpSubnetworks'
description: 'CIDR block IP subnetwork specification. Must be IPv4.'
item_type: Api::Type::String
- !ruby/object:Api::Type::NestedObject
name: 'custom'
description: |
Expand Down
30 changes: 30 additions & 0 deletions mmv1/products/accesscontextmanager/ServicePerimeter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,21 @@ properties:
- :ANY_IDENTITY
- :ANY_USER_ACCOUNT
- :ANY_SERVICE_ACCOUNT
- !ruby/object:Api::Type::Array
name: 'sources'
description: 'Sources that this EgressPolicy authorizes access from.'
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: 'accessLevel'
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- !ruby/object:Api::Type::Enum
name: 'sourceRestriction'
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
values:
- :SOURCE_RESTRICTION_UNSPECIFIED
- :SOURCE_RESTRICTION_ENABLED
- :SOURCE_RESTRICTION_DISABLED
- !ruby/object:Api::Type::Array
name: 'identities'
description: |
Expand Down Expand Up @@ -619,6 +634,21 @@ properties:
- :ANY_IDENTITY
- :ANY_USER_ACCOUNT
- :ANY_SERVICE_ACCOUNT
- !ruby/object:Api::Type::Array
name: 'sources'
description: 'Sources that this EgressPolicy authorizes access from.'
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: 'accessLevel'
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- !ruby/object:Api::Type::Enum
name: 'sourceRestriction'
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
values:
- :SOURCE_RESTRICTION_UNSPECIFIED
- :SOURCE_RESTRICTION_ENABLED
- :SOURCE_RESTRICTION_DISABLED
- !ruby/object:Api::Type::Array
name: 'identities'
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ properties:
Should be in the format of email address. The email address should
represent individual user or service account only.
item_type: Api::Type::String
- !ruby/object:Api::Type::Array
name: 'sources'
description: 'Sources that this EgressPolicy authorizes access from.'
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: 'accessLevel'
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- !ruby/object:Api::Type::Enum
name: 'sourceRestriction'
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
values:
- :SOURCE_RESTRICTION_UNSPECIFIED
- :SOURCE_RESTRICTION_ENABLED
- :SOURCE_RESTRICTION_DISABLED
- !ruby/object:Api::Type::NestedObject
name: 'egressTo'
description: |
Expand Down
30 changes: 30 additions & 0 deletions mmv1/products/accesscontextmanager/ServicePerimeters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,21 @@ properties:
represent individual user or service account only.
is_set: true
item_type: Api::Type::String
- !ruby/object:Api::Type::Array
name: 'sources'
description: 'Sources that this EgressPolicy authorizes access from.'
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: 'accessLevel'
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- !ruby/object:Api::Type::Enum
name: 'sourceRestriction'
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
values:
- :SOURCE_RESTRICTION_UNSPECIFIED
- :SOURCE_RESTRICTION_ENABLED
- :SOURCE_RESTRICTION_DISABLED
- !ruby/object:Api::Type::NestedObject
name: 'egressTo'
description: |
Expand Down Expand Up @@ -613,6 +628,21 @@ properties:
represent individual user or service account only.
item_type: Api::Type::String
is_set: true
- !ruby/object:Api::Type::Array
name: 'sources'
description: 'Sources that this EgressPolicy authorizes access from.'
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: 'accessLevel'
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- !ruby/object:Api::Type::Enum
name: 'sourceRestriction'
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
values:
- :SOURCE_RESTRICTION_UNSPECIFIED
- :SOURCE_RESTRICTION_ENABLED
- :SOURCE_RESTRICTION_DISABLED
- !ruby/object:Api::Type::NestedObject
name: 'egressTo'
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
resource "google_compute_network" "vpc_network" {
name = "tf-test"
}

resource "google_access_context_manager_access_level" "<%= ctx[:primary_resource_id] %>" {
parent = "accessPolicies/${google_access_context_manager_access_policy.access-policy.name}"
name = "accessPolicies/${google_access_context_manager_access_policy.access-policy.name}/accessLevels/<%= ctx[:vars]['access_level_name'] %>"
title = "<%= ctx[:vars]['access_level_name'] %>"
basic {
conditions {
vpc_network_sources {
vpc_subnetwork {
network = "//compute.googleapis.com/${google_compute_network.vpc_network.id}"
vpc_ip_subnetworks = ["20.0.5.0/24"]
}
}
}
}
}

resource "google_access_context_manager_access_policy" "access-policy" {
parent = "organizations/123456789"
title = "my policy"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func testAccAccessContextManagerAccessLevelCondition_basicTest(t *testing.T) {
project := envvar.GetTestProjectFromEnv()

serviceAccountName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
vpcName := fmt.Sprintf("test-vpc-%s", acctest.RandString(t, 10))

expected := map[string]interface{}{
"ipSubnetworks": []interface{}{"192.0.4.0/24"},
"members": []interface{}{"user:[email protected]", "user:[email protected]", fmt.Sprintf("serviceAccount:%s@%s.iam.gserviceaccount.com", serviceAccountName, project)},
"members": []interface{}{"user:[email protected]", "user:[email protected]", fmt.Sprintf("serviceAccount:%s@%s.iam.gserviceaccount.com", serviceAccountName, project)},
"devicePolicy": map[string]interface{}{
"requireCorpOwned": true,
"osConstraints": []interface{}{
Expand All @@ -35,6 +35,14 @@ func testAccAccessContextManagerAccessLevelCondition_basicTest(t *testing.T) {
},
},
"regions": []interface{}{"IT", "US"},
"vpcNetworkSources": []interface{}{
map[string]interface{}{
"vpcSubnetwork": map[string]interface{}{
"network": fmt.Sprintf("//compute.googleapis.com/projects/%s/global/networks/%s", project, vpcName),
"vpcIpSubnetworks": []interface{}{"20.0.5.0/24"},
},
},
},
}

acctest.VcrTest(t, resource.TestCase{
Expand All @@ -43,7 +51,7 @@ func testAccAccessContextManagerAccessLevelCondition_basicTest(t *testing.T) {
CheckDestroy: testAccCheckAccessContextManagerAccessLevelConditionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccAccessContextManagerAccessLevelCondition_basic(org, "my policy", "level", serviceAccountName),
Config: testAccAccessContextManagerAccessLevelCondition_basic(org, "my policy", "level", serviceAccountName, vpcName),
Check: testAccCheckAccessContextManagerAccessLevelConditionPresent(t, "google_access_context_manager_access_level_condition.access-level-condition", expected),
},
},
Expand Down Expand Up @@ -111,7 +119,7 @@ func testAccCheckAccessContextManagerAccessLevelConditionDestroyProducer(t *test
}
}

func testAccAccessContextManagerAccessLevelCondition_basic(org, policyTitle, levelTitleName, saName string) string {
func testAccAccessContextManagerAccessLevelCondition_basic(org, policyTitle, levelTitleName, saName, vpcName string) string {
return fmt.Sprintf(`
resource "google_access_context_manager_access_policy" "test-access" {
parent = "organizations/%s"
Expand Down Expand Up @@ -139,10 +147,6 @@ resource "google_access_context_manager_access_level" "test-access" {
"US",
]
}

conditions {
ip_subnetworks = ["176.0.4.0/24"]
}
}

lifecycle {
Expand All @@ -154,9 +158,12 @@ resource "google_service_account" "created-later" {
account_id = "%s"
}

resource "google_compute_network" "vpc_network" {
name = "%s"
}

resource "google_access_context_manager_access_level_condition" "access-level-condition" {
access_level = google_access_context_manager_access_level.test-access.name
ip_subnetworks = ["192.0.4.0/24"]
members = ["user:[email protected]", "user:[email protected]", "serviceAccount:${google_service_account.created-later.email}"]
negate = false
device_policy {
Expand All @@ -171,6 +178,13 @@ resource "google_access_context_manager_access_level_condition" "access-level-co
"IT",
"US",
]

vpc_network_sources {
vpc_subnetwork {
network = "//compute.googleapis.com/${google_compute_network.vpc_network.id}"
vpc_ip_subnetworks = ["20.0.5.0/24"]
}
}
}
`, org, policyTitle, levelTitleName, levelTitleName, saName)
`, org, policyTitle, levelTitleName, levelTitleName, saName, vpcName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import (

func testAccAccessContextManagerAccessLevel_basicTest(t *testing.T) {
org := envvar.GetTestOrgFromEnv(t)
vpcName := fmt.Sprintf("test-vpc-%s", acctest.RandString(t, 10))

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckAccessContextManagerAccessLevelDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccAccessContextManagerAccessLevel_basic(org, "my policy", "level"),
Config: testAccAccessContextManagerAccessLevel_basic(org, "my policy", "level", vpcName),
},
{
ResourceName: "google_access_context_manager_access_level.test-access",
Expand Down Expand Up @@ -114,7 +115,7 @@ func testAccAccessContextManagerAccessLevel_customTest(t *testing.T) {
})
}

func testAccAccessContextManagerAccessLevel_basic(org, policyTitle, levelTitleName string) string {
func testAccAccessContextManagerAccessLevel_basic(org, policyTitle, levelTitleName, vpcName string) string {
return fmt.Sprintf(`
resource "google_access_context_manager_access_policy" "test-access" {
parent = "organizations/%s"
Expand All @@ -133,7 +134,30 @@ resource "google_access_context_manager_access_level" "test-access" {
}
}
}
`, org, policyTitle, levelTitleName, levelTitleName)

resource "google_compute_network" "vpc_network" {
name = "%s"
}

resource "google_access_context_manager_access_level" "test-access2" {
parent = "accessPolicies/${google_access_context_manager_access_policy.test-access.name}"
name = "accessPolicies/${google_access_context_manager_access_policy.test-access.name}/accessLevels/%s2"
title = "%s2"
description = "hello2"
basic {
combining_function = "AND"
conditions {
vpc_network_sources {
vpc_subnetwork {
network = "//compute.googleapis.com/${google_compute_network.vpc_network.id}"
vpc_ip_subnetworks = ["20.0.5.0/24"]
}
}
}
}
}

`, org, policyTitle, levelTitleName, levelTitleName, vpcName, levelTitleName, levelTitleName)
}

func testAccAccessContextManagerAccessLevel_custom(org, policyTitle, levelTitleName string) string {
Expand Down
Loading