# Ingest data with the Ingestion API

Supported in:

> [!CAUTION]
> **Caution:** The Ingestion API described in this document is [deprecated](https://docs.cloud.google.com/chronicle/docs/deprecations.md.txt) and will be discontinued on July 20, 2027. To ingest data into Google SecOps, use the [Chronicle API](https://docs.cloud.google.com/chronicle/docs/reference/ingestion-methods.md.txt) instead. For details on how to migrate, see [Migrate from legacy SIEM API to Chronicle API](https://docs.cloud.google.com/chronicle/docs/administration/migrate-from-legacy-api-to-chronicle-api.md.txt).

This document explains how to use Backstory Ingestion to forward logs directly to your Google Security Operations instance, eliminating the need for additional hardware or software (for example, forwarders) in your environment.

> [!NOTE]
> **Note:** The maximum log size is 1 MB. Logs larger than this won't be ingested into Google SecOps.

The Ingestion method is a RESTful API with a JSON payload. Managed Security Service Providers (MSSPs) and [Technology Partners](https://docs.cloud.google.com/chronicle/docs/technology-partner-program.md.txt) can develop systems to call Ingestion directly and forward logs to Google SecOps.

The Ingestion supports:

- UDM events
- Unstructured logs
- Log types retrieval

You can forward your data to Google SecOps using either of the following types of Ingestion endpoints:

- Unified Data Model (UDM) event
- Unstructured log

If you have formatted your log data using Google SecOps UDM, you can forward UDM events to your Google SecOps account using the UDM API endpoint. Since UDM events are standardized, Google SecOps is better able to process and interpret the data, increasing Google SecOps's ability to recognize security compromises and threats within your enterprise. See [Format log data as UDM](https://docs.cloud.google.com/chronicle/docs/unified-data-model/format-events-as-udm) for information about converting raw logs to UDM.

You can also forward your data to Google SecOps as unstructured logs using the unstructured log API endpoints. Your unstructured log data is normalized within the Google SecOps infrastructure and made available to you through the Google SecOps UI. However, some information may be difficult to extract from the unstructured log data and might only be searchable using Raw Log Scan.

Whenever possible, we recommend forwarding your data to Google SecOps as UDM events.

> [!IMPORTANT]
> **Important:** Occasionally, logs sent through the ingestion API or streaming endpoints (Webhook, Pub/Sub, Amazon Data Firehose) don't contain separate log lines. This causes Google SecOps to treat multiple lines as a single entry, leading to parsing errors. To avoid parsing errors, ensure that all log lines start on a new line.

### Batch deduplication

Google SecOps uses a batch-level deduplication mechanism to prevent ingesting duplicate data. This process ensures that Google SecOps avoids processing the exact same set of log data from the same source multiple times, but still allows it to ingest similar data categorized under different log types.

#### How batch deduplication works

When you send a batch of logs, Google SecOps generates a unique batch ID by hashing the customer ID and the *content of the log entries* within the batch, including raw log data and any Unified Data Model (UDM) fields. The batch ID hash *does not* include the log type or other metadata fields like namespaces, labels, or the feed ID.

Google SecOps performs deduplication *only within the context of a single log type* for a specific customer. Google SecOps does not consider batches with identical content but different log types as duplicates and ingests them.

If a newly generated batch ID matches an existing batch ID for the same customer ID and log type, Google SecOps rejects the entire new batch as a duplicate.

## Get API authentication credentials

Your Google Security Operations representative provides you with a [Google Developer
service account](https://developers.google.com/identity/protocols/OAuth2#serviceaccount) credential to enable the API client to communicate with the API, and share its credentials (JSON key) so your API client can authenticate to the API.

You also must provide the Auth Scope when initializing your API client. OAuth 2.0 uses
a scope to limit an application's access to an account. When an application requests a scope,
the access token issued to the application is limited to the scope granted.

Use the following scope to initialize your Google API client:

`https://www.googleapis.com/auth/malachite-ingestion`

### Python example

The following Python example demonstrates how to use OAuth 2.0 credentials and the
HTTP client, with `google.oauth2` and `googleapiclient`. Note, you may need
to use the OAuth 2.0 credentials contained in the `apikeys-demo.json`
file.

    # Imports required for the sample - Google Auth and API Client Library.
    # Install these packages from https://pypi.org/project/google-api-python-client/
    # or run from your terminal: pip install google-api-python-client
    import json

    from google.auth.transport import requests
    from google.oauth2 import service_account

    SCOPES = ['https://www.googleapis.com/auth/malachite-ingestion']

    # The apikeys-demo.json file contains the OAuth 2 credentials.
    # ING_SERVICE_ACCOUNT_FILE is the full path to the ingestion apikeys.json file.
    # ToDo: Replace with the full path to the OAuth 2.0 credentials file.
    ING_SERVICE_ACCOUNT_FILE = '/customer-keys/apikeys.json'

    # Customer ID is available at /settings/profile on your Google Security Operations.
    CUSTOMER_ID=CUSTOMER_ID

    # Create a credential using an Ingestion Service Account Credential file
    # and the Chronicle API Scope.
    credentials = service_account.Credentials.from_service_account_file(ING_SERVICE_ACCOUNT_FILE, scopes=SCOPES)

    # Build a requests Session Object to make authorized OAuth requests.
    http_session = requests.AuthorizedSession(credentials)

    # UDM Event example (example: US region)
    url = 'https://malachiteingestion-pa.googleapis.com/v2/udmevents:batchCreate'

    # For other regions, you may need to use another regional endpoint for your API call; see
    # https://docs.cloud.google.com/chronicle/docs/reference/ingestion-api#regional_endpoints

    # json_events are a collection of UDM events in (serialized) JSON format.

    body = {
        "customerId": CUSTOMER_ID,
        "events": json.loads(json_events),
    }
    response = http_session.request("POST", url, json=body)

    # For more complete examples, see:
    # https://github.com/chronicle/api-samples-python/blob/master/ingestion/create_entities.py
    # https://github.com/chronicle/api-samples-python/blob/master/ingestion/create_udm_events.py
    # https://github.com/chronicle/api-samples-python/blob/master/ingestion/create_unstructured_log_entries.py

The Service Account Credential provided to you corresponds to one Google SecOps instance. The requests that are issued to the Ingestion API include a field, `customer_id`, which is a unique identifier for a Google SecOps instance. This is provided by your Google SecOps representative. The credential used when issuing requests and the unique identifier must correspond.

## Set up domain allowlisting

The Google SecOps push Ingestion API mechanism requires *domain allowlisting* to support your egress proxy settings.

Allowlist the following domains for egress traffic:

- **OAuth / authorization** :
  - `oauth2.googleapis.com`
  - `www.googleapis.com` (specifically for legacy or fallback token requests)
- **Google SecOps ingestion API**:

  - `<region>-chronicle.googleapis.com` (the modern Chronicle Ingestion API)---for regional ingestion endpoints, for example, `europe-chronicle.googleapis.com` or `asia-northeast1-chronicle.googleapis.com`.  
    For the complete list, see [Regional service endpoints](https://docs.cloud.google.com/chronicle/docs/reference/rest.md.txt#service-chronicle.googleapis.com).

  > [!NOTE]
  > **Note:** The legacy Backstory Ingestion API uses `malachiteingestion-pa.googleapis.com`. For the regional endpoints, see [Regional endpoints](https://docs.cloud.google.com/chronicle/docs/reference/ingestion-api.md.txt#regional-endpoints).

#### Automate the handling of IP-range updates

Because Google's public IP address ranges *are updated dynamically* , Google recommends that you configure your firewall to periodically fetch and parse the JSON file with the [Google Services IP ranges](https://www.gstatic.com/ipranges/goog.json).

You can use the following Python script to create a list of IP address ranges that include those used by the default domains for Google APIs and services. For information about running this script, see [How to run](https://github.com/GoogleCloudPlatform/networking-tools-python/tree/main/tools/cidr#how-to-run).

```python
from __future__ import print_function

import json

try:
    from urllib import urlopen
except ImportError:
    from urllib.request import urlopen
    from urllib.error import HTTPError

import netaddr

IPRANGE_URLS = {
    "goog": "https://www.gstatic.com/ipranges/goog.json",
    "cloud": "https://www.gstatic.com/ipranges/cloud.json",
}

def read_url(url):
    try:
        return json.loads(urlopen(url).read())
    except (IOError, HTTPError):
        print("ERROR: Invalid HTTP response from %s" % url)
    except json.decoder.JSONDecodeError:
        print("ERROR: Could not parse HTTP response from %s" % url)

def get_data(link):
    data = read_url(link)
    if data:
        print("{} published: {}".format(link, data.get("creationTime")))
        cidrs = netaddr.IPSet()
        for e in data["prefixes"]:
            if "ipv4Prefix" in e:
                cidrs.add(e.get("ipv4Prefix"))
            if "ipv6Prefix" in e:
                cidrs.add(e.get("ipv6Prefix"))
        return cidrs

def main():
    cidrs = {group: get_data(link) for group, link in IPRANGE_URLS.items()}
    if len(cidrs) != 2:
        raise ValueError("ERROR: Could not process data from Google")
    print("IP ranges for Google APIs and services default domains:")
    for ip in (cidrs["goog"] - cidrs["cloud"]).iter_cidrs():
        print(ip)

if __name__ == "__main__":
    main()
```

> [!NOTE]
> **Note:** The preceding subtraction script (`goog.json - cloud.json`) is intended only for egress proxy rules with push ingestion API methods. Don't use this script for pull feeds, as pull feeds require both `goog.json` and `cloud.json` IP ranges.

## Regional endpoints

Google SecOps provides the following regional endpoints for each API:

- [São Paulo](https://cloud.google.com/about/locations#americas)---`https://southamerica-east1-malachiteingestion-pa.googleapis.com`
- [Canada](https://cloud.google.com/about/locations#americas)---`https://northamerica-northeast2-malachiteingestion-pa.googleapis.com`
- [Dammam](https://cloud.google.com/about/locations#middle-east)---`https://me-central2-malachiteingestion-pa.googleapis.com`
- [Doha](https://cloud.google.com/about/locations#middle-east)---`https://me-central1-malachiteingestion-pa.googleapis.com`
- [Europe Multi-Region](https://cloud.google.com/about/locations#multi-region)---`https://europe-malachiteingestion-pa.googleapis.com`
- [Frankfurt](https://cloud.google.com/about/locations#europe)---`https://europe-west3-malachiteingestion-pa.googleapis.com`
- [Jakarta](https://cloud.google.com/about/locations#asia-pacific)---`https://asia-southeast2-malachiteingestion-pa.googleapis.com`
- [Johannesburg](https://cloud.google.com/about/locations#africa-south1)---`https://africa-south1-malachiteingestion-pa.googleapis.com`
- [London](https://cloud.google.com/about/locations#europe)---`https://europe-west2-malachiteingestion-pa.googleapis.com`
- [Mumbai](https://cloud.google.com/about/locations#asia-pacific)---`https://asia-south1-malachiteingestion-pa.googleapis.com`
- [Paris](https://cloud.google.com/about/locations#europe)---`https://europe-west9-malachiteingestion-pa.googleapis.com`
- [Warsaw](https://cloud.google.com/about/locations#europe)---`https://europe-central2-malachiteingestion-pa.googleapis.com`
- [Singapore](https://cloud.google.com/about/locations#asia-pacific)---`https://asia-southeast1-malachiteingestion-pa.googleapis.com`
- [Sydney](https://cloud.google.com/about/locations#asia-pacific)---`https://australia-southeast1-malachiteingestion-pa.googleapis.com`
- [Tel Aviv](https://cloud.google.com/about/locations#middle-east)---`https://me-west1-malachiteingestion-pa.googleapis.com`
- [Tokyo](https://cloud.google.com/about/locations#asia-pacific)---`https://asia-northeast1-malachiteingestion-pa.googleapis.com`
- [Turin](https://cloud.google.com/about/locations#europe)---`https://europe-west12-malachiteingestion-pa.googleapis.com`
- [United States Multi-Region](https://cloud.google.com/about/locations#multi-region)---`https://malachiteingestion-pa.googleapis.com`
- [Zurich](https://cloud.google.com/about/locations#europe)---`https://europe-west6-malachiteingestion-pa.googleapis.com`

## Ingestion API reference

This sections describes how to use the Ingestion API methods.

### udmevents

Use this method to forward UDM events to Google SecOps in batches.

The `udmevents` endpoint ingests pre-parsed telemetry that has been structured into UDM events. Because these events are already normalized, they bypass the internal Configuration-Based Normalizer (CBN) parsing layer and move directly to the indexing and rules engine. Use this ingestion path if you manage your own data transformation before transmission. This approach reduces end-to-end latency by eliminating your need for server-side parsing.

> [!NOTE]
> **Note:** Events ingested with `udmevents` won't have any raw logs associated with them since this endpoint only ingests UDM events. Ingested data has the log_type = "UDM" and you can find this data by using a search string, such as `metadata.log_type = "UDM"`.

#### Request

`POST https://malachiteingestion-pa.googleapis.com/v2/udmevents:batchCreate`

#### Request body

The following example illustrates how you could format your log data using the `udmevents` API endpoint. It shows how to format your enterprise log data using UDM.

> [!NOTE]
> **Note:** The `<Noun>.mac` field accepts both uppercase and lowercase characters. `Noun` is `principal`, `src`, `target`, `observer`, `intermediary`, or `about`. Character values will be converted and stored as lowercase.

    {
      "customer_id": "c8c65bfa-5f2c-42d4-9189-64bb7b939f2c",
      "events": [
        {
          "metadata": {
            "event_timestamp": "2019-10-22T12:00:00.000Z",
            "event_type": "USER_LOGIN",
            "product_name": "Acme SSO",
            "vendor_name": "Acme"
          },
          "principal": {
            "ip": [
              "10.1.2.3"
            ]
          },
          "target": {
            "application": "Acme Connect",
            "user": {
              "user_display_name": "Mary Jane",
              "userid": "mary@altostrat.com"
            }
          },
          "extensions": {
            "auth": {
              "type": "MACHINE",
              "mechanism": [
                "NETWORK"
              ]
            }
          }
        },
        {
          "metadata": {
            "event_timestamp": "2019-10-23T04:00:00.000Z",
            "event_type": "NETWORK_HTTP",
            "product_name": "Acme Proxy",
            "vendor_name": "Acme"
          },
          "network": {
            "http": {
              "method": "GET",
              "response_code": 200
            }
          },
          "principal": {
            "hostname": "host0",
            "ip": [
              "10.1.2.3"
            ],
            "port": 60000
          },
          "target": {
            "hostname": "www.altostrat.com",
            "ip": [
              "198.51.100.68"
            ],
            "port": 443,
            "url": "www.altostrat.com/images/logo.png"
          }
        }
      ]
    }

#### Body parameters

|---|---|---|---|
| Field | Value | Required | Description |
| customer_id | string | Yes | Unique identifier (UUID) corresponding to a particular Google SecOps instance. Provided by your Google SecOps representative. |
| events\[\] | array | Yes | Array of UDM events. |

#### Response

You shouldn't receive a response unless there's an error in the method syntax.

### unstructuredlogentries

Use this method to forward unstructured log entries to Google SecOps one batch at a time.

Each batch of log data has a maximum size limit of 1 MB (uncompressed). Use only one timestamp format per batch---either `ts_epoch_microseconds` or `ts_rfc3339`, but not both.
If no separate timestamp is provided, ensure that a timestamp is included within the `log_text` field.

> [!NOTE]
> **Note:** The 1 MB maximum size limit applies to uncompressed payload data. If you send compressed payload data, ensure that the batch size is limited to 1 MB after decompression.

#### Request

`POST https://malachiteingestion-pa.googleapis.com/v2/unstructuredlogentries:batchCreate`

#### Request body

The following example illustrates how you could format your log data using the unstructuredlogentries API endpoint. It shows how to format three BIND DNS logs.

When sending the timestamp as a separate name-value pair, use the same key for all entries in the batch. For example, in a single batch, don't use `ts_epoch_microseconds` for one entry and `ts_rfc3339` for another entry.

For example, this payload will return an error because it includes both `ts_epoch_microseconds` and `ts_rfc3339`.

    {
      "customer_id": "c8c65bfa-5f2c-42d4-9189-64bb7b939f2c",
      "log_type": "BIND_DNS",
      "labels" : [
        {
          "key" : "key_name_one",
          "rbac_enabled" : "true",
          "value" : "value_one"
        },
        {
          "key" : "key_name_two",
          "rbac_enabled" : "true",
          "value" : "value_two"
        }
      ]
      "entries": [
        {
          "log_text": "26-Feb-2019 13:35:02.187 client 10.120.20.32#4238: query: altostrat.com IN A + (203.0.113.102)",
          "ts_epoch_microseconds": 1551188102187000
        },
        {
          "log_text": "26-Feb-2019 13:37:04.523 client 10.50.100.33#1116: query: examplepetstore.com IN A + (203.0.113.102)",
          "ts_rfc3339": "2019-26-02T13:37:04.523-08:00"
        },
        {
          "log_text": "26-Feb-2019 13:39:01.115 client 10.1.2.3#3333: query: www.example.com IN A + (203.0.113.102)"
        }
      ];
    }

#### Body parameters

|---|---|---|---|
| Field | Value | Required | Description |
| customer_id | string | Yes | Unique identifier (UUID) corresponding to a particular Google SecOps instance. Provided by your Google SecOps representative. |
| log_type | string | Yes | Identifies the log entries in the batch (for example, WINDOWS_DNS). |
| namespace | string | Yes | User-configured environment namespace to identify the data domain the logs originated from. Use namespace as a tag to identify the appropriate data domain for indexing and enrichment functionality. |
| entries\[\] | array | Yes | Array of objects containing the fields for the raw log and its timestamp. |
| entries\[\].log_text | string | Yes | Text of the raw log entry. This shouldn't contain any binary data and should only use UTF-8 strings. |
| entries\[\].ts_epoch_microseconds | uint64 | Optional | UNIX timestamp in microseconds associated with the log entry. |
| entries\[\].ts_rfc3339 | string | Optional | Timestamp associated with the log entry in RFC 3339 format. |
| labels\[\] | array | Optional | Array of objects containing the key-value pairs for labels to be applied to the logs. |
| labels\[\].key | string | Optional | Name of a key for applying a label. |
| labels\[\].value | string | Optional | Value for applying a label. |

#### Response

You shouldn't receive a response unless there's an error in the method syntax.

### createentities

Creates entities. You are limited to 4 MB of data per request.

#### Request

`POST https://malachiteingestion-pa.googleapis.com/v2/entities:batchCreate`

#### Request body

    {
      "customer_id": "<customer UUID>",
      "log_type": "<log type goes here>",
      "entities": [<array of Entities>],
    }

#### Body parameters

|---|---|---|---|
| Field | Value | Required | Description |
| customer_id | string | Yes | Unique identifier (UUID) corresponding to a particular Google SecOps instance. Provided by your Google SecOps representative. |
| log_type | string | Yes | Any log_type value returned by the logtypes endpoint. |
| entities\[\] | array | Yes | Array of Entities. |

#### Sample request body

> [!NOTE]
> **Note:** The entity.asset.mac field accepts both uppercase and lowercase characters. Character values will be converted and stored as lowercase.

    {
     "log_type": "AZURE_AD_CONTEXT",
     "entities": [{
       "metadata": {
          "collected_timestamp":"2021-11-14T15:30:18.142265Z",
          "entity_type": "USER",
          "vendor_name": "vendor",
          "product_name": "product"
       },
       "entity": {
          "user": {
            "userid": "johndoe",
            "product_object_id": "doejohn"
          }
       }
      },
      {
       "metadata": {
          "collected_timestamp":"2021-11-14T16:30:18.142265Z",
          "entity_type": "USER",
          "vendor_name": "vendor",
          "product_name": "product"
       },
       "entity": {
          "user": {
            "userid": "janedoe",
            "product_object_id": "doejane"
          }
       }
      }]
    }

#### Response

Returns an empty JSON with 200 OK, indicating the operation has completed successfully.

### logtypes

Use this method to retrieve a list of supported log types. The log types are formatted using the following fields:

#### Request

`GET https://malachiteingestion-pa.googleapis.com/v2/logtypes`

#### Response

The following example illustrates the format of the information returned when calling the logtypes API endpoint.

    {
      "logtypes": [
        {
         "log_type": "BIND_DNS",
         "description": "BIND DNS Server"
        },
        {
          "log_type": "WINDOWS_DNS",
          "description": "Windows DNS"
        },
        {
          "log_type": "WINDOWS_DHCP",
          "description": "Windows DHCP"
        },
        {
          "log_type": "WINEVTLOG",
          "description": "Windows Event Log"
        }
      ]
    }

#### Response fields

|---|---|---|
| Field | Value | Description |
| logtypes\[\] | array | Returns an array of the supported log types. |
| logtypes\[\].log_type | string | Log type. Appears in the response only. |
| logtypes\[\].description | string | Human readable description of the log type. Appears in the response only. |
| logtypes\[\].index | uint64 | Index of the log type. Appears in the response only. |

## Frequently asked questions

**What is the maximum batch size (per HTTP request)?**

4 MB when uncompressed (in case the incoming batch is compressed).

**Can a customer create an allowlist to include certain public IP addresses that are allowed to connect to the collector API endpoint? Or do you support other forms of client authorization?**

For push ingestion using the Ingestion API, Google SecOps doesn't support ingress IP allowlisting. Any client with a valid API key can connect to the collector API endpoint. For pull-based data feeds, see [Set up IP allowlisting](https://docs.cloud.google.com/chronicle/docs/reference/feed-management-api.md.txt#ip-allowlist).

**Does the API endpoint vary depending on the region?**

Yes. Your API endpoint will vary depending on where your customer account is provisioned. See [Regional Endpoints](https://docs.cloud.google.com/chronicle/docs/reference/ingestion-api.md.txt#regional-endpoints).

**What should the request timeout be?**

Clients should use a request timeout of 90 seconds.

**What should we do if an HTTP request fails? What are the error codes?**

See [AIP-193 Errors](https://cloud.google.com/apis/design/errors#handling_errors), specifically the following:

Clients should retry on 5XX errors with exponential backoff. The minimum delay should be 1s unless it is documented otherwise. For 429 errors, the client may retry with minimum 30s delay. For all other errors, retry may not be applicable.

**Do you support standard HTTP GZIP compression (for example, Accept-Encoding: gzip header)?**

Yes, Google SecOps supports standard HTTP GZIP compression.

**What time format should my raw logs follow?**

Most of the prebuilt parsers expect one of the following time formats: `RFC3339`, `UNIX` and `ISO8601`.

**Is there a default timezone if it's missing in the raw log timestamp?**

Most of the prebuilt parsers can extract timezone information correctly if it's included in raw logs. In raw logs where the timezone information is missing, the parser applies the `UTC` timezone to the timestamp in the raw log. This may cause the raw logs to appear as delayed or early during a UDM search. For this reason, it's recommended to include proper timezone information from the source while configuring the syslogs. This is especially important for logs ingested using the Ingestion API, Forwarder and Bindplane agents.