Protect Compute Engine using a VPC Service Controls perimeter Stay organized with collections Save and categorize content based on your preferences.
This tutorial shows you how to protect Compute Engine using a serviceperimeter and troubleshoot an ingress violation to allow authorized access toCompute Engine.
VPC Service Controls enables you to define a service perimeter aroundresources of Google-managed services to control communication to and betweenthose services. You can establish a zero-trust perimeter around your sensitiveresources, restricting access to authorized IP addresses, users, and devices. Thiscapability lets you define security policies that prevent access toGoogle-managed services outside of a trusted perimeter, block access to datafrom untrusted locations, and mitigate data exfiltration risks.
This tutorial is intended for Google Cloud organization administrators whowant to learn the basic VPC Service Controls concepts.
Objectives
- Understand the basics of VPC Service Controls.
- Create a service perimeter.
- Protect a project using VPC Service Controls.
- Troubleshoot a VPC Service Controls ingress violation.
Costs
In this document, you use the following billable components of Google Cloud:
To generate a cost estimate based on your projected usage, use thepricing calculator.
When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, seeClean up.
Before you begin
You need to have a Google Cloudorganization resource.If you don't have a Google Workspace or Cloud Identity accountalready, you mustacquire oneand that creates an organization resource automatically for you.
Create a folder,
Exercise, at the organization level.Create two projects,
My-Project-1andMy-Project-2, in theExercisefolder within the same organization.Make sure that you have the following permissions and roles at theorganization level:
Permissions and rolesrequired to configure VPC Service Controls.
Permissions and roles required to manageCompute Engine.
Create a service perimeter
Create a service perimeter that protects the Compute Engine API in theMy-Project-2 project:
In the Google Cloud console, go to theVPC Service Controls page.
Make sure that you are in the organization scope.
ClickManage policies.
Create a new accesspolicythat is scoped to the
Exercisefolder.Create a newperimeter with thefollowing details:
Title:
MyFirstPerimeterPerimeter type:Regular
Enforcement mode:Enforced
Resources to protect:
My-Project-2projectRestricted services:Compute Engine API
Verify the perimeter
In this section, you can make access requests to the resources in the projectsto confirm whether the perimeter protects the intended resources.
Access the
My-Project-1project and verify that you can accessCompute Engine by visitingVM instances page.You should be able to access because
My-Project-1is not protected by theperimeter that you created earlier.Access the
My-Project-2project and verify that you can accessCompute Engine by visitingVM instances page.You should see that VPC Service Controls denies your request to accessCompute Engine because the
MyFirstPerimeterperimeter protectsMy-Project-2and the Compute Engine API.
Troubleshoot a violation
VPC Service Controls audit logsinclude details about requests to protected resources and the reason whyVPC Service Controls denied the request. You need this information to identify andtroubleshoot the violation in theMy-Project-2 project.
View audit logs
Find the unique ID of the VPC Service Controls violation in the
My-Project-2project's audit logs:In the Google Cloud console, go to theLogs Explorer page:
If you use the search bar to find this page, then select the result whose subheading isLogging.
Select the
My-Project-2project.To display all audit logs, enter the following query into thequery-editor field:
resource.type="audited_resource"protoPayload.metadata."@type"="type.googleapis.com/google.cloud.audit.VpcServiceControlAuditMetadata"
ClickRun query.
This query displays all VPC Service Controls audit logs. To find the violationdetails for accessing the Compute Engine API in the
Note: To filter the logs more granularly, you can use thesesamplequeries and add theVPC Service Controls unique ID that you received whileverifying theperimeter.My-Project-2project, check the last error log.For more information, seeView logs.
In theQuery results pane, clickVPC Service Controls next to thedenial that you want to troubleshoot, and then clickTroubleshoot denial.
TheVPC Service Controls violation analyzerpage opens. This page shows the violation reason and other information suchas if the violation is an ingress or egress violation.
In this tutorial, look for the following information:
"principalEmail": "USER@DOMAIN""callerIp": "PUBLIC_IP_ADDRESS""serviceName": "compute.googleapis.com""servicePerimeterName":"accessPolicies/POLICY_NUMBER/servicePerimeters/MyFirstPerimeter"ingressViolations": [ {"targetResource": "projects/PROJECT_NUMBER","servicePerimeter": "accessPolicies/POLICY_NUMBER/servicePerimeters/MyFirstPerimeter" } ],"violationReason": "NO_MATCHING_ACCESS_LEVEL","resourceNames": "PROJECT_ID"The violation reason is
"NO_MATCHING_ACCESS_LEVEL". The"NO_MATCHING_ACCESS_LEVEL"violation occurs when the IP address, device type, or user identity doesn'tmatch any ingress rules or access levels that are associated with the perimeter.If the caller IP address is missing or appears as an internal IP address inthe log, then this violation can be due to a Google Cloud service thatis notsupported by VPC Service Controls.
To fix this denial in theMy-Project-2 project, you have two options:
Create anaccess level that allowsaccess to your system IP address to the project inside the perimeter.
Create aningress rulethat allows access to an API client from outside the perimeter to resourceswithin the perimeter.
The following section illustrates how to troubleshoot this denial by creating anaccess level.
Create an access level
In the Google Cloud console, go to theAccess Context Manager page atthe
Exercisefolder scope.Create an access levelwith the following details:
ForCreate conditions in, selectBasic mode.
ForWhen condition is met, return, selectTrue.
Select theIP Subnetworks attribute, specify your system's public IPaddress.
Select theGeographic locations attribute, specify your geographiclocation.
This access level allows access only when the IP address and the geographiclocation is matched.
Go to theVPC Service Controls page at the organization scope.
Select the access policy that you created earlier in this tutorial.
Add the access levelthat you created at the
Exercisefolder scope to theMyFirstPerimeterperimeter.
Test the access
After you add the access level, verify that you can access Compute Enginein theMy-Project-2 project and create a VM instance.
In the Google Cloud console, go to theVM instances page.
- Note: Retain the default values in the fields and create a low-cost VMinstance.
After about a minute, Compute Engine creates a VM instance and thisaction verifies that you have full access to Compute Engine protectedinside the perimeter.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.
Delete the project
Delete individual resources
Delete VM instances
- In the Google Cloud console, go to theVM instances page.
- Select the checkbox for the instance that you want to delete.
- To delete the instance, clickMore actions, clickDelete, and then follow the instructions.
Delete VPC Service Controls resources
Delete the access levelthat you created at the
Exercisefolder scope.
What's next
- Learn how todiagnose an access denial in violation analyzer and view its comprehensive evaluation report.
- Diagnose an access denial and view the classic report
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.