From 10198ad61b1cf6955361558ad169ed0922f306cc Mon Sep 17 00:00:00 2001 From: Alijohn Ghassemlouei Date: Tue, 20 Oct 2026 02:27:44 +0000 Subject: [PATCH 1/2] feat(0-bootstrap): gate compute.requireOsLogin by compliance regime Fixes #197 --- .../custom-org-policies/compute_policy.yaml | 22 +++++++++++++++++++ .../data/org-policies/compute_policy.yaml | 5 +---- fast/stages-aw/0-bootstrap/organization.tf | 6 ++--- 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml diff --git a/fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml b/fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml new file mode 100644 index 000000000..ca54e21f3 --- /dev/null +++ b/fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml @@ -0,0 +1,22 @@ +# 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 +# +# http://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. + +--- +%{ if !contains(["IL4", "IL5", "ASSURED_WORKLOADS_IL4", "ASSURED_WORKLOADS_IL5"], regime) ~} +compute.requireOsLogin: + rules: + - enforce: true +%{ else ~} +{} +%{ endif ~} diff --git a/fast/stages-aw/0-bootstrap/data/org-policies/compute_policy.yaml b/fast/stages-aw/0-bootstrap/data/org-policies/compute_policy.yaml index 3841a823a..ae4168933 100644 --- a/fast/stages-aw/0-bootstrap/data/org-policies/compute_policy.yaml +++ b/fast/stages-aw/0-bootstrap/data/org-policies/compute_policy.yaml @@ -80,10 +80,7 @@ compute.disableSerialPortAccess: # OS Login. GKE instances in public clusters do not currently support OS Login. # If this constraint is applied to a Project running public clusters, GKE # instances running in that Project may not function properly. -# COULD HAVE -compute.requireOsLogin: - rules: - - enforce: true +# COULD HAVE (rendered conditionally via custom-org-policies/compute_policy.yaml for non-IL4/IL5 regimes) # This boolean constraint, when set to True, requires that all new Compute diff --git a/fast/stages-aw/0-bootstrap/organization.tf b/fast/stages-aw/0-bootstrap/organization.tf index 9724edd99..250051e46 100644 --- a/fast/stages-aw/0-bootstrap/organization.tf +++ b/fast/stages-aw/0-bootstrap/organization.tf @@ -108,11 +108,11 @@ locals { _org_policies_raw = merge(concat( [ for f in try(fileset("./data/org-policies/", "*_policy.yaml"), []) : - yamldecode(file("./data/org-policies/${f}")) + try({ for k, v in yamldecode(file("./data/org-policies/${f}")) : k => v }, {}) ], [ for f in try(fileset("./data/custom-org-policies/", "*_policy.yaml"), []) : - yamldecode(templatefile("./data/custom-org-policies/${f}", { + try({ for k, v in yamldecode(templatefile("./data/custom-org-policies/${f}", { # NOTE: # If there are more variables need to be substituted, put them # into a separate yaml file or map, use the following line to @@ -124,7 +124,7 @@ locals { drs_tag_name : local.drs_tag_name allowed_domains : var.org_policies_config.constraints.allowed_policy_member_domains regime : var.assured_workloads.regime - })) + })) : k => v }, {}) ] )...) # formalize the policies From 103955ef121d427426e4cccf291ef7090e0f51ec Mon Sep 17 00:00:00 2001 From: Alijohn Ghassemlouei Date: Mon, 26 Oct 2026 19:12:40 +0000 Subject: [PATCH 2/2] fix(0-bootstrap): address review feedback from @Calvin-Cheng1 https://github.com/google/stellar-engine/pull/293#pullrequestreview-5616715353 - fast/stages-aw/0-bootstrap/organization.tf: remove try() wrappers around yamldecode(file(...)) and yamldecode(templatefile(...)) so malformed YAML or template syntax fails fast (@Calvin-Cheng1) (item 1) - fast/stages-aw/0-bootstrap/import.sh: query evaluated keys(local.org_policies) via terraform console instead of grepping unrendered YAML templates (@Calvin-Cheng1) (item 2) - fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml: simplify regime condition to !contains(["IL4", "IL5"], regime) (@Calvin-Cheng1) (item 3) - fast/stages-aw/0-bootstrap/data/org-policies/compute_policy.yaml, fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml: move the compute.requireOsLogin comment block into custom-org-policies and ensure a trailing newline (@Calvin-Cheng1) (item 4) --- cli/tests/test_repo.py | 5 ++++- .../data/custom-org-policies/compute_policy.yaml | 12 +++++++++++- .../data/org-policies/compute_policy.yaml | 12 ------------ fast/stages-aw/0-bootstrap/import.sh | 3 ++- fast/stages-aw/0-bootstrap/organization.tf | 6 +++--- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/cli/tests/test_repo.py b/cli/tests/test_repo.py index 155f03685..4a72421f6 100644 --- a/cli/tests/test_repo.py +++ b/cli/tests/test_repo.py @@ -230,12 +230,15 @@ def test_scan_org_policies_treat_foreign_custom_as_undeclared(repo): _MODERATE_GATED = "compute.managed.restrictProtocolForwardingCreationForTypes" +_IL_GATED = "compute.requireOsLogin" def test_declared_org_policies_follow_the_regime(repo): every = set(repo.declared_org_policies()) moderate = set(repo.declared_org_policies("FEDRAMP_MODERATE")) - assert set(repo.declared_org_policies("IL5")) == every + assert set(repo.declared_org_policies("FEDRAMP_HIGH")) == every + assert set(repo.declared_org_policies("IL4")) == every - {_IL_GATED} + assert set(repo.declared_org_policies("IL5")) == every - {_IL_GATED} assert _MODERATE_GATED in every - moderate # The FedRAMP Moderate branch of an if and else pair still counts. assert "gcp.resourceLocations" in moderate diff --git a/fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml b/fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml index ca54e21f3..3f74ea15d 100644 --- a/fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml +++ b/fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml @@ -13,7 +13,17 @@ # limitations under the License. --- -%{ if !contains(["IL4", "IL5", "ASSURED_WORKLOADS_IL4", "ASSURED_WORKLOADS_IL5"], regime) ~} +%{ if !contains(["IL4", "IL5"], regime) ~} +# This boolean constraint, when set to true, enables OS Login on all newly +# created Projects. All VM instances created in new projects will have OS Login +# enabled. On new and existing projects, this constraint prevents metadata +# updates that disable OS Login at the project or instance level. By default, +# the OS Login feature is disabled on Compute Engine projects.GKE instances in +# private clusters running node pool versions 1.20.5-gke.2000 and later support +# OS Login. GKE instances in public clusters do not currently support OS Login. +# If this constraint is applied to a Project running public clusters, GKE +# instances running in that Project may not function properly. +# COULD HAVE compute.requireOsLogin: rules: - enforce: true diff --git a/fast/stages-aw/0-bootstrap/data/org-policies/compute_policy.yaml b/fast/stages-aw/0-bootstrap/data/org-policies/compute_policy.yaml index ae4168933..0399823bb 100644 --- a/fast/stages-aw/0-bootstrap/data/org-policies/compute_policy.yaml +++ b/fast/stages-aw/0-bootstrap/data/org-policies/compute_policy.yaml @@ -71,18 +71,6 @@ compute.disableSerialPortAccess: # - enforce: false -# This boolean constraint, when set to true, enables OS Login on all newly -# created Projects. All VM instances created in new projects will have OS Login -# enabled. On new and existing projects, this constraint prevents metadata -# updates that disable OS Login at the project or instance level. By default, -# the OS Login feature is disabled on Compute Engine projects.GKE instances in -# private clusters running node pool versions 1.20.5-gke.2000 and later support -# OS Login. GKE instances in public clusters do not currently support OS Login. -# If this constraint is applied to a Project running public clusters, GKE -# instances running in that Project may not function properly. -# COULD HAVE (rendered conditionally via custom-org-policies/compute_policy.yaml for non-IL4/IL5 regimes) - - # This boolean constraint, when set to True, requires that all new Compute # Engine VM instances use Shielded disk images with Secure Boot, vTPM, and # Integrity Monitoring options enabled. Secure Boot can be disabled after diff --git a/fast/stages-aw/0-bootstrap/import.sh b/fast/stages-aw/0-bootstrap/import.sh index 400129b91..3588f770a 100755 --- a/fast/stages-aw/0-bootstrap/import.sh +++ b/fast/stages-aw/0-bootstrap/import.sh @@ -44,6 +44,7 @@ fi echo "Fetching current Terraform state list..." state_list=$(terraform state list 2>/dev/null) +declared_policies=$(echo 'keys(local.org_policies)' | terraform console 2>/dev/null) rm -f imports.tf import_count=0 @@ -55,7 +56,7 @@ while IFS= read -r constraint_path; do target_resource="module.organization.google_org_policy_policy.default[\"${constraint_name}\"]" # Check if constraint is declared in local configuration files - if ! grep -rq "^${constraint_name}:" ./data/org-policies/ ./data/custom-org-policies/ 2>/dev/null; then + if ! echo "${declared_policies}" | grep -qF "\"${constraint_name}\""; then continue fi diff --git a/fast/stages-aw/0-bootstrap/organization.tf b/fast/stages-aw/0-bootstrap/organization.tf index 250051e46..9724edd99 100644 --- a/fast/stages-aw/0-bootstrap/organization.tf +++ b/fast/stages-aw/0-bootstrap/organization.tf @@ -108,11 +108,11 @@ locals { _org_policies_raw = merge(concat( [ for f in try(fileset("./data/org-policies/", "*_policy.yaml"), []) : - try({ for k, v in yamldecode(file("./data/org-policies/${f}")) : k => v }, {}) + yamldecode(file("./data/org-policies/${f}")) ], [ for f in try(fileset("./data/custom-org-policies/", "*_policy.yaml"), []) : - try({ for k, v in yamldecode(templatefile("./data/custom-org-policies/${f}", { + yamldecode(templatefile("./data/custom-org-policies/${f}", { # NOTE: # If there are more variables need to be substituted, put them # into a separate yaml file or map, use the following line to @@ -124,7 +124,7 @@ locals { drs_tag_name : local.drs_tag_name allowed_domains : var.org_policies_config.constraints.allowed_policy_member_domains regime : var.assured_workloads.regime - })) : k => v }, {}) + })) ] )...) # formalize the policies