IAM answers "is this identity allowed to call this API?". It does not answer "should this call be allowed from here, to there?". When an attacker steals a valid service account key or an access token from a CI runner, IAM lets them read the production bucket from their own laptop and copy it into their own project, because the credential is legitimate. VPC Service Controls close that gap: a service perimeter draws a boundary around projects and Google APIs and blocks API calls that cross it, regardless of IAM, unless a rule explicitly allows them. It is the main defense against the pattern MITRE ATT&CK calls transfer data to cloud account, and also the control that most often breaks pipelines when rolled out without a dry run. Left at defaults, there is no perimeter at all.
Baseline controls
Start with these controls on the projects that hold production data, then widen the perimeter. CIS IDs refer to the CIS GCP Foundations Benchmark v5.0.1.
| Control | Why | How to check | CIS / SCC |
|---|---|---|---|
| Put production data projects in a perimeter | Blocks exfiltration with stolen credentials | gcloud access-context-manager perimeters list | CIS 3.8 |
| Restrict every supported service you use | Unrestricted services are side doors | Perimeter restrictedServices | CIS 3.8 |
| Change perimeters through dry run first | Avoid outages from unseen traffic | gcloud access-context-manager perimeters dry-run describe | n/a |
| Limit VPC accessible services | VMs cannot call unrestricted APIs | vpcAccessibleServices in perimeter | n/a |
| Route Google APIs to the restricted VIP or PSC | Network path honors the perimeter | Private DNS zone for googleapis.com | CIS 3.9 |
| Use narrow ingress and egress rules | Exceptions scoped to identity and method | Perimeter ingressPolicies, egressPolicies | n/a |
| Avoid perimeter bridges | Bridges open all services both ways | Perimeters with type PERIMETER_TYPE_BRIDGE | n/a |
| Restrict who can edit access policies | Perimeter edits disable the control | IAM on accesscontextmanager roles | n/a |
| Alert on violations and perimeter changes | Spot probing and tampering | Policy Denied audit logs | n/a |
Security Health Analytics has no finding category for missing perimeters, so CIS 3.8 is checked by inventory, not by SCC.
Concepts and what a perimeter blocks
- Access policy: an organization-level container for perimeters and access levels. One organization-wide policy is typical; scoped policies (bound to a folder or project) let you delegate administration of one perimeter to a team.
- Service perimeter: projects plus a list of restricted services. Calls to restricted services on resources inside are allowed only from inside, or through a matching rule.
- Access levels: conditions in Access Context Manager (IP ranges, device attributes, identities) that let callers from outside reach resources inside.
- Ingress and egress rules: narrow exceptions for specific identities, methods and resources.
- Dry run: a configuration that logs what would be blocked without blocking it.
With storage.googleapis.com restricted on a perimeter containing prj-website-prod:
- A VM inside copying objects to a bucket in a project outside: blocked (egress).
- A user on the internet with valid credentials reading a bucket inside: blocked (ingress), unless an access level or ingress rule allows it.
- A service inside reading a bucket inside: allowed, subject to IAM.
The perimeter does not replace IAM. Both must allow a call.
Plan and create the perimeter
Start with one perimeter around your most sensitive data, not the whole organization. For each candidate list:
- Which projects belong inside (data projects and the workloads that process the data).
- Which services hold or process the data. Restrict all supported services you use where practical: if
bigquery.googleapis.comis restricted butbigquerydatatransfer.googleapis.comis not, there may be a path around the boundary. - Who needs access from outside: CI pipelines, BI tools, administrators, partners.
- Where data legitimately flows: another perimeter, a partner project, a SaaS export.
Access policy
You need roles/accesscontextmanager.policyAdmin at the organization.
gcloud access-context-manager policies create \
--organization=ORG_ID --title="org-policy"
gcloud access-context-manager policies list --organization=ORG_ID
gcloud config set access_context_manager/policy POLICY_ID
To delegate one perimeter to a platform team, create a scoped policy instead (--scopes=folders/FOLDER_ID) and grant the team roles/accesscontextmanager.policyEditor on that policy only.
Perimeter in dry run
Create the perimeter with only a dry run configuration. Nothing is enforced yet:
gcloud access-context-manager perimeters dry-run create sp_data_prod \
--perimeter-title="Production data" \
--perimeter-type=regular \
--perimeter-resources=projects/111111111111,projects/222222222222 \
--perimeter-restricted-services=storage.googleapis.com,bigquery.googleapis.com,sqladmin.googleapis.com,cloudkms.googleapis.com \
--perimeter-enable-vpc-accessible-services \
--perimeter-vpc-allowed-services=RESTRICTED-SERVICES
Projects are referenced by number, not ID. The VPC accessible services setting limits which APIs VMs inside the perimeter can call over the network, so they cannot use an unrestricted service as a side channel.
Console: Security > VPC Service Controls.
Dry run and violation analysis
Calls that would have been blocked are logged in the audit logs of the projects inside the perimeter with a dryRun flag:
protoPayload.metadata.@type="type.googleapis.com/google.cloud.audit.VpcServiceControlAuditMetadata"
protoPayload.metadata.dryRun=true
Each entry carries the caller identity, source IP, method, a violationReason such as RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER, NETWORK_NOT_IN_SAME_SERVICE_PERIMETER or NO_MATCHING_ACCESS_LEVEL, and a vpcServiceControlsUniqueIdentifier. Paste that identifier into the violation analyzer in the console: it explains which perimeter, rule or access level caused the denial and, for supported cases, suggests the rule that would fix it. Grant analysts roles/accesscontextmanager.vpcScTroubleshooterViewer at the organization so they can use it without permission to edit perimeters.
Leave the dry run running for at least two weeks, longer if you have monthly batch jobs. Every legitimate violation needs either a design change (move the project inside) or a narrow rule.
Access levels, ingress and egress rules
Access levels for trusted networks
An access level matching your corporate egress IPs lets administrators reach the console and APIs from the office or VPN:
# corp-network.yaml
- ipSubnetworks:
- 203.0.113.0/24
gcloud access-context-manager levels create corp_network \
--title="Corporate network" \
--basic-level-spec=corp-network.yaml
gcloud access-context-manager perimeters dry-run update sp_data_prod \
--add-access-levels=corp_network
An access level applies to every identity and every restricted service. Prefer ingress rules for anything more specific than "this network".
Ingress rules
An ingress rule lets a named identity from a named source call named methods on resources inside. Example: a CI pipeline outside the perimeter that writes objects to one project:
# ingress.yaml
- ingressFrom:
identities:
- serviceAccount:deployer@prj-ci.iam.gserviceaccount.com
sources:
- accessLevel: accessPolicies/POLICY_ID/accessLevels/corp_network
ingressTo:
operations:
- serviceName: storage.googleapis.com
methodSelectors:
- method: google.storage.objects.create
resources:
- projects/111111111111
Using a real access level as the source ties the exception to the CI runners' network. accessLevel: "*" accepts any source, which is acceptable only when the identity itself is tightly controlled.
Egress rules
An egress rule lets identities inside reach resources outside, for example exports to a partner project:
# egress.yaml
- egressFrom:
identities:
- serviceAccount:exporter@prj-website-prod.iam.gserviceaccount.com
egressTo:
operations:
- serviceName: storage.googleapis.com
methodSelectors:
- method: google.storage.objects.create
resources:
- projects/333333333333
gcloud access-context-manager perimeters dry-run update sp_data_prod \
--set-ingress-policies=ingress.yaml \
--set-egress-policies=egress.yaml
Keep rules narrow: one identity, named methods, named projects. identityType: ANY_IDENTITY turns an ingress rule into an access level in disguise, and method: "*" on an egress rule to an external project is the exfiltration path you built the perimeter to close.
Bridges versus ingress and egress rules
A perimeter bridge (--perimeter-type=bridge) lets projects in two perimeters communicate in both directions for every restricted service. That is far broader than most integrations need. Model cross-perimeter flows as paired egress and ingress rules naming the identities, methods and projects involved, and keep bridges only where an existing design depends on them.
Enforce and maintain
When the dry run log is clean for a full business cycle, promote the dry run configuration:
gcloud access-context-manager perimeters dry-run enforce sp_data_prod
gcloud access-context-manager perimeters describe sp_data_prod \
--format="yaml(status.restrictedServices,status.resources)"
Keep the habit for every later change: update the dry run configuration (perimeters dry-run update), watch the logs, then enforce. perimeters dry-run drop discards a pending change.
Protect the control itself
A perimeter is only as strong as the people who can edit it. Grant roles/accesscontextmanager.policyAdmin to a small security group, manage perimeters through Terraform with code review, and keep project owners out of it: anyone who can remove a project from the perimeter can turn exfiltration back on. New projects created in a protected folder are not added automatically, so include perimeter membership in your project factory.
Network configuration for workloads inside
VMs and GKE nodes inside the perimeter should reach Google APIs through restricted.googleapis.com (199.36.153.4/30) or a Private Service Connect endpoint with the vpc-sc bundle, both of which only serve APIs supported by VPC Service Controls. The DNS zone and PSC commands are on the VPC and firewall rules page. On-premises networks reach the perimeter over Cloud Interconnect or VPN using the same restricted VIP, and an access level for the on-premises ranges, or by adding the VPC network that carries the hybrid traffic to the perimeter.
Logging and detection
Enforced denials are written to the Policy Denied audit logs of the projects inside the perimeter. These logs are always on and cannot be disabled, but make sure no sink exclusion drops them. Alert on enforced violations:
log_id("cloudaudit.googleapis.com/policy")
protoPayload.metadata.@type="type.googleapis.com/google.cloud.audit.VpcServiceControlAuditMetadata"
NOT protoPayload.metadata.dryRun=true
gcloud logging metrics create vpcsc-violations \
--description="Enforced VPC Service Controls denials" \
--log-filter='log_id("cloudaudit.googleapis.com/policy") AND protoPayload.metadata.@type="type.googleapis.com/google.cloud.audit.VpcServiceControlAuditMetadata" AND NOT protoPayload.metadata.dryRun=true'
Alert on changes to perimeters and access levels, recorded as Admin Activity at the organization:
protoPayload.serviceName="accesscontextmanager.googleapis.com"
(protoPayload.methodName:"UpdateServicePerimeter" OR protoPayload.methodName:"DeleteServicePerimeter"
OR protoPayload.methodName:"ReplaceServicePerimeters" OR protoPayload.methodName:"CommitServicePerimeters"
OR protoPayload.methodName:"UpdateAccessLevel" OR protoPayload.methodName:"DeleteAccessLevel"
OR protoPayload.methodName:"ReplaceAccessLevels")
Worth investigating:
- A burst of ingress denials against a production perimeter from an unknown IP or a service account that normally works inside.
- Egress denials naming a destination project you do not own.
- Any perimeter change outside your Terraform pipeline's service account.
Route all of it to the central logging project described on the Cloud Logging page.
Common mistakes
- Enforcing without a dry run. Service agents and scheduled jobs you forgot about stop working, and the perimeter is rolled back in a hurry and never re-enabled.
- Forgetting service-to-service flows. BigQuery reading Cloud Storage, Cloud Build pushing to Artifact Registry and Dataflow staging buckets all cross projects; include those projects or write rules.
- Restricting only Storage and BigQuery. Every supported service you leave unrestricted is a possible path out; review the supported products list.
- Using broad access levels as a shortcut. An access level for "the VPN" lets every identity on that network call every restricted service from outside.
- Bridging perimeters. Bridges are two-way and cover all services; paired ingress and egress rules are almost always enough.
- Letting project owners edit perimeters. Perimeter administration belongs to a small security group with changes in code review.
- Treating console errors from home as a bug. Administrators outside the corporate network see access errors for restricted services; that is the perimeter working, and the fix is a scoped access level or managed device policy, not removing the service.
References
- VPC Service Controls overview, Google Cloud documentation
- Dry run mode for service perimeters, Google Cloud documentation
- Ingress and egress rules, Google Cloud documentation
- Supported products and limitations, Google Cloud documentation
- Violation analyzer, Google Cloud documentation
- CIS Google Cloud Platform Foundation Benchmark, Center for Internet Security
- T1537 Transfer Data to Cloud Account, MITRE ATT&CK
- NIST SP 800-207 Zero Trust Architecture, NIST
About the author
Florian AmetteSecurity engineer writing practical, benchmark-aligned guides to hardening Google Cloud organizations, projects and workloads.