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.
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
- 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.
-
Verify that you have the permissions required to complete this guide.
-
Verify that billing is enabled for your Google Cloud project.
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.enablepermission. 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.-
Install the gcloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
Verify that you have the permissions required to complete this guide.
-
Verify that billing is enabled for your Google Cloud project.
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.enablepermission. 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.-
Install the gcloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
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.
-
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.
-
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
accessLevelssource.
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.initializeon your workload project -
Verify the workload project allow policy:
resourcemanager.projects.getIamPolicyon your workload project -
Inspect and update service perimeters:
-
accesscontextmanager.policies.liston your organization or scoped access policy -
accesscontextmanager.servicePerimeters.geton your organization or scoped access policy -
accesscontextmanager.servicePerimeters.updateon 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.
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_IDwith your workload project ID.Get the project number for your backup vault project:
gcloud projects describe BACKUP_VAULT_PROJECT_ID \ --format="value(projectNumber)"Replace
BACKUP_VAULT_PROJECT_IDwith your backup vault project ID.Optional: If your projects are in different perimeters, get your access policy ID from the
NAMEcolumn. See the gcloud CLI documentation forgcloud access-context-manager policies list:gcloud access-context-manager policies list \ --organization=ORGANIZATION_IDReplace
ORGANIZATION_IDwith 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
validateOnlytotruestill 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:
- Creating the policy binding: The administrator principal creates the
binding in the backup vault project. The binding
scopefield referencesprojects/WORKLOAD_PROJECT_ID. - 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_IDin the backup vault project. - 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.
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.yamlReplace the following:
WORKLOAD_PERIMETER_NAME: the workload service perimeter name.ACCESS_POLICY_ID: your Access Context Manager access policy ID.
Create a file named
workload-egress.yamland copy any existing items fromstatus.egressPoliciesinworkload-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_NUMBERReplace the following:
WORKLOAD_PROJECT_NUMBER: your workload project number.BACKUP_VAULT_PROJECT_NUMBER: your backup vault project number.
Create a file named
workload-ingress.yamland copy any existing items fromstatus.ingressPoliciesinworkload-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_NUMBERReplace the following:
ADMIN_PRINCIPAL: the user or service account that creates the policy binding (for example,user:dana@example.comorserviceAccount:tf-runner@PROJECT_ID.iam.gserviceaccount.com).BACKUP_VAULT_PROJECT_NUMBER: your backup vault project number.WORKLOAD_PROJECT_NUMBER: your workload project number.
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.yamlReplace
WORKLOAD_PERIMETER_NAMEwith your workload service perimeter name, and replaceACCESS_POLICY_IDwith 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.
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.yamlReplace the following:
BACKUP_VAULT_PERIMETER_NAME: the backup vault service perimeter name.ACCESS_POLICY_ID: your Access Context Manager access policy ID.
Create a file named
vault-ingress.yamland copy any existing items fromstatus.ingressPoliciesinvault-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_NUMBERReplace the following:
WORKLOAD_PROJECT_NUMBER: your workload project number.BACKUP_VAULT_PROJECT_NUMBER: your backup vault project number.
Create a file named
vault-egress.yamland copy any existing items fromstatus.egressPoliciesinvault-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_NUMBERReplace the following:
ADMIN_PRINCIPAL: the user or service account that creates the policy binding (for example,user:dana@example.comorserviceAccount:tf-runner@PROJECT_ID.iam.gserviceaccount.com).WORKLOAD_PROJECT_NUMBER: your workload project number.
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.yamlReplace
BACKUP_VAULT_PERIMETER_NAMEwith your backup vault service perimeter name, and replaceACCESS_POLICY_IDwith 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.
Check the workload project allow policy for the
roles/backupdr.serviceAgentrole. See the gcloud CLI documentation forgcloud 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_IDwith your workload project ID.The output is similar to the following:
serviceAccount:service-WORKLOAD_PROJECT_NUMBER@gcp-sa-backupdr.iam.gserviceaccount.com
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_NAMEwith each updated perimeter name, and replaceACCESS_POLICY_IDwith your access policy ID.Confirm that
status.ingressPoliciesandstatus.egressPolicieslistbackupdr.googleapis.comfor 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.
Recreate your original ingress and egress YAML files from
workload-perimeter-backup.yamlandvault-perimeter-backup.yaml.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_FILEReplace 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
- Create and apply auto-protection policies in Automate resource protection.
- Configure the backup vault service agent rules for Compute Engine in Configure VPC Service Controls for Backup and DR.
- Test ingress and egress rules safely in dry-run mode by reading the VPC Service Controls documentation for Ingress and egress rules.
- Diagnose blocked API calls by reading the VPC Service Controls documentation for Troubleshoot VPC Service Controls.