Configure VPC Service Controls for auto-protection

This tutorial shows you how to configure VPC Service Controls for Backup and DR auto-protection policies that protect Compute Engine instances and disks. You provision the workload project service agent and apply the ingress and egress rules for your perimeter topology.

Auto-protection policies use the Backup and DR Service Agent in the workload project to manage backup plan associations. This service agent uses the email format service-WORKLOAD_PROJECT_NUMBER@gcp-sa-backupdr.iam.gserviceaccount.com. Complete this configuration before you add a perimeter-protected workload or backup vault project to an auto-protection policy.

This tutorial is intended for security engineers, cloud architects, and backup administrators who manage Compute Engine backups in VPC Service Controls environments.

Objectives

  • Provision the Backup and DR Service Agent in a workload project inside a VPC Service Controls service perimeter.
  • Identify the ingress and egress rules that match your perimeter topology.
  • Apply the required ingress and egress rules to your workload and backup vault service perimeters.
  • Verify the provisioned service agent and enforced perimeter rules.

Costs

In this document, you use the following billable components of Google Cloud:

To generate a cost estimate based on your projected usage, use the pricing calculator.

New Google Cloud users might be eligible for a free trial.

Initializing the service agent with validateOnly set to true doesn't create a backup vault or backup plan. Charges apply when you create backup vaults, store backups, or run Compute Engine resources.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. Verify that you have the permissions required to complete this guide.

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Backup and DR, Access Context Manager, and Compute Engine APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  5. Install the gcloud CLI.

  6. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  7. To initialize the gcloud CLI, run the following command:

    gcloud init
  8. Verify that you have the permissions required to complete this guide.

  9. Verify that billing is enabled for your Google Cloud project.

  10. Enable the Backup and DR, Access Context Manager, and Compute Engine APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  11. Install the gcloud CLI.

  12. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  13. To initialize the gcloud CLI, run the following command:

    gcloud init
  14. Identify two Google Cloud projects in your organization:

    • Backup vault project: contains your backup vault, backup plan, and auto-protection policy.
    • Workload project: contains the Compute Engine instances or disks to protect.
  15. Confirm that an Access Context Manager access policy and service perimeter protect your backup vault project, your workload project, or both. In the VPC Service Controls documentation, see Create a service perimeter.

  16. Confirm that your administrator principal can access the target perimeters from your command environment, such as Cloud Shell, a workstation, or a CI/CD system. Administrators typically gain this access through an existing ingress rule with an accessLevels source.

Required roles

To get the permissions that you need to configure VPC Service Controls for auto-protection policies, ask your administrator to grant you the following IAM roles:

  • Initialize the workload project service agent: Backup and DR Admin (roles/backupdr.admin) on your workload project
  • Verify the workload project allow policy: Security Reviewer (roles/iam.securityReviewer) on your workload project
  • Inspect and update service perimeters: Access Context Manager Editor (roles/accesscontextmanager.policyEditor) on your organization or scoped access policy

For more information about granting roles, see Manage access to projects, folders, and organizations.

These predefined roles contain the permissions required to configure VPC Service Controls for auto-protection policies. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to configure VPC Service Controls for auto-protection policies:

  • Initialize the workload project service agent: backupdr.serviceConfig.initialize on your workload project
  • Verify the workload project allow policy: resourcemanager.projects.getIamPolicy on your workload project
  • Inspect and update service perimeters:
    • accesscontextmanager.policies.list on your organization or scoped access policy
    • accesscontextmanager.servicePerimeters.get on your organization or scoped access policy
    • accesscontextmanager.servicePerimeters.update on your organization or scoped access policy

You might also be able to get these permissions with custom roles or other predefined roles.

Prepare the environment

Gather the project numbers and access policy ID that you need for the YAML rules and commands. Run all commands from an environment authorized to access your service perimeters.

  1. Get the project number for your workload project. See the gcloud CLI documentation for gcloud projects describe:

    gcloud projects describe WORKLOAD_PROJECT_ID \
        --format="value(projectNumber)"
    

    Replace WORKLOAD_PROJECT_ID with your workload project ID.

  2. Get the project number for your backup vault project:

    gcloud projects describe BACKUP_VAULT_PROJECT_ID \
        --format="value(projectNumber)"
    

    Replace BACKUP_VAULT_PROJECT_ID with your backup vault project ID.

  3. Optional: If your projects are in different perimeters, get your access policy ID from the NAME column. See the gcloud CLI documentation for gcloud access-context-manager policies list:

    gcloud access-context-manager policies list \
        --organization=ORGANIZATION_ID
    

    Replace ORGANIZATION_ID with your Google Cloud organization ID.

Provision the Backup and DR Service Agent

If a workload project hasn't created a Backup and DR resource yet, its Backup and DR Service Agent isn't provisioned. When the workload project is inside a VPC Service Controls perimeter, you must provision this service agent from an authorized principal before auto-protection policies can manage backup plan associations.

Limitations

The projects.locations.serviceConfig.initialize request has the following limitation:

  • Setting validateOnly to true still validates the location and customer-managed encryption key (CMEK) organization policies for a default backup vault. If those policies restrict the requested region or require CMEK, then the request can fail.

Initialize the service configuration

Call the projects.locations.serviceConfig.initialize method with validateOnly set to true. This request provisions the service agent without creating a default backup vault or default backup plan.

From an environment authorized to access your VPC Service Controls perimeter, send the following POST request:

curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://backupdr.googleapis.com/v1/projects/WORKLOAD_PROJECT_ID/locations/LOCATION/serviceConfig:initialize" \
    -d '{
      "resourceType": "compute.googleapis.com/Instance",
      "validateOnly": true
    }'

Replace the following:

  • WORKLOAD_PROJECT_ID: the project ID of the workload project.
  • LOCATION: the region of your workload resources and auto-protection policy (for example, us-central1).

When validateOnly is true, Backup and DR provisions service-WORKLOAD_PROJECT_NUMBER@gcp-sa-backupdr.iam.gserviceaccount.com and grants it the Backup and DR Service Agent (roles/backupdr.serviceAgent) role. The method returns a completed operation without creating a default backup vault or backup plan.

Identify your perimeter topology

The required ingress and egress rules depend on how your service perimeters enclose your backup vault and workload projects. The following table summarizes the required steps for each topology.

Perimeter topology Service agent initialization (validateOnly: true) Required perimeter rules
Scenario A: Same perimeter Required None.
Scenario B: Different perimeters Required Configure both the workload and backup vault perimeter rules. Also configure the backup vault service agent rules for Compute Engine.
Scenario C: Only workload project in a perimeter Required Configure the workload perimeter rules. Also configure the backup vault service agent rules for Compute Engine.
Scenario D: Only backup vault project in a perimeter Recommended (or automatic) Configure the backup vault perimeter rules. Also configure the backup vault service agent rules for Compute Engine.

Scenario A: Projects in the same service perimeter

If your backup vault project and workload project share a VPC Service Controls perimeter, you don't need extra ingress or egress rules. After you provision the workload service agent, continue to Verify the configuration.

Scenarios B, C, and D: Projects across perimeter boundaries

When your backup vault project and workload project aren't in the same perimeter, cross-project API calls occur across three operations:

  1. Creating the policy binding: The administrator principal creates the binding in the backup vault project. The binding scope field references projects/WORKLOAD_PROJECT_ID.
  2. Managing backup plan associations: The workload project's Backup and DR Service Agent creates or updates backup plan associations in the workload project. Those associations reference projects/BACKUP_VAULT_PROJECT_ID/locations/LOCATION/backupPlans/BACKUP_PLAN_ID in the backup vault project.
  3. Executing Compute Engine backups: The backup vault service agent backs up Compute Engine instances and disks in the workload project.

In Scenarios B, C, and D, also configure the backup vault service agent rules for Compute Engine alongside the rules in the next section.

Configure perimeter ingress and egress rules

For Scenarios B, C, and D, update the enforced ingress and egress policies on the applicable perimeters. Complete the workload perimeter steps for Scenarios B and C, and complete the backup vault perimeter steps for Scenarios B and D.

Configure workload perimeter rules (Scenarios B and C)

These rules allow the workload service agent to call backupdr.googleapis.com in the backup vault project. These rules also allow the administrator principal to reference the workload project when you create a policy binding.

  1. Export and back up the existing workload perimeter rules. See the gcloud CLI documentation for gcloud access-context-manager perimeters describe:

    gcloud access-context-manager perimeters describe \
        WORKLOAD_PERIMETER_NAME \
        --policy=ACCESS_POLICY_ID \
        --format="yaml(status.ingressPolicies,status.egressPolicies)" \
        > workload-perimeter-backup.yaml
    

    Replace the following:

    • WORKLOAD_PERIMETER_NAME: the workload service perimeter name.
    • ACCESS_POLICY_ID: your Access Context Manager access policy ID.
  2. Create a file named workload-egress.yaml and copy any existing items from status.egressPolicies in workload-perimeter-backup.yaml. Then append the following egress rule:

    # Egress rule in the WORKLOAD project's service perimeter
    - egressFrom:
        identities:
        - serviceAccount:service-WORKLOAD_PROJECT_NUMBER@gcp-sa-backupdr.iam.gserviceaccount.com
      egressTo:
        operations:
        - serviceName: backupdr.googleapis.com
          methodSelectors:
          - method: "*"
        resources:
        - projects/BACKUP_VAULT_PROJECT_NUMBER
    

    Replace the following:

    • WORKLOAD_PROJECT_NUMBER: your workload project number.
    • BACKUP_VAULT_PROJECT_NUMBER: your backup vault project number.
  3. Create a file named workload-ingress.yaml and copy any existing items from status.ingressPolicies in workload-perimeter-backup.yaml. Then append the following ingress rule:

    # Ingress rule in the WORKLOAD project's service perimeter
    - ingressFrom:
        identities:
        - ADMIN_PRINCIPAL
        sources:
        - resource: projects/BACKUP_VAULT_PROJECT_NUMBER
      ingressTo:
        operations:
        - serviceName: backupdr.googleapis.com
          methodSelectors:
          - method: "*"
        resources:
        - projects/WORKLOAD_PROJECT_NUMBER
    

    Replace the following:

    • ADMIN_PRINCIPAL: the user or service account that creates the policy binding (for example, user:dana@example.com or serviceAccount:tf-runner@PROJECT_ID.iam.gserviceaccount.com).
    • BACKUP_VAULT_PROJECT_NUMBER: your backup vault project number.
    • WORKLOAD_PROJECT_NUMBER: your workload project number.
  4. Apply the updated rules to your workload perimeter. See the gcloud CLI documentation for gcloud access-context-manager perimeters update:

    gcloud access-context-manager perimeters update \
        WORKLOAD_PERIMETER_NAME \
        --policy=ACCESS_POLICY_ID \
        --set-egress-policies=workload-egress.yaml \
        --set-ingress-policies=workload-ingress.yaml
    

    Replace WORKLOAD_PERIMETER_NAME with your workload service perimeter name, and replace ACCESS_POLICY_ID with your Access Context Manager access policy ID.

Configure backup vault perimeter rules (Scenarios B and D)

These rules allow the workload service agent to call backupdr.googleapis.com in the backup vault project. These rules also allow the administrator principal to reference the workload project from the backup vault project. The administrator principal still needs ingress access to this perimeter from its command environment to manage Backup and DR resources.

  1. Export and back up the existing backup vault perimeter rules:

    gcloud access-context-manager perimeters describe \
        BACKUP_VAULT_PERIMETER_NAME \
        --policy=ACCESS_POLICY_ID \
        --format="yaml(status.ingressPolicies,status.egressPolicies)" \
        > vault-perimeter-backup.yaml
    

    Replace the following:

    • BACKUP_VAULT_PERIMETER_NAME: the backup vault service perimeter name.
    • ACCESS_POLICY_ID: your Access Context Manager access policy ID.
  2. Create a file named vault-ingress.yaml and copy any existing items from status.ingressPolicies in vault-perimeter-backup.yaml. Then append the following ingress rule:

    # Ingress rule in the BACKUP VAULT project's service perimeter
    - ingressFrom:
        identities:
        - serviceAccount:service-WORKLOAD_PROJECT_NUMBER@gcp-sa-backupdr.iam.gserviceaccount.com
        sources:
        - resource: projects/WORKLOAD_PROJECT_NUMBER
      ingressTo:
        operations:
        - serviceName: backupdr.googleapis.com
          methodSelectors:
          - method: "*"
        resources:
        - projects/BACKUP_VAULT_PROJECT_NUMBER
    

    Replace the following:

    • WORKLOAD_PROJECT_NUMBER: your workload project number.
    • BACKUP_VAULT_PROJECT_NUMBER: your backup vault project number.
  3. Create a file named vault-egress.yaml and copy any existing items from status.egressPolicies in vault-perimeter-backup.yaml. Then append the following egress rule:

    # Egress rule in the BACKUP VAULT project's service perimeter
    - egressFrom:
        identities:
        - ADMIN_PRINCIPAL
      egressTo:
        operations:
        - serviceName: backupdr.googleapis.com
          methodSelectors:
          - method: "*"
        resources:
        - projects/WORKLOAD_PROJECT_NUMBER
    

    Replace the following:

    • ADMIN_PRINCIPAL: the user or service account that creates the policy binding (for example, user:dana@example.com or serviceAccount:tf-runner@PROJECT_ID.iam.gserviceaccount.com).
    • WORKLOAD_PROJECT_NUMBER: your workload project number.
  4. Apply the updated rules to your backup vault perimeter:

    gcloud access-context-manager perimeters update \
        BACKUP_VAULT_PERIMETER_NAME \
        --policy=ACCESS_POLICY_ID \
        --set-ingress-policies=vault-ingress.yaml \
        --set-egress-policies=vault-egress.yaml
    

    Replace BACKUP_VAULT_PERIMETER_NAME with your backup vault service perimeter name, and replace ACCESS_POLICY_ID with your Access Context Manager access policy ID.

Verify the configuration

Confirm that the Backup and DR Service Agent has its required role binding in the workload project. For Scenarios B, C, and D, also confirm that each updated perimeter enforces your new rules.

  1. Check the workload project allow policy for the roles/backupdr.serviceAgent role. See the gcloud CLI documentation for gcloud projects get-iam-policy:

    gcloud projects get-iam-policy WORKLOAD_PROJECT_ID \
        --flatten="bindings[].members" \
        --filter="bindings.role:roles/backupdr.serviceAgent" \
        --format="value(bindings.members)"
    

    Replace WORKLOAD_PROJECT_ID with your workload project ID.

    The output is similar to the following:

    serviceAccount:service-WORKLOAD_PROJECT_NUMBER@gcp-sa-backupdr.iam.gserviceaccount.com
    
  2. For Scenarios B, C, and D, inspect each updated perimeter:

    gcloud access-context-manager perimeters describe \
        PERIMETER_NAME \
        --policy=ACCESS_POLICY_ID \
        --format="yaml(status.ingressPolicies,status.egressPolicies)"
    

    Replace PERIMETER_NAME with each updated perimeter name, and replace ACCESS_POLICY_ID with your access policy ID.

    Confirm that status.ingressPolicies and status.egressPolicies list backupdr.googleapis.com for the expected identities and project numbers.

Clean up

To undo the changes from this tutorial and avoid unexpected charges, revert the perimeter rules in existing projects or delete dedicated test projects.

Revert perimeter rules

If you modified existing service perimeters, remove the rules that you added and restore your previous configuration.

  1. Recreate your original ingress and egress YAML files from workload-perimeter-backup.yaml and vault-perimeter-backup.yaml.

  2. Restore the previous policies on each modified perimeter:

    gcloud access-context-manager perimeters update \
        PERIMETER_NAME \
        --policy=ACCESS_POLICY_ID \
        --set-ingress-policies=INGRESS_YAML_FILE \
        --set-egress-policies=EGRESS_YAML_FILE
    

    Replace the following:

    • PERIMETER_NAME: the perimeter name to restore.
    • ACCESS_POLICY_ID: your Access Context Manager access policy ID.
    • INGRESS_YAML_FILE: the YAML file with original ingress rules.
    • EGRESS_YAML_FILE: the YAML file with original egress rules.

Delete dedicated test projects

If you created dedicated backup vault or workload projects for this tutorial, delete those projects to stop all billing. See the Resource Manager documentation for Shut down (delete) a project.

What's next