Google Chronicle (om_chronicle)

Google Chronicle is a cloud service built as a specialized layer on top of the core Google infrastructure. It is designed for enterprises to privately retain, analyze, and search the massive amounts of security and network telemetry they generate. Chronicle normalizes, indexes, correlates, and analyzes the data to provide instant analysis and context on risky activity.

The Chronicle Ingestion API enables you to forward logs directly to Chronicle. This module supports forwarding logs to the udmevents and unstructuredlogentries endpoints. Event data is sent in batches, thus reducing HTTP response latency and improving data throughput.

om_chronicle can send logs to Chronicle Ingestion API v1 and v2. API v1 requires a Chronicle Ingestion API access key. Although this method is deprecated, it still works when writing this documentation. API v2 requires a Google Developer Service Account for OAuth 2.0 authentication.

Unstructured logs output format

om_chronicle forwards structured log records over HTTP(S) as JSON payload in the following format:

{
    "log_type": "<log_type>",
    "customer_id": "<customer_id>",
    "entries": [
        {
            "log_text": "<json_escaped_raw_event>",
            "ts_rfc3339": "<event_time>"
        }
    ]
}

For example:

{
    "log_type": "BIND_DNS",
    "customer_id": "c8c65bfa-5f2c-42d4-9189-64bb7b939f2c",
    "entries": [
        {
            "log_text": "<13>Oct  9 17:33:15 SERVER-1 09-Oct-2023 17:33:15.187 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)",
            "ts_rfc3339": "2023-10-09T17:51:27.122616+02:00"
        }
    ]
}

Required fields:

  • log_type is the value specified by the LogType directive.

  • log_text is the JSON escaped value of the $raw_event field.

Optional fields:

  • customer_id is present if the CustomerId directive is specified.

  • ts_rfc3339 is present if the $EventReceivedTime core field is present. If this field is not required, use the delete() procedure to remove $EventReceivedTime. This can be useful if the log text already contains a received date and time.

Additional metadata, including the NXLog Agent-specific fields $SourceModuleName and $SourceModuleType, will not be included in the output unless these values have been written to the $raw_event field. The processing required to achieve this depends on the format of the input data. For example, if the input data is in JSON format, you need to:

  1. Use parse_json() to parse $raw_event into fields.

  2. Create and populate any additional custom fields.

  3. Use to_json() to convert the fields to JSON format and update the value of $raw_event.

Structured logs output format

om_chronicle forwards structured log records over HTTP(S) as JSON payload in the following format:

{
    "metadata": {
        "event_type": "NETWORK_CONNECTION",
        "event_timestamp": "<event_time>",
        "description": "<json_escaped_raw_event>",
        "ingestion_labels": [
            {
                "key": "source_module_name",
                "value": "<source_module_name>"
            },
            {
                "key": "source_module_type",
                "value": "<source_module_type>"
            }
        ]
    },
    "network": {
        "ip_protocol": "TCP"
    },
    "principal": {
        "ip": "<message_source_address>"
    },
    "target": {
        "application": "nxlog",
        "ip": "127.0.0.1"
    }
}

For example:

{
    "metadata": {
        "description": "16-May-2023 20:11:15.187 client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)",
        "event_timestamp": "2023-05-16T20:11:27.421707+05:45",
        "event_type": "NETWORK_CONNECTION",
        "ingestion_labels": [
            {
                "key": "source_module_name",
                "value": "tcp"
            },
            {
                "key": "source_module_type",
                "value": "im_tcp"
            }
        ]
    },
    "network": {
        "ip_protocol": "TCP"
    },
    "principal": {
        "ip": "127.0.0.1"
    },
    "target": {
        "application": "nxlog",
        "ip": "127.0.0.1"
    }
}

Required fields:

  • description is the JSON escaped value of the $raw_event field.

  • event_timestamp is the value of $EventReceivedTime.

  • ingestion_labels.source_module_name is the value of $SourceModuleName, i.e., the name of the NXLog Agent input module instance.

  • ingestion_labels.source_module_type is the value of $SourceModuleType, i.e., the NXLog Agent input module.

If you remove any of these fields from the log record, for example, with the delete() procedure, the field value will be set to an empty string.

Configuration

The om_chronicle module can work in one of two configured modes: structured and unstructured, which are specified by the ChronicleMode directive.

The om_chronicle module accepts the following directives in addition to the common module directives.

Output format directives

The following directives define how the module formats the log records it sends to Google Chronicle.

LogType

Must correspond to a valid log type. To retrieve the list of possible log types, visit https://malachiteingestion-pa.googleapis.com/v1/logtypes?key=YOUR_API_KEY.

This directive is required when ChronicleMode is set to unstructured.

ChronicleMode

This directive specifies the Google Chronicle API endpoint. The accepted values are:

unstructured

This mode supports forwarding unstructured logs to the unstructuredlogentries endpoint. Log data normalization is then handled by Google Chronicle. You must also set the LogType directive when forwarding unstructured logs. This is the default value.

structured

This mode supports forwarding logs to the udmevents endpoint. Log data must be in the UDM format supported by Google Chronicle.

ChronicleSchema

The output data from each NXLog Agent module is mapped to the Chronicle UDM format using a custom schema mapping. Use this directive to specify the name of a different schema file and override the default mapping.

This directive only applies when ChronicleMode is set to structured.

SchemaDir

Specify the path to the directory containing the custom schema files defined by the ChronicleSchema and SchemaMap directives. The path can be relative to the configuration directory.

This directive only applies when ChronicleMode is set to structured.

SchemaMap

Use this directive to map the data schema dynamically.

<SchemaMap>
    "spawning"    im_file-spawning.json
    "running"     im_file-running.json
    "exited"      im_file-exited.json
</SchemaMap>

<Exec>
    if ($eventMessage =~ /service state: (\w+)/)
        set_schema($1);
    else
        log_warning("Unknown eventMessage: " + $eventMessage);
</Exec>

HTTP(S) directives

The following directives are for configuring HTTP(S) connection settings.

OutputRequestSize

This optional directive specifies the recommended size (in bytes) of each batch of log data. The maximum size for unstructured logs is 1 MB (1,048,576 bytes).

AddHeader

This optional directive can be specified multiple times to add custom headers to each HTTP request.

Compression

This optional directive can be used to enable HTTP compression for outgoing HTTP messages. The possible values are none, gzip, and deflate. By default, compression is disabled. Please note that some HTTP servers may not accept compressed HTTP requests. If a server doesn’t support a specific compression method, it may return 415 Unsupported Media Type errors in response to compressed requests.

HTTPBasicAuthUser

HTTP basic authorization username. You must also set the HTTPBasicAuthPassword directive to use HTTP authorization.

HTTPBasicAuthPassword

HTTP basic authorization password. You must also set the HTTPBasicAuthUser directive to use HTTP authorization.

HTTPSAllowExpired

This boolean directive specifies whether the connection should be allowed with an expired certificate. If set to TRUE, the remote client will be able to connect with an expired certificate. The default is FALSE: the certificate must not be expired. This directive is only valid if HTTPSRequireCert is set to TRUE.

HTTPSAllowUntrusted

This boolean directive specifies that the connection should be allowed without certificate verification. If set to TRUE, the connection will be allowed even if the remote hosts presents an unknown or self-signed certificate. The default value is FALSE: the remote host must present a trusted certificate.

HTTPSCADir

This directive specifies a path to a directory containing certificate authority (CA) certificates. These certificates will be used to verify the certificate presented by the remote host. The certificate files must be named using the OpenSSL hashed format, i.e. the hash of the certificate followed by .0, .1 etc. To find the hash of a certificate using OpenSSL:

$ openssl x509 -hash -noout -in ca.crt

For example, if the certificate hash is e2f14e4a, then the certificate filename should be e2f14e4a.0. If there is another certificate with the same hash then it should be named e2f14e4a.1 and so on.

A remote host’s self-signed certificate (which is not signed by a CA) can also be trusted by including a copy of the certificate in this directory.

The default operating system root certificate store will be used if this directive is not specified. Unix-like operating systems commonly store root certificates in /etc/ssl/certs. Windows operating systems use the Windows Certificate Store, while macOS uses the Keychain Access Application as the default certificate store.

HTTPSCAFile

This specifies the path of the certificate authority (CA) certificate that will be used to verify the certificate presented by the remote host. A remote host’s self-signed certificate (which is not signed by a CA) can be trusted by specifying the remote host certificate itself. In the case of certificates signed by an intermediate CA, the certificate specified must contain the complete certificate chain (certificate bundle).

HTTPSCertFile

This specifies the path of the certificate file that will be presented to the remote host during the HTTPS handshake.

HTTPSCertKeyFile

This specifies the path of the private key file that was used to generate the certificate specified by the HTTPSCertFile directive. This is used for the HTTPS handshake.

Proxy

This optional directive is used to specify the protocol, IP address (or hostname) and port number of the HTTP or SOCKS proxy server to be used. The format is protocol://hostname:port.

Reconnect

This optional directive sets the reconnect interval in seconds. If it is set, the module attempts to reconnect in every defined second. If it is not set, the reconnect interval will start at 1 second and doubles on every attempt. If the duration of the successful connection is greater than the current reconnect interval, then the reconnect interval will be reset to 1 sec.

Optional directives

ChronicleRegion

This directive specifies a regional endpoint. Supported values are: US, Europe, asia-southeast1, etc. See the Locations page.

ChronicleVersion

Specifies the Google Chronicle Ingestion API version. The supported values are v1 and v2 (or 1, 2), The default is v1.

API v1 requires a ChronicleKey.

API v2 requires a CredentialsFile and CustomerId.

ChronicleKey

This directive specifies a Chronicle Ingestion API access key required for API v1. Chronicle responds with HTTP error 403 if this key is not valid.

This directive is only required for API v1. See the ChronicleVersion directive for more information.

CredentialsFile

This directive specifies the path to the private key file of the Google Developer Service Account required for authenticating with Google Chronicle API v2. Chronicle responds with HTTP error 403 if this key is not valid.

See Configuring a Google Cloud service account for more information.

This directive is only required for API v2. See the ChronicleVersion directive for more information.

CustomerId

This directive specifies the unique identifier (UUID) corresponding to your Chronicle instance. The ID is provided by your Chronicle representative. The Ingestion API responds with HTTP error 400 or 403 if the UUID is not valid.

This directive is optional for API v1 and required for API v2. See the ChronicleVersion directive for more information.

URL

Optional directive for specifying the Chronicle Ingestion API endpoint.

Alternatively, use the optional ChronicleRegion, ChronicleVersion, ChronicleMode, and ChronicleKey directives to use the default endpoint: https://{ChronicleRegion}-malachiteingestion-pa.googleapis.com/{ChronicleVersion}/{ChronicleMode}/?key={ChronicleKey}

Depending on the URL provided, the module operates in plain HTTP or HTTPS mode. If you do not specify the port number in the URL, it uses port 80 for HTTP and port 443 for HTTPS.

ChronicleKey is only required for API v1.
This module does not support specifying multiple URL directives as a failover configuration.

Procedures

The following procedures are exported by om_chronicle.

set_schema(string schema_name);

Use a different schema file to override the default mapping. The schema_name specifies the schema name declared in the SchemaMap directive.

Examples

Example 1. Sending unstructured plain text logs

This configuration collects logs from a BIND 9 DNS server and forwards them to Chronicle. Since the BIND_DNS LogType requires the events to be in syslog format, log records are converted to syslog using the to_syslog_bsd() procedure of the xm_syslog module.

nxlog.conf
# Google Chronicle API key, required.
define API_KEY             <YOUR_API_KEY>

<Extension syslog>
    Module                xm_syslog
</Extension>

<Output chronicle>
    Module                om_chronicle
    ChronicleKey          %API_KEY%

    # Unstructured events
    ChronicleMode         unstructured

    # Identifies the type of logs in the batch.
    LogType               BIND_DNS

    <Exec>
        $Message = $raw_event;
        to_syslog_bsd();
    </Exec>
</Output>
Input sample
09-Oct-2023 17:33:15.187 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)
09-Oct-2023 17:34:16.120 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)
09-Oct-2023 17:35:17.165 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)
Output sample

The following is the JSON-formatted log record that will be sent to Google Chronicle. Note that the ts_rfc3339 field is added by the module and specifies the time when the event was received and corresponds to the $EventReceivedTime core field.

{
  "log_type": "BIND_DNS",
  "entries": [
    {
      "log_text": "<13>Oct  9 17:33:15 SERVER-1 09-Oct-2023 17:33:15.187 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)",
      "ts_rfc3339": "2023-10-09T17:51:27.122616+02:00"
    },
    {
      "log_text": "<13>Oct  9 17:34:16 SERVER-1 09-Oct-2023 17:34:16.120 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)",
      "ts_rfc3339": "2023-10-09T17:51:27.126157+02:00"
    },
    {
      "log_text": "<13>Oct  9 17:35:17 SERVER-1 09-Oct-2023 17:35:17.165 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)",
      "ts_rfc3339": "2023-10-09T17:51:27.126176+02:00"
    }
  ]
}
Example 2. Sending structured logs

This configuration collects logs from a BIND 9 DNS server and forwards them to Chronicle in UDM format. It parses log records into structured data with a regular expression and uses a custom ChronicleSchema file in the same folder as the NXLog Agent configuration.

nxlog.conf
# Google Chronicle API key, required.
define API_KEY         <YOUR_API_KEY>

<Input dns>
    Module             im_file
    File               '/var/log/bind.log'
    <Exec>
        if $raw_event =~ /(?x)^(?<EventTime>\S+\s\S+)\s(?<category>.*):\s
                          (?<severity>.*):\s.*\s(?<source>.*)\#
                          (?<port>\d+):\s+(?<message>.+)$/
        {
            $EventTime = parsedate($EventTime);
        }
    </Exec>
</Input>

<Output chronicle_udm>
    Module             om_chronicle
    ChronicleKey       %API_KEY%
    ChronicleMode      structured
    ChronicleSchema    'bind_dns.json'
</Output>
bind_dns.json
{
  "metadata": {
    "event_type": "NETWORK_DNS",
    "event_timestamp": "$EventTime",
    "ingested_timestamp": "$EventReceivedTime",
    "description": "$message",
    "product_name": "BIND 9",
    "vendor_name": "ISC",
    "product_event_type": "$category",
    "severity_details": "$severity",
    "ingestion_labels": [
      {
        "key": "source_module_name",
        "value": "$SourceModuleName"
      },
      {
        "key": "source_module_type",
        "value": "$SourceModuleType"
      }
    ]
  },
  "src": {
    "ip": "$source",
    "port": "$port"
  },
  "principal": {
    "hostname": "$Hostname"
  }
}
Input sample
09-Oct-2023 17:33:15.187 queries: info: client 10.120.20.20#4238:  query: example.com IN A + (100.90.80.102)
Output sample

The following is the JSON-formatted log record that will be sent to Google Chronicle.

{
  "events": [
    {
      "metadata": {
        "description": "query: example.com IN A + (100.90.80.102)",
        "event_timestamp": "2023-10-09T17:35:17.165000+02:00",
        "event_type": "NETWORK_DNS",
        "ingested_timestamp": "2023-10-09T17:39:17.901029+02:00",
        "ingestion_labels": [
          {
            "key": "source_module_name",
            "value": "dns"
          },
          {
            "key": "source_module_type",
            "value": "im_file"
          }
        ],
        "product_event_type": "queries",
        "product_name": "BIND 9",
        "severity_details": "info",
        "vendor_name": "ISC"
      },
      "principal": {
        "hostname": "SERVER-1"
      },
      "src": {
        "ip": "10.120.20.20",
        "port": "4238"
      }
    }
  ]
}
Example 3. Setting the UDM schema dynamically

This configuration sends logs to Chronicle in UDM format. The output instance implements schema-selection logic based on the $EventType field. It sets the SchemaDir to a folder relative to the NXLog Agent configuration file and uses the SchemaMap directive and set_schema() procedure to set the UDM schema dynamically.

nxlog.conf
# Google Chronicle API key, required.
define API_KEY       <YOUR_API_KEY>

<Output chronicle_udm>
    Module           om_chronicle
    ChronicleKey     %API_KEY%
    ChronicleMode    structured

    SchemaDir        'chronicle-schemas'

    <SchemaMap>
        copy         file-copy.json
        delete       file-delete.json
        spawn        process-create.json
        default      default.json
    </SchemaMap>

    <Exec>
        if ($EventType == "File copied") {
            set_schema("copy");
        }
        else if ($EventType == "File deleted") {
            set_schema("delete");
        }
        else if ($EventType == "Process created") {
            set_schema("spawn");
        }
        else {
            set_schema("default");
        }
    </Exec>
</Output>
Example 4. Sending logs to Chronicle Ingestion API v2

This configuration collects logs from a BIND 9 DNS server and forwards them to Chronicle in unstructured format. Sending logs to Chronicle Ingestion API v2 requires the following directives:

nxlog.conf
# Chronicle UUID, required.
define CUSTOMER_ID     <YOUR_CHRONICLE_UUID>

<Extension syslog>
    Module             xm_syslog
</Extension>

<Output chronicle_v2>
    Module             om_chronicle
    ChronicleVersion   v2
    CustomerId         %CUSTOMER_ID%

    # Google Service Account credentias file, required.
    CredentialsFile    '/opt/nxlog/etc/credentials.json'

    # Unstructured events
    ChronicleMode      unstructured

    # Identifies the type of logs in the batch.
    LogType            BIND_DNS

    <Exec>
        $Message = $raw_event;
        to_syslog_bsd();
    </Exec>
</Output>