Google Cloud VPC Service Controls lets you set up a
service perimeter to guard against data exfiltration. Configure
Audit Manager with
[VPC Service Controls](https://docs.cloud.google.com/vpc-service-controls/docs/overview.md.txt) so that
Audit Manager can access resources and services outside its
service perimeter.

## Before you begin

1. Make sure that you have the [required roles to configure VPC Service Controls](https://docs.cloud.google.com/vpc-service-controls/docs/access-control.md.txt) at the organization level.
2. Make sure that you have the following information, depending on whether you are enrolling a resource or running an audit in Audit Manager.
   1. **When you enroll a resource for auditing**: the Google Cloud user account that you specified when you set up Audit Manager.
   2. **When you run an audit** : the [Audit Manager service agent](https://docs.cloud.google.com/audit-manager/docs/enroll-resource.md.txt) that was created automatically when you enroll a resource for auditing.

## Limitations

- You can't use a perimeter to protect folder level or organization level Audit Manager resources. To manage Audit Manager permissions at the folder or organization level, we recommend using IAM. For more information, see [Manage access to projects,
  folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).

## Configure the ingress and egress rules

Configure ingress and egress rules based on the service perimeter
configuration. For more information, see [Service
perimeter overview](https://docs.cloud.google.com/vpc-service-controls/docs/service-perimeters).

You may have to [configure the ingress and egress
rules](https://docs.cloud.google.com/vpc-service-controls/docs/configuring-ingress-egress-policies) when you
perform the following actions:

1. Enroll a resource for auditing
2. Run an audit

### Configure ingress and egress rules when you enroll a resource for auditing

You can [enroll an organization, a folder, or a project as a resource for
auditing](https://docs.cloud.google.com/audit-manager/docs/enroll-resource) in Audit Manager.

You must configure ingress or egress rules when any of the following resources
are not within the same service perimeter:

- the Audit Manager service agent
- the Cloud Storage bucket configured as the destination to store the audit data
- the services involved in the audit process

The Cloud Storage methods in the following samples are required.
You can adjust the following sample ingress and egress rules to meet your business requirements.

Complete the following tasks for the Google Cloud user account
that you specified when you set up Audit Manager.

1. Configure the following ingress rule:

   ```yaml
   - ingressFrom:
       identities:
       - user: USER_EMAIL_ADDRESS
       sources:
           - accessLevel: "*"
     ingressTo:
       operations:
         - serviceName: storage.googleapis.com
           methodSelectors:
             - method: google.storage.buckets.getIamPolicy
             - method: google.storage.buckets.testIamPermissions
             - method: google.storage.objects.getIamPolicy
             - method: google.storage.buckets.setIamPolicy
             - method: google.storage.objects.setIamPolicy
             - method: google.storage.objects.create
             - method: google.storage.objects.get
       resources: "*"
   ```

   Replace the following:
   - <var translate="no">USER_EMAIL_ADDRESS</var>: the email address that you specified when you set up Audit Manager
2. Configure the following egress rule:

   ```yaml
   - egressFrom:
      identities:
       - user: USER_EMAIL_ADDRESS
         sources:
           - accessLevel: "*"
     egressTo:
       operations:
         - serviceName: storage.googleapis.com
           methodSelectors:
             - method: google.storage.buckets.getIamPolicy
             - method: google.storage.buckets.testIamPermissions
             - method: google.storage.objects.getIamPolicy
             - method: google.storage.buckets.setIamPolicy
             - method: google.storage.objects.setIamPolicy
             - method: google.storage.objects.create
             - method: google.storage.objects.get
     resources: "*"
   ```

   Replace the following:
   - <var translate="no">USER_EMAIL_ADDRESS</var>: the email address that you specified when you set up Audit Manager

### Configure the ingress and egress rules when you run an audit

You can [run an audit](https://docs.cloud.google.com/audit-manager/docs/run-audit.md.txt) against a framework.

Configure the following ingress or egress rules when the folder or project that
is being audited and the enrolled Cloud Storage bucket are in different
service perimeters.

The Cloud Storage methods in the following samples are required. You can
adjust the following sample ingress and egress rules to meet your business
requirements.

#### Configure the ingress rule when you run an audit for folders

Configure the following ingress rule when you run an audit for a folder and the
enrolled Cloud Storage bucket or one of the projects within the folder is
*inside* the perimeter.

Complete this task for the Audit Manager service account.

```yaml
- ingressFrom:
    identities:
    - serviceAccount: SA_EMAIL_ADDRESS
    - user: USER_EMAIL_ADDRESS
    sources:
        - accessLevel: "*"
  ingressTo:
    operations:
        - serviceName: "*"
    resources: "*"
```

Replace the following:

- <var translate="no">SA_EMAIL_ADDRESS</var>: the email address of the Audit Manager service account
- <var translate="no">USER_EMAIL_ADDRESS</var>: the email address that you specified when you set up Audit Manager

#### Configure the ingress rule when the enrolled Cloud Storage bucket is inside a service perimeter

Configure the following ingress rule if the audit is run for a project and the
enrolled Cloud Storage bucket is *inside* a service perimeter.

Complete this task for the Audit Manager service account.

```yaml
- ingressFrom:
    identities:
    - serviceAccount: SA_EMAIL_ADDRESS
    - user: USER_EMAIL_ADDRESS
    sources:
        - accessLevel: "*"
  ingressTo:
    operations:
        - serviceName: storage.googleapis.com
          methodSelectors:
            - method: google.storage.buckets.getIamPolicy
            - method: google.storage.buckets.testIamPermissions
            - method: google.storage.objects.getIamPolicy
            - method: google.storage.buckets.setIamPolicy
            - method: google.storage.objects.setIamPolicy
            - method: google.storage.objects.create
            - method: google.storage.objects.get
  resources: "*"
```

Replace the following:

- <var translate="no">SA_EMAIL_ADDRESS</var>: the email address of the Audit Manager service account
- <var translate="no">USER_EMAIL_ADDRESS</var>: the email address that you specified when you set up Audit Manager

#### Configure the egress rule when the enrolled Cloud Storage bucket is outside a service perimeter

Configure the following egress rule if the audit is run for a project within a
service perimeter and the enrolled Cloud Storage bucket is *outside* the
perimeter.

Complete this task for the project that contains the
Cloud Storage bucket.

```yaml
- egressFrom:
   identities:
      - serviceAccount: SA_EMAIL_ADDRESS
        - user: USER_EMAIL_ADDRESS
      sources:
        - accessLevel: "*"
  egressTo:
    operations:
        - serviceName: storage.googleapis.com
          methodSelectors:
            - method: google.storage.buckets.getIamPolicy
            - method: google.storage.buckets.testIamPermissions
            - method: google.storage.objects.getIamPolicy
            - method: google.storage.buckets.setIamPolicy
            - method: google.storage.objects.setIamPolicy
            - method: google.storage.objects.create
            - method: google.storage.objects.get
    resources: "*"
```

Replace the following:

- <var translate="no">SA_EMAIL_ADDRESS</var>: the email address of the Audit Manager service account
- <var translate="no">USER_EMAIL_ADDRESS</var>: the email address that you specified when you set up Audit Manager

If you encounter issues with VPC Service Controls, use the
VPC Service Controls violation analyzer to debug and analyse the issue. For more
information, see [Diagnose an access denial using unique ID in violation analyzer](https://docs.cloud.google.com/vpc-service-controls/docs/troubleshooter.md.txt).

## What's next

- Learn more about [VPC Service Controls](https://docs.cloud.google.com/vpc-service-controls/docs/overview.md.txt).
- See the Audit Manager entry in the [VPC Service Controls supported
  products
  table](https://docs.cloud.google.com/vpc-service-controls/docs/supported-products#table_audit_manager).