Skip to content

Commit 1944963

Browse files
authored
feat(data-drains): add Splunk HTTP Event Collector destination (#10674)
* feat(data-drains): add Splunk HTTP Event Collector destination * fix(data-drains): wait for Splunk indexer acks and honor long Retry-After * fix(data-drains): fail unreadable Splunk replies and keep the probe to acceptance
1 parent 118b2af commit 1944963

16 files changed

Lines changed: 35291 additions & 10 deletions

File tree

‎apps/docs/content/docs/platform/enterprise/data-drains.mdx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Data drains
3-
description: Export retained logs and Chat data to storage, a warehouse, Microsoft Sentinel, Datadog, or a webhook endpoint.
3+
description: Export retained logs and Chat data to storage, a warehouse, Microsoft Sentinel, Datadog, Splunk, or a webhook endpoint.
44
---
55

66
import { Callout } from '@/components/ui/callout'
@@ -192,6 +192,16 @@ Sim posts to v2 logs intake, exposes top-level row fields as log attributes, and
192192

193193
Expanded entries are split before compression. Requests are limited to **5,000,000 uncompressed bytes**, **1,000 entries**, and **1,000,000 bytes per entry**, with a defensive 6 MiB wire-size cap. Payloads larger than 1,024 bytes use gzip.
194194

195+
### Splunk
196+
197+
Create an HTTP Event Collector (HEC) token in Splunk, then supply the **HEC URL** and **HEC token**. Enter the HEC base URL, such as `https://http-inputs-<stack>.splunkcloud.com` for Splunk Cloud Platform or `https://splunk.example.com:8088` for Splunk Enterprise; Sim appends `/services/collector/event`, and a URL that already ends in `/services/collector` or `/services/collector/event` is accepted. Any path in front of it is kept, for HEC served behind a reverse proxy. **Index** is optional and defaults to the token's default index; it must be in the token's allowed indexes. **Source type** is optional and defaults to `sim:<source>`, for example `sim:audit_logs`.
198+
199+
Each source row becomes one HEC event with the full row under `event`, `source` set to `sim`, and indexed fields `sim_drain_id`, `sim_run_id`, and `sim_source`. `time` is the row's own event time: `createdAt` for audit logs and Chats, and `startedAt` for workflow logs, job logs, and Chat runs. A row without a parseable time uses the drain run start. Search with `index=<index> sourcetype="sim:audit_logs"`; Splunk extracts the JSON fields at search time.
200+
201+
Sim batches events into requests of at most **1,000,000 bytes**, within Splunk Cloud Platform's 1 MB HEC limit. An event larger than one request fails the run; send large workflow logs or Chats to object storage instead. If large events appear cut off in search, raise `TRUNCATE` in `props.conf` for the source type. Each session sends a fresh `X-Splunk-Request-Channel`. When the token has indexer acknowledgment enabled, Sim polls `/services/collector/ack` and checkpoints a batch only after Splunk confirms it was indexed; a batch not confirmed within 120 seconds fails the run, and the next run resends it. Without acknowledgment, HTTP 200 counts as delivered.
202+
203+
**Test connection writes one probe event** with `event: {"sim":"connection-test"}` and indexed field `sim_probe=1` to the configured index. A successful test confirms Splunk accepted the event, not that it is already indexed or searchable. Invalid tokens, disabled tokens, and indexes the token may not write fail immediately with Splunk's reason; `408`, `429`, and `5xx` responses retry up to three times with backoff, honoring `Retry-After` up to 60 seconds; a longer `Retry-After` fails the run for the next one to retry. Like the webhook, the URL must use HTTPS and resolve to public addresses on Sim Cloud, Sim pins the resolved address for the run, and redirects are refused. HEC certificates must be trusted by Sim's TLS store.
204+
195205
### HTTPS webhook
196206

197207
Supply **URL**, **Signing secret**, optional **Bearer token**, and optional **Signature header name** (default `X-Sim-Signature`). On Sim Cloud, the URL must use HTTPS and resolve to public addresses. Self-hosted deployments apply their [outbound-network policy](/platform/self-hosting/security#the-ssrf-boundary): approved private endpoints and loopback are available, with HTTP only where that policy permits it. Sim blocks cloud-metadata addresses and pins the resolved address for the run to prevent DNS rebinding.

‎apps/docs/content/docs/platform/enterprise/siem.mdx‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Sim sends logs to a SIEM through [data drains](/platform/enterprise/data-drains)
1313
| --- | --- |
1414
| Microsoft Sentinel | **Microsoft Sentinel** destination. Sim writes to a custom Log Analytics table through the Logs Ingestion API. |
1515
| Datadog Cloud SIEM | **Datadog** destination. Sim writes to Datadog Logs. |
16-
| Splunk | **Amazon S3** destination, then the Splunk Add-on for AWS reads the objects. Sim has no native Splunk destination. |
16+
| Splunk | **Splunk** destination. Sim writes to the HTTP Event Collector (HEC). |
1717
| Other SIEMs | **Amazon S3**, **Google Cloud Storage**, **Azure Blob Storage**, or **HTTPS webhook**, then your SIEM's collector for that source. |
1818

1919
## Choose sources
@@ -28,7 +28,7 @@ Create one drain per source. Most security teams start with audit logs.
2828
| **Chats** | Chat conversation snapshots. |
2929
| **Chat runs** | Finished Chat runs, with agent, model, provider, status, and error. |
3030

31-
Workflow logs and Chats can contain large payloads. Sentinel rejects a row whose `Data` exceeds 64,000 bytes, so send those sources to object storage if rows are large.
31+
Workflow logs and Chats can contain large payloads. Sentinel rejects a row whose `Data` exceeds 64,000 bytes, and Sim rejects a Splunk event over 1,000,000 bytes (Splunk Cloud Platform's HEC limit), so send those sources to object storage if rows are large.
3232

3333
## Set up a drain
3434

@@ -50,13 +50,11 @@ Each source row becomes one log. Top-level row fields become log attributes. Sim
5050

5151
### Splunk
5252

53-
Splunk has no native destination in Sim. Use an S3 drain and the [Splunk Add-on for AWS SQS-based S3 input](https://splunk.github.io/splunk-add-on-for-amazon-web-services/SQS-basedS3/):
53+
Create an HTTP Event Collector token, then choose **Splunk** and enter the **HEC URL** and **HEC token**. **Index** defaults to the token's default index, and **Source type** defaults to `sim:<source>`, for example `sim:audit_logs`.
5454

55-
1. Create an **Amazon S3** drain for each source.
56-
2. In AWS, send the bucket's object-create notifications to SNS and an SQS queue, as the add-on's guide describes.
57-
3. In Splunk, add an SQS-based S3 input for that queue. Objects are newline-delimited JSON, so configure a custom sourcetype that parses one JSON event per line.
55+
Each source row becomes one HEC event. `event` holds the full source row, `time` is the row's event time (`createdAt` or `startedAt`), and the indexed fields `sim_drain_id`, `sim_run_id`, and `sim_source` identify the drain. Search with `index=<index> sourcetype="sim:audit_logs"`.
5856

59-
The SQS-based S3 input only reads objects that produce notifications. Set up the notification before creating the drain so the backfill is collected.
57+
Splunk Enterprise serves HEC on port 8088 by default. Splunk Cloud Platform serves it on 443. See [Splunk](/platform/enterprise/data-drains#splunk) for batching limits, large events, and indexer acknowledgment.
6058

6159
### Object storage and webhooks
6260

@@ -110,7 +108,7 @@ Drains are scheduled batch export, not real-time streaming; see [Cadence and lat
110108

111109
## Deduplicate on `id`
112110

113-
Delivery is at least once. A retry, a partial acceptance, or a crash after delivery can send the same row twice. Deduplicate on the row's `id` together with the source. In Sentinel, use `Source` and `RecordId`.
111+
Delivery is at least once. A retry, a partial acceptance, or a crash after delivery can send the same row twice. Deduplicate on the row's `id` together with the source. In Sentinel, use `Source` and `RecordId`. In Splunk, use `sim_source` and `event.id`.
114112

115113
## Retries and checkpoints
116114

@@ -121,7 +119,7 @@ A failed run resumes after the last accepted chunk and never skips a row; see [C
121119
Sim connects to the destination from its own servers. Allow Sim's outbound traffic through your firewall and the destination's network rules.
122120

123121
<Callout type="info">
124-
If your organization sends outbound traffic through a dedicated egress gateway, destinations must use HTTPS on port 443. A webhook or storage endpoint on another port, or over plain HTTP, fails.
122+
If your organization sends outbound traffic through a dedicated egress gateway, destinations must use HTTPS on port 443. A webhook, Splunk, or storage endpoint on another port, or over plain HTTP, fails, including Splunk Enterprise's default HEC port 8088.
125123
</Callout>
126124

127125
Self-hosted deployments also apply their [outbound-network policy](/platform/self-hosting/security#the-ssrf-boundary).

‎apps/sim/ee/data-drains/destinations/registry.tsx‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,64 @@ const datadogFormSpec: DestinationFormSpec<DatadogState> = {
396396
}),
397397
}
398398

399+
interface SplunkState {
400+
url: string
401+
index: string
402+
sourcetype: string
403+
token: string
404+
}
405+
406+
const splunkFormSpec: DestinationFormSpec<SplunkState> = {
407+
displayName: 'Splunk',
408+
initialState: { url: '', index: '', sourcetype: '', token: '' },
409+
FormFields: ({ state, setState }) => (
410+
<>
411+
<SettingRow label='HEC URL' htmlFor='drain-splunk-url'>
412+
<ChipInput
413+
id='drain-splunk-url'
414+
value={state.url}
415+
onChange={(e) => setState({ ...state, url: e.target.value })}
416+
placeholder='https://http-inputs-acme.splunkcloud.com'
417+
/>
418+
</SettingRow>
419+
<SettingRow label='Index (optional)' htmlFor='drain-splunk-index-optional'>
420+
<ChipInput
421+
id='drain-splunk-index-optional'
422+
value={state.index}
423+
onChange={(e) => setState({ ...state, index: e.target.value })}
424+
placeholder="Token's default index"
425+
/>
426+
</SettingRow>
427+
<SettingRow label='Source type (optional)' htmlFor='drain-splunk-sourcetype-optional'>
428+
<ChipInput
429+
id='drain-splunk-sourcetype-optional'
430+
value={state.sourcetype}
431+
onChange={(e) => setState({ ...state, sourcetype: e.target.value })}
432+
placeholder='sim:<source>'
433+
/>
434+
</SettingRow>
435+
<SettingRow label='HEC token' htmlFor='drain-splunk-token'>
436+
<SecretInput
437+
id='drain-splunk-token'
438+
value={state.token}
439+
onChange={(token) => setState({ ...state, token })}
440+
placeholder='Paste your HTTP Event Collector token'
441+
/>
442+
</SettingRow>
443+
</>
444+
),
445+
isComplete: (s) => s.url.trim().length > 0 && s.token.trim().length > 0,
446+
toDestinationBranch: (s) => ({
447+
destinationType: 'splunk',
448+
destinationConfig: {
449+
url: s.url.trim(),
450+
index: s.index.trim() || undefined,
451+
sourcetype: s.sourcetype.trim() || undefined,
452+
},
453+
destinationCredentials: { token: s.token.trim() },
454+
}),
455+
}
456+
399457
interface BigQueryState {
400458
projectId: string
401459
datasetId: string
@@ -661,6 +719,7 @@ export const DESTINATION_FORM_REGISTRY: Record<DestinationType, DestinationFormS
661719
azure_blob: azureBlobFormSpec as DestinationFormSpec<unknown>,
662720
sentinel: sentinelFormSpec as DestinationFormSpec<unknown>,
663721
datadog: datadogFormSpec as DestinationFormSpec<unknown>,
722+
splunk: splunkFormSpec as DestinationFormSpec<unknown>,
664723
bigquery: bigqueryFormSpec as DestinationFormSpec<unknown>,
665724
snowflake: snowflakeFormSpec as DestinationFormSpec<unknown>,
666725
webhook: webhookFormSpec as DestinationFormSpec<unknown>,

‎apps/sim/ee/data-drains/labels.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const DESTINATION_LABELS: Record<(typeof DESTINATION_TYPES)[number], stri
1414
azure_blob: 'Azure Blob Storage',
1515
sentinel: 'Microsoft Sentinel',
1616
datadog: 'Datadog',
17+
splunk: 'Splunk',
1718
bigquery: 'Google BigQuery',
1819
snowflake: 'Snowflake',
1920
webhook: 'HTTPS webhook',

‎apps/sim/lib/api/contracts/data-drains.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { z } from 'zod'
22
import { defineRouteContract } from '@/lib/api/contracts/types'
33
import { sentinelConfigSchema } from '@/lib/data-drains/destinations/sentinel-config'
4+
import { splunkConfigSchema } from '@/lib/data-drains/destinations/splunk-config'
45
import {
56
azureBlobConfigBodySchema,
67
bigqueryConfigBodySchema,
@@ -53,6 +54,10 @@ const drainDestinationResponseSchema = z.discriminatedUnion('destinationType', [
5354
destinationType: z.literal('datadog'),
5455
destinationConfig: datadogConfigBodySchema,
5556
}),
57+
z.object({
58+
destinationType: z.literal('splunk'),
59+
destinationConfig: splunkConfigSchema,
60+
}),
5661
z.object({
5762
destinationType: z.literal('bigquery'),
5863
destinationConfig: bigqueryConfigBodySchema,

‎apps/sim/lib/data-drains/destinations/registry.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { gcsDestination } from '@/lib/data-drains/destinations/gcs'
55
import { s3Destination } from '@/lib/data-drains/destinations/s3'
66
import { sentinelDestination } from '@/lib/data-drains/destinations/sentinel'
77
import { snowflakeDestination } from '@/lib/data-drains/destinations/snowflake'
8+
import { splunkDestination } from '@/lib/data-drains/destinations/splunk'
89
import { webhookDestination } from '@/lib/data-drains/destinations/webhook'
910
import type { DestinationType, DrainDestination } from '@/lib/data-drains/types'
1011

@@ -14,6 +15,7 @@ export const DESTINATION_REGISTRY = {
1415
azure_blob: azureBlobDestination,
1516
sentinel: sentinelDestination,
1617
datadog: datadogDestination,
18+
splunk: splunkDestination,
1719
bigquery: bigqueryDestination,
1820
snowflake: snowflakeDestination,
1921
webhook: webhookDestination,
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { z } from 'zod'
2+
import { validateExternalUrl } from '@/lib/core/security/input-validation'
3+
4+
const HEC_EVENT_PATH = '/services/collector/event'
5+
const HEC_PATH_SUFFIX = /\/services\/collector(?:\/event)?$/
6+
/** Splunk index names: lowercase letters, digits, `_` and `-`, not starting with `_` or `-`. */
7+
const SPLUNK_INDEX_RE = /^[a-z0-9][a-z0-9_-]{0,79}$/
8+
const SPLUNK_SOURCETYPE_RE = /^[A-Za-z0-9_][A-Za-z0-9_:.-]{0,127}$/
9+
const HEADER_INJECTION_RE = /[\r\n\0]/
10+
11+
/**
12+
* The HEC event endpoint for a configured URL. Accepts the bare HEC base URL or
13+
* one already ending in `/services/collector[/event]`, and keeps any path prefix
14+
* in front of it so HEC served behind a reverse proxy still resolves.
15+
*/
16+
export function splunkEventEndpoint(url: string): string {
17+
const parsed = new URL(url)
18+
const prefix = parsed.pathname.replace(/\/+$/, '').replace(HEC_PATH_SUFFIX, '')
19+
return `${parsed.origin}${prefix}${HEC_EVENT_PATH}`
20+
}
21+
22+
export const splunkConfigSchema = z.object({
23+
url: z
24+
.string()
25+
.trim()
26+
.url('url must be a valid URL')
27+
.max(2048, 'url must be at most 2048 characters')
28+
.refine(
29+
(value) => {
30+
if (!URL.canParse(value)) return false
31+
const url = new URL(value)
32+
return !url.username && !url.password && !url.search && !url.hash
33+
},
34+
{ message: 'url must not include credentials, a query string, or a fragment' }
35+
)
36+
.refine((value) => validateExternalUrl(value, 'url', 'configuredEndpoint').isValid, {
37+
message: 'url must be HTTPS and not point at a private, loopback, or metadata address',
38+
}),
39+
index: z
40+
.string()
41+
.trim()
42+
.regex(SPLUNK_INDEX_RE, {
43+
message:
44+
'index must be lowercase letters, digits, underscores, or hyphens, starting with a letter or digit',
45+
})
46+
.optional(),
47+
sourcetype: z
48+
.string()
49+
.trim()
50+
.regex(SPLUNK_SOURCETYPE_RE, {
51+
message: 'sourcetype may contain letters, digits, underscores, colons, dots, and hyphens',
52+
})
53+
.optional(),
54+
})
55+
56+
export const splunkCredentialsSchema = z.object({
57+
token: z
58+
.string()
59+
.trim()
60+
.min(1, 'token is required')
61+
.max(512, 'token must be at most 512 characters')
62+
.refine((value) => !HEADER_INJECTION_RE.test(value), {
63+
message: 'token cannot contain CR, LF, or NUL characters',
64+
}),
65+
})

0 commit comments

Comments
 (0)