> ## Documentation Index
> Fetch the complete documentation index at: https://docs-xcor.paloaltonetworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Route logs from Google Cloud Platform

> Learn how to route logs from Google Cloud Platform into Palo Alto Networks Cortex XCOR.

> [!NOTE]
>
> To set up new log collection from Google Cloud, use the Dataflow job in
> [Ingest Google Cloud logs](https://docs-xcor.paloaltonetworks.com/ingest/xcor/integrations/server/gcp/logs.md). The setup on
> this page, where Palo Alto Networks Cortex XCOR Support pulls logs from a subscription
> you create, is supported only for tenants already running it.

Google Cloud Platform provides
[sinks](https://cloud.google.com/logging/docs/routing/overview#sinks), which control
how you can route log data to supported destinations. Use the
[Google Cloud Pub/Sub](https://cloud.google.com/pubsub/docs) destination to route log
data from Google Cloud Platform to Cortex XCOR.

Complete the following steps to route logs from Google Cloud Platform:

1. [Create a sink for logs](#create-a-sink-for-logs).
2. [Create a service account](#create-a-service-account).
3. [Create a pull subscription](#create-a-pull-subscription).
4. [Contact Cortex XCOR Support](#contact-cortex-xcor-support).

If you want to use Terraform to manage routing Google logs to Cortex XCOR,
refer to the [Terraform example](#terraform-example). After applying this
configuration, Terraform generates the information that you supply to
[Cortex XCOR Support](#contact-cortex-xcor-support).

> [!NOTE]
>
> This integration is only intended to handle throughput with low volume. To determine
> whether this integration is suited to your use case, contact
> [Cortex XCOR Support](https://docs-xcor.paloaltonetworks.com/support.md).

If you want to route metrics data from Google Cloud Platform, see
[Ingest Google Cloud metrics](https://docs-xcor.paloaltonetworks.com/ingest/xcor/integrations/server/gcp).

## Create a sink for logs

First, you need to create a sink that defines the service type and destination to
route your logs.

1. In the Google Cloud Logs Console, in the left navigation, click **Log Router**
   to open the [Log router](https://console.cloud.google.com/logs/router) page.
2. Follow the steps in the Google Cloud documentation to
   [create a sink](https://cloud.google.com/logging/docs/export/configure_export_v2#creating_sink).
3. Select **Cloud Pub/Sub topic** as the sink service.
4. Optional: Enter a filter expression that matches the log entries you want to
   include.

   See the
   [Logging query language](https://cloud.google.com/logging/docs/view/logging-query-language)
   in the Google Cloud documentation for information about how to construct queries.
5. Complete the remaining steps to create the sink.

Next, [create a service account](#create-a-service-account).

## Create a service account

After creating a sink, you create a service account in Google Cloud that
Cortex XCOR impersonates.

Before starting this process, obtain the Cortex XCOR principal for Google
Cloud. Click your [profile icon](https://docs-xcor.paloaltonetworks.com/navigate#your-account) from the menu bar and select
**My Account**. Copy the value next to **Google Cloud Logs IAM Principal**. Each
Google Cloud service account must grant access to the Cortex XCOR
principal to impersonate them.

1. In the Google Cloud console,
   [create a service account](https://cloud.google.com/iam/docs/service-accounts-create#creating).

   > [!NOTE]
   >
   > The service account must have read access to route log data to Cortex XCOR.

2. Add the Cortex XCOR principal you obtained previously to the Google
   Cloud service account.

3. Grant the principal the `iam.serviceAccountTokenCreator` role.

4. Enter information for the remaining fields to finish creating the service account.

Next, [create a pull subscription](#create-a-pull-subscription).

## Create a pull subscription

Add a [pull subscription](https://cloud.google.com/pubsub/docs/subscription-overview)
to the Pub/Sub destination you previously created. Cortex XCOR initiates
requests to the Pub/Sub server to retrieve messages.

1. In the Google Cloud console,
   [Create a pull subscription](https://cloud.google.com/pubsub/docs/create-subscription#create_a_pull_subscription).
2. In the **Delivery type** menu, select **Pull**.
3. Configure the following recommended settings:

| Setting | Value |
| - | - |
| Message retention duration | 23 hours<sup>\*</sup> |
| Expiration period | Never expire |
| Acknowledgement deadline | 60 seconds |
| Exactly once delivery | No |
| Message ordering | No |
| Dead lettering | No |
| Retry policy | Retry after exponential backoff delay |

<sup>\*</sup>Set **Message retention duration** to less than 24 hours to avoid
storage costs.

1. Grant access to the Pub/Sub you created by assigning the following roles to your
   new internal service account:
   * `roles/pubsub.subscriber`
   * `roles/pubsub.viewer`

Lastly, [contact Cortex XCOR Support](#contact-cortex-xcor-support) and provide the details
about your pull subscription.

## Contact Cortex XCOR Support

After completing the previous steps, [contact Cortex XCOR Support](https://docs-xcor.paloaltonetworks.com/support.md) and
provide the following information:

* The name of your new Google Cloud service account email, such as:

  ```text theme={null}
  SERVICE-ACCOUNT@PROJECT-ID.iam.gserviceaccount.com
  ```

  * *`SERVICE-ACCOUNT`* is the name of the Google Cloud service account you created
    in [create a service account](#create-a-service-account).
  * *`PROJECT-ID`* is the ID of your Google Cloud project.
* The name of the logging sink subscription you created, such as

  ```text theme={null}
  projects/PROJECT-ID/subscriptions/SUBSCRIPTION
  ```

  * *`SUBSCRIPTION`* is the name of the pull subscription you created in
    [create a pull subscription](#create-a-pull-subscription).

Cortex XCOR can then enable the logging integration to start routing your Google
Cloud logs to Cortex XCOR.

## Terraform example

The following code provides an example for creating a single Google Cloud service
account in the a Google Cloud project, and enables Cortex XCOR to
impersonate and gain access.

```terraform expandable Terraform example icon="square-terminal" theme={null}
locals {
  // Email address of your Cortex XCOR Logs tenant-specific principal.
  chronosphere_sa_email = "gcp-logs-TENANT@chronosphere-production-b.iam.gserviceaccount.com"

  // Google Cloud project containing logging data to be ingested into
  // Cortex XCOR.
  logging_project_id = "PROJECT_ID"

  // Organization ID of the Google Cloud organization containing the project.
  org_id = "ORGANIZATION_ID"
}

// Creates Pub/Sub topic for logging sink.
resource "google_pubsub_topic" "main" {
  name    = "logging_sink"
  project = local.project_id
}

// Creates a new logging sink.
resource "google_logging_organization_sink" "main" {
  org_id           = local.org_id
  name             = "all_logs_sink"
  destination      = "pubsub.googleapis.com/${google_pubsub_topic.main.id}"
  include_children = true
}

// Grants sink permission to roles so they can write to the Pub/Sub topic.
data "google_iam_policy" "topic" {
  binding {
    role = "roles/pubsub.publisher"
    members = [
      google_logging_organization_sink.main.writer_identity,
    ]
  }
}

// Binds the role to a new topic.
resource "google_pubsub_topic_iam_policy" "main" {
  project     = local.project_id
  topic       = google_pubsub_topic.main.name
  policy_data = data.google_iam_policy.topic.policy_data
}

// Creates a new Pub/Sub subscription.
resource "google_pubsub_subscription" "main" {
  name    = "all_logs_sink"
  project = local.project_id
  topic   = google_pubsub_topic.main.name

  message_retention_duration = "23h"
  ack_deadline_seconds = 60

  retry_policy {
    minimum_backoff = "10s"
  }

  enable_message_ordering    = false
  enable_exactly_once_delivery = false
}

// Creates a policy granting the new Cortex XCOR logs service account access to
// the subscription.
data "google_iam_policy" "subscription" {
  binding {
    role = "roles/pubsub.viewer"
    members = [
      google_service_account.chronosphere_logs.member
    ]
  }

  binding {
    role    = "roles/pubsub.subscriber"
    members = [
      google_service_account.chronosphere_logs.member
    ]
  }
}

// Binds the new policy to the subscription.
resource "google_pubsub_subscription_iam_policy" "main" {
  project      = local.project_id
  subscription = google_pubsub_subscription.main.name
  policy_data  = data.google_iam_policy.subscription.policy_data
}

// Service account that lets a Cortex XCOR tenant-specific principal
// to impersonate it.
resource "google_service_account" "chronosphere_logs" {
  project    = local.project_id
  account_id = "chronosphere-logs"
}

// The service account provides the Cortex XCOR tenant-specific principal with
// roles/iam.serviceAccountTokenCreator access so that it can impersonate it. Only
// the Cortex XCOR tenant-specific principal can perform this
// impersonation.
data "google_iam_policy" "chronosphere_logs" {
  binding {
    role    = "roles/iam.serviceAccountTokenCreator"
    members = ["serviceAccount:${local.chronosphere_sa_email}"]
  }
}

// Assigns the token creator permission to the service account.
resource "google_service_account_iam_policy" "chronosphere_logs" {
  service_account_id = google_service_account.chronosphere_logs.name
  policy_data        = data.google_iam_policy.chronosphere_logs.policy_data
}
```


## Related topics

- [Ingest Google Cloud logs](https://docs-xcor.paloaltonetworks.com/ingest/xcor/integrations/server/gcp/logs.md)
- [Ingest Google Cloud metrics](https://docs-xcor.paloaltonetworks.com/ingest/xcor/integrations/server/gcp/metrics.md)
- [Google Cloud](https://docs-xcor.paloaltonetworks.com/ingest/xcor/integrations/server/gcp.md)
- [Ingest log data](https://docs-xcor.paloaltonetworks.com/ingest/logs.md)
- [Integrate with Cortex XCOR](https://docs-xcor.paloaltonetworks.com/integrate.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.