Skip to main content

More Info:

Ensure that Google Cloud Platform - Resource Location Restriction constraint policy is enforced for your GCP organizations.

Risk Level

Medium

Address

Operational Maturity, Reliability, Security

Compliance Standards

  • Cloudanix Best Practice

Triage and Remediation

Remediation

Using Console

To restrict the creation of cloud resources to specific locations in GCP, you can follow these steps:
  1. Open the GCP console and navigate to the IAM & admin page.
  2. Select the project for which you want to restrict the creation of cloud resources.
  3. Click on the “Edit” button next to the “Service Accounts” section.
  4. Locate the service account that you want to restrict and click on the “Edit” button next to it.
  5. Scroll down to the “Service Account Permissions” section and click on the “Add Another” button.
  6. In the “Add Permission” dialog box, select “Cloud Resource Manager API” from the “Select a service” dropdown menu.
  7. In the “Select a role” dropdown menu, select “Cloud Resource Manager Editor” or “Cloud Resource Manager Viewer” depending on the level of access you want to grant.
  8. In the “Select a resource” dropdown menu, select “All resources in the selected project”.
  9. In the “Condition” section, click on the “Add Condition” button.
  10. In the “Add Condition” dialog box, select “Location” from the “Attribute” dropdown menu.
  11. In the “Operator” dropdown menu, select “is not one of”.
  12. In the “Value” field, enter the list of allowed locations separated by commas (e.g. us-central1, us-west1, europe-west1).
  13. Click on the “Save” button to save the changes.
By following these steps, you have restricted the creation of cloud resources to specific locations in GCP. Any attempt to create resources outside of the allowed locations will be denied.

To restrict the creation of cloud resources to specific locations in GCP, you can follow these steps using the GCP CLI:
  1. Open the GCP Cloud Shell by clicking on the icon in the top right-hand corner of the GCP console.
  2. In the Cloud Shell, enter the following command to list the current organization policy constraints:
  3. Identify the policy constraint that needs to be updated to restrict the creation of cloud resources to specific locations.
  4. Enter the following command to get the details of the policy constraint:
    Replace [CONSTRAINT] with the name of the policy constraint.
  5. Determine the locations to which you want to restrict the creation of cloud resources.
  6. Enter the following command to update the policy constraint to restrict the creation of cloud resources to the specified locations:
    Replace [CONSTRAINT] with the name of the policy constraint and [LOCATION1], [LOCATION2], etc. with the locations to which you want to restrict the creation of cloud resources.
  7. Verify that the policy constraint has been updated by entering the following command:
    Replace [CONSTRAINT] with the name of the policy constraint.
Once these steps are completed, the creation of cloud resources will be restricted to the specified locations in GCP.
To restrict the creation of cloud resources to specific locations in GCP using Python, you can follow these steps:
  1. First, you need to set up a GCP project and install the necessary Python libraries. You can use the google-cloud-resource-manager library to manage GCP resources.
  2. Next, you need to create a configuration file that specifies the allowed locations where resources can be created. For example, you can create a config.yaml file that looks like this:
  1. In your Python script, you can read the configuration file and use it to validate the location of the resources being created. Here’s an example code snippet:
  1. You can repeat this validation for other types of resources as well, such as GCS buckets or Cloud Functions.
By following these steps, you can ensure that your GCP resources are only created in allowed locations, which can help prevent misconfigurations and improve the security of your cloud environment.
Substitute:
  • ORGANIZATION_ID with your org numeric ID.
  • ALLOWED_LOCATION_GROUP_OR_REGION_1/2 with the specific region groups or regions you want to allow.
This does not force replacement of existing projects/resources, but will block creation of new resources outside the allowed locations once applied.Verification: terraform plan should show one google_org_policy_policy.restrict_resource_locations to be created (or updated if it already exists) with name set to constraints/gcp.resourceLocations and your specified allowed_values under spec.rules.values.