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 new file mode 100644 index 000000000..3f74ea15d --- /dev/null +++ b/fast/stages-aw/0-bootstrap/data/custom-org-policies/compute_policy.yaml @@ -0,0 +1,32 @@ +# 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"], 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 +%{ 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..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,21 +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 -compute.requireOsLogin: - rules: - - enforce: true - - # 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