Skip to content

Commit 878da45

Browse files
authored
feat: new org policies (#791)
* new org policies * inverting the logic for os login constraint enablement * removing unnecessary commnets * Adjusting org policiest location on file definition + other small changes * Adding dynamic allow list length to restricted contacts * Changing essential contacts to use email domains * Removing wrong default value for essential contacts * APplying missing generate docs * removing the need to ask the user to put "@" in front of essential contacts * fixing wrong local placement * wrong locals typing * Adding list of boolean type policy orgs * removing flag for enable os login constraint * changing org policies local var from map to set
1 parent c6f12e2 commit 878da45

File tree

6 files changed

+58
-118
lines changed

6 files changed

+58
-118
lines changed

1-org/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ You can change the filters & sinks by modifying the configuration in `envs/share
8282

8383
**Note:** Currently, this module does not enable [bucket policy retention](https://cloud.google.com/storage/docs/bucket-lock) for organization logs, please, enable it if needed.
8484

85-
**Note:** It is possible to enable an organization policy for [OS Login](https://cloud.google.com/compute/docs/oslogin/manage-oslogin-in-an-org) with this module.
86-
OS Login has some [limitations](https://cloud.google.com/compute/docs/instances/managing-instance-access#limitations).
87-
If those limitations do not apply to your workload/environment, you can choose to enable the OS Login policy by setting variable `enable_os_login_policy` to `true`.
88-
8985
**Note:** You need to set variable `enable_hub_and_spoke` to `true` to be able to use the **Hub-and-Spoke** architecture detailed in the **Networking** section of the [Google Cloud security foundations guide](https://cloud.google.com/architecture/security-foundations/networking#hub-and-spoke).
9086

9187
**Note:** If you are using MacOS, replace `cp -RT` with `cp -R` in the relevant

1-org/envs/shared/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
| dns\_hub\_project\_budget\_amount | The amount to use as the budget for the DNS hub project. | `number` | `1000` | no |
1919
| domains\_to\_allow | The list of domains to allow users from in IAM. Used by Domain Restricted Sharing Organization Policy. Must include the domain of the organization you are deploying the foundation. To add other domains you must also grant access to these domains to the terraform service account used in the deploy. | `list(string)` | n/a | yes |
2020
| enable\_hub\_and\_spoke | Enable Hub-and-Spoke architecture. | `bool` | `false` | no |
21-
| enable\_os\_login\_policy | Enable OS Login Organization Policy. | `bool` | `false` | no |
21+
| essential\_contacts\_domains\_to\_allow | The list of domains that email addresses added to Essential Contacts can have. | `list(string)` | n/a | yes |
2222
| essential\_contacts\_language | Essential Contacts preferred language for notifications, as a ISO 639-1 language code. See [Supported languages](https://cloud.google.com/resource-manager/docs/managing-notification-contacts#supported-languages) for a list of supported languages. | `string` | `"en"` | no |
2323
| gcp\_audit\_viewer | Google Workspace or Cloud Identity group that members are part of an audit team and view audit logs in the logging project. | `string` | `null` | no |
2424
| gcp\_billing\_admin\_user | Identity that has billing administrator permissions. | `string` | `null` | no |

1-org/envs/shared/org_policy.tf

Lines changed: 46 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,42 @@ locals {
1818
organization_id = local.parent_folder != "" ? null : local.org_id
1919
folder_id = local.parent_folder != "" ? local.parent_folder : null
2020
policy_for = local.parent_folder != "" ? "folder" : "organization"
21+
essential_contacts_domains_to_allow = concat(
22+
[for domain in var.essential_contacts_domains_to_allow : "${domain}" if can(regex("^@.*$", domain)) == true],
23+
[for domain in var.essential_contacts_domains_to_allow : "@${domain}" if can(regex("^@.*$", domain)) == false]
24+
)
25+
boolean_type_organization_policies = toset([
26+
"compute.disableNestedVirtualization",
27+
"compute.disableSerialPortAccess",
28+
"compute.disableGuestAttributesAccess",
29+
"compute.skipDefaultNetworkCreation",
30+
"compute.restrictXpnProjectLienRemoval",
31+
"compute.disableVpcExternalIpv6",
32+
"compute.setNewProjectDefaultToZonalDNSOnly",
33+
"compute.requireOsLogin",
34+
"sql.restrictPublicIp",
35+
"iam.disableServiceAccountKeyCreation",
36+
"iam.automaticIamGrantsForDefaultServiceAccounts",
37+
"iam.disableServiceAccountKeyUpload",
38+
"storage.uniformBucketLevelAccess"
39+
])
2140
}
2241

23-
24-
/******************************************
25-
Compute org policies
26-
*******************************************/
27-
28-
module "org_disable_nested_virtualization" {
29-
source = "terraform-google-modules/org-policy/google"
30-
version = "~> 5.1"
31-
organization_id = local.organization_id
32-
folder_id = local.folder_id
33-
policy_for = local.policy_for
34-
policy_type = "boolean"
35-
enforce = "true"
36-
constraint = "constraints/compute.disableNestedVirtualization"
37-
}
38-
39-
module "org_disable_serial_port_access" {
42+
module "organization_policies_type_boolean" {
43+
for_each = local.boolean_type_organization_policies
4044
source = "terraform-google-modules/org-policy/google"
4145
version = "~> 5.1"
4246
organization_id = local.organization_id
4347
folder_id = local.folder_id
4448
policy_for = local.policy_for
4549
policy_type = "boolean"
4650
enforce = "true"
47-
constraint = "constraints/compute.disableSerialPortAccess"
51+
constraint = "constraints/${each.value}"
4852
}
4953

50-
module "org_compute_disable_guest_attributes_access" {
51-
source = "terraform-google-modules/org-policy/google"
52-
version = "~> 5.1"
53-
organization_id = local.organization_id
54-
folder_id = local.folder_id
55-
policy_for = local.policy_for
56-
policy_type = "boolean"
57-
enforce = "true"
58-
constraint = "constraints/compute.disableGuestAttributesAccess"
59-
}
54+
/******************************************
55+
Compute org policies
56+
*******************************************/
6057

6158
module "org_vm_external_ip_access" {
6259
source = "terraform-google-modules/org-policy/google"
@@ -69,53 +66,16 @@ module "org_vm_external_ip_access" {
6966
constraint = "constraints/compute.vmExternalIpAccess"
7067
}
7168

72-
module "org_skip_default_network" {
73-
source = "terraform-google-modules/org-policy/google"
74-
version = "~> 5.1"
75-
organization_id = local.organization_id
76-
folder_id = local.folder_id
77-
policy_for = local.policy_for
78-
policy_type = "boolean"
79-
enforce = "true"
80-
constraint = "constraints/compute.skipDefaultNetworkCreation"
81-
}
82-
83-
module "org_shared_vpc_lien_removal" {
84-
source = "terraform-google-modules/org-policy/google"
85-
version = "~> 5.1"
86-
organization_id = local.organization_id
87-
folder_id = local.folder_id
88-
policy_for = local.policy_for
89-
policy_type = "boolean"
90-
enforce = "true"
91-
constraint = "constraints/compute.restrictXpnProjectLienRemoval"
92-
}
93-
94-
module "org_shared_require_os_login" {
95-
source = "terraform-google-modules/org-policy/google"
96-
count = var.enable_os_login_policy ? 1 : 0
97-
version = "~> 5.1"
98-
organization_id = local.organization_id
99-
folder_id = local.folder_id
100-
policy_for = local.policy_for
101-
policy_type = "boolean"
102-
enforce = "true"
103-
constraint = "constraints/compute.requireOsLogin"
104-
}
105-
106-
/******************************************
107-
Cloud SQL
108-
*******************************************/
109-
110-
module "org_cloudsql_external_ip_access" {
111-
source = "terraform-google-modules/org-policy/google"
112-
version = "~> 5.1"
113-
organization_id = local.organization_id
114-
folder_id = local.folder_id
115-
policy_for = local.policy_for
116-
policy_type = "boolean"
117-
enforce = "true"
118-
constraint = "constraints/sql.restrictPublicIp"
69+
module "restrict_protocol_fowarding" {
70+
source = "terraform-google-modules/org-policy/google"
71+
version = "~> 5.1"
72+
organization_id = local.organization_id
73+
folder_id = local.folder_id
74+
policy_for = local.policy_for
75+
policy_type = "list"
76+
allow = ["INTERNAL"]
77+
allow_list_length = 1
78+
constraint = "constraints/compute.restrictProtocolForwardingCreationForTypes"
11979
}
12080

12181
/******************************************
@@ -131,41 +91,20 @@ module "org_domain_restricted_sharing" {
13191
domains_to_allow = var.domains_to_allow
13292
}
13393

134-
module "org_disable_sa_key_creation" {
135-
source = "terraform-google-modules/org-policy/google"
136-
version = "~> 5.1"
137-
organization_id = local.organization_id
138-
folder_id = local.folder_id
139-
policy_for = local.policy_for
140-
policy_type = "boolean"
141-
enforce = "true"
142-
constraint = "constraints/iam.disableServiceAccountKeyCreation"
143-
}
144-
145-
module "org_disable_automatic_iam_grants_on_default_service_accounts" {
146-
source = "terraform-google-modules/org-policy/google"
147-
version = "~> 5.1"
148-
organization_id = local.organization_id
149-
folder_id = local.folder_id
150-
policy_for = local.policy_for
151-
policy_type = "boolean"
152-
enforce = "true"
153-
constraint = "constraints/iam.automaticIamGrantsForDefaultServiceAccounts"
154-
}
155-
15694
/******************************************
157-
Storage
95+
Essential Contacts
15896
*******************************************/
15997

160-
module "org_enforce_bucket_level_access" {
161-
source = "terraform-google-modules/org-policy/google"
162-
version = "~> 5.1"
163-
organization_id = local.organization_id
164-
folder_id = local.folder_id
165-
policy_for = local.policy_for
166-
policy_type = "boolean"
167-
enforce = "true"
168-
constraint = "constraints/storage.uniformBucketLevelAccess"
98+
module "domain_restricted_contacts" {
99+
source = "terraform-google-modules/org-policy/google"
100+
version = "~> 5.1"
101+
organization_id = local.organization_id
102+
folder_id = local.folder_id
103+
policy_for = local.policy_for
104+
policy_type = "list"
105+
allow_list_length = length(local.essential_contacts_domains_to_allow)
106+
allow = local.essential_contacts_domains_to_allow
107+
constraint = "constraints/essentialcontacts.allowedContactDomains"
169108
}
170109

171110
/******************************************

1-org/envs/shared/terraform.example.tfvars

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// Must include the domain of the organization you are deploying the foundation.
1818
domains_to_allow = ["example.com"]
1919

20+
essential_contacts_domains_to_allow = ["@example.com"]
21+
2022
group_org_admins = "[email protected]"
2123

2224
group_billing_admins = "[email protected]"

1-org/envs/shared/variables.tf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ variable "domains_to_allow" {
4141
type = list(string)
4242
}
4343

44-
variable "enable_os_login_policy" {
45-
description = "Enable OS Login Organization Policy."
46-
type = bool
47-
default = false
48-
}
49-
5044
variable "audit_logs_table_expiration_days" {
5145
description = "Period before tables expire for all audit logs in milliseconds. Default is 30 days."
5246
type = number
@@ -323,3 +317,8 @@ variable "backend_bucket" {
323317
description = "Backend bucket to load remote state information from previous steps."
324318
type = string
325319
}
320+
321+
variable "essential_contacts_domains_to_allow" {
322+
description = "The list of domains that email addresses added to Essential Contacts can have."
323+
type = list(string)
324+
}

test/setup/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ output "domains_to_allow" {
7676
value = tolist([var.domain_to_allow])
7777
}
7878

79+
output "essential_contacts_domains_to_allow" {
80+
value = tolist(["@${var.domain_to_allow}"])
81+
}
82+
7983
output "target_name_server_addresses" {
8084
value = ["192.168.0.1", "192.168.0.2"]
8185
}

0 commit comments

Comments
 (0)