VPC Service Controls (VPC SC) helps you secure data exchanges between Google Cloud and SAP Business Data Cloud (BDC). Depending on your integration direction, you can configure egress rules to query SAP tables from Google Cloud or ingress rules to publish data to SAP BDC.

<br />

## Egress rules for querying SAP

You might see this error when querying SAP tables:

`VPC Service Controls: Request is prohibited by organization's policy. File: gs://example-bucket/path/to/file`

This occurs because BigQuery must read Cloud Storage external
buckets that host the table data. If your perimeter restricts
`storage.googleapis.com`, you might receive a
`RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER` error because the external bucket is
outside your perimeter. To resolve this, configure an egress rule.
For more information, see [Resources not in the same
perimeter](https://docs.cloud.google.com/vpc-service-controls/docs/troubleshooting#resources-not-in-same-perimeter).

### Configure egress rules

This configuration applies if your SAP landscape is deployed on
Google Cloud.

If your project uses VPC Service Controls and the perimeter restricts
`storage.googleapis.com`, you must configure an egress rule to allow
BigQuery to read SAP Cloud Storage buckets for table queries.

1. Check the current perimeter.

   ```bash
   PERIMETER_NAME=accessPolicies/ACCESS_POLICY/servicePerimeters/PERIMETER
   gcloud access-context-manager perimeters describe ${PERIMETER_NAME}
   ```

   Replace the following:
   - `ACCESS_POLICY`: your access policy.
   - `PERIMETER`: your service perimeter.

   Your perimeter restricts Cloud Storage bucket reads if the response
   includes:

   ```yaml
   resources:
   - projects/PROJECT_ID
   ...
   restrictedServices:
   - storage.googleapis.com
   ```
2. Export the current egress rules and append a rule to allow Cloud Storage
   bucket reads.

   ```bash
   PERIMETER_NAME=accessPolicies/ACCESS_POLICY/servicePerimeters/PERIMETER
   gcloud access-context-manager perimeters describe ${PERIMETER_NAME} \
       --format="yaml(status.egressPolicies)" | sed '1,2d; s/^  //' > egress-policies.yaml
   ```

   Replace the following:
   - `ACCESS_POLICY`: your access policy.
   - `PERIMETER`: your service perimeter.

   Append this rule to `egress-policies.yaml` to allow you to read
   Cloud Storage buckets outside the perimeter:

   ```yaml
   - egressFrom:
       identityType: ANY_IDENTITY
     egressTo:
       operations:
       - methodSelectors:
         - method: google.storage.buckets.get
         - method: google.storage.objects.get
         - method: google.storage.objects.list
         serviceName: storage.googleapis.com
       resources:
       - '*'
   ```
3. Update the service perimeter:

   ```bash
   gcloud access-context-manager perimeters update ${PERIMETER_NAME} \
       --set-egress-policies=egress-policies.yaml
   ```

   Verify the updated egress policies:

   ```bash
   gcloud access-context-manager perimeters describe ${PERIMETER_NAME}
   ```

## Ingress rules for publishing data to SAP

SAP needs to query the BigLake API to read
Apache Iceberg tables managed by Lakehouse. Your VPC Service Controls rules might
block this if the project's perimeter restricts the `biglake.googleapis.com`
service.

If your project has VPC Service Controls enforced, and the perimeter applied on
the project restricts the `biglake.googleapis.com` service, you must configure
an ingress rule to allow SAP federated principals to access the
BigLake API.

### Configure ingress rules

1. Check the current perimeter.

   ```bash
   PERIMETER_NAME=accessPolicies/ACCESS_POLICY/servicePerimeters/PERIMETER
   gcloud access-context-manager perimeters describe ${PERIMETER_NAME}
   ```

   Replace the following:
   - `ACCESS_POLICY`: your access policy.
   - `PERIMETER`: your service perimeter.

   Your service perimeter can restrict the BigLake API if the response contains:

   ```yaml
   resources:
   - projects/PROJECT_ID
   ...
   restrictedServices:
   - biglake.googleapis.com
   ```
2. Export the current ingress rules and append a rule to allow SAP federated principals to call Lakehouse APIs.

   ```bash
   PERIMETER_NAME=accessPolicies/ACCESS_POLICY/servicePerimeters/PERIMETER
   gcloud access-context-manager perimeters describe ${PERIMETER_NAME} \
       --format="yaml(status.ingressPolicies)" | sed '1,2d; s/^  //' > ingress-policies.yaml
   ```

   Replace the following:
   - `ACCESS_POLICY`: your access policy.
   - `PERIMETER`: your service perimeter.

   > [!NOTE]
   > **Note:** The preceding command might create an empty file if the perimeter doesn't have any existing ingress rules.

   Append a rule for the SAP federated principal:

   ```yaml
   - ingressFrom:
       identities:
       - principal://iam.googleapis.com/projects/PROJECT_ID/locations/global/workloadIdentityPools/POOL_NAME/subject/SUBJECT
       sources:
       - accessLevel: '*'
     ingressTo:
       operations:
       - methodSelectors:
         - method: '*'
         serviceName: biglake.googleapis.com
       resources:
       - '*'
   ```

   Replace the following:
   - `PROJECT_ID`: the project ID containing the workload identity pool.
   - `POOL_NAME`: the name of the workload identity pool.
   - `SUBJECT`: the UUID issued by the SAP-side issuer for the workload.
3. Update the service perimeter:

   ```bash
   gcloud access-context-manager perimeters update ${PERIMETER_NAME} \
       --set-ingress-policies=ingress-policies.yaml
   ```

   Verify the updated policies:

   ```bash
   gcloud access-context-manager perimeters describe ${PERIMETER_NAME}
   ```

## What's next

- [Set up cross-cloud connection for SAP Business Data Cloud](https://docs.cloud.google.com/lakehouse/docs/set-up-cross-cloud-connection-sap-bdc.md.txt).
- [Query SAP data](https://docs.cloud.google.com/lakehouse/docs/query-sap-data.md.txt).