From e73b3ca0f122adc35ac86bb24be716e2e8e55db8 Mon Sep 17 00:00:00 2001 From: Brandon Corbett Date: Sun, 8 Nov 2026 07:09:35 -0500 Subject: [PATCH 1/2] test(audit): refuse syslog sinks until the SD-ID is registered Refs #586 --- tests/integration/admin/auditSinks.spec.ts | 36 ++++++++++++++++++-- tests/postgres/auditSinks.spec.ts | 8 ++++- tests/unit/services/auditSinkService.spec.ts | 16 +++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/tests/integration/admin/auditSinks.spec.ts b/tests/integration/admin/auditSinks.spec.ts index 07c51471..aa0b882f 100644 --- a/tests/integration/admin/auditSinks.spec.ts +++ b/tests/integration/admin/auditSinks.spec.ts @@ -2,7 +2,7 @@ import { Application } from 'express'; import request from 'supertest'; import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -const { query } = vi.hoisted(() => ({ query: vi.fn() })); +const { query, gate } = vi.hoisted(() => ({ query: vi.fn(), gate: { syslog: false } })); vi.mock('../../../src/models/index.js', async (importOriginal) => { const actual = await importOriginal(); @@ -11,11 +11,17 @@ vi.mock('../../../src/models/index.js', async (importOriginal) => { vi.mock('../../../src/lib/auditSinkTransport.js', async (importOriginal) => { const actual = await importOriginal(); - return { ...actual, sendToSink: vi.fn() }; + return { + ...actual, + sendToSink: vi.fn(), + get SYSLOG_SINKS_AVAILABLE() { + return gate.syslog; + }, + }; }); import { createApp } from '../../../src/app'; -import { sendToSink } from '../../../src/lib/auditSinkTransport.js'; +import { sendToSink, SYSLOG_UNAVAILABLE } from '../../../src/lib/auditSinkTransport.js'; import { AuditSink } from '../../../src/models/auditSinks.js'; import { Session } from '../../../src/models/sessions.js'; import { AuthEventService } from '../../../src/services/authEventService.js'; @@ -62,6 +68,7 @@ beforeAll(async () => { beforeEach(() => { vi.clearAllMocks(); + gate.syslog = false; (Session.findOne as any).mockResolvedValue(buildFreshStepUpSession()); query.mockResolvedValue([{ head: '42', oldest: '1' }]); }); @@ -111,7 +118,29 @@ describe('audit sinks', () => { expect(AuditSink.create).not.toHaveBeenCalled(); }); + it('refuses a syslog sink until its SD-ID is registered', async () => { + const created = await request(app) + .post('/admin/audit-sinks') + .send({ name: 'SIEM', settings: { kind: 'syslog', host: 'collector.example.com' } }); + + expect(created.status).toBe(400); + expect(created.body.error).toBe(SYSLOG_UNAVAILABLE); + expect(AuditSink.create).not.toHaveBeenCalled(); + + const record = buildSink(); + vi.mocked(AuditSink.findByPk).mockResolvedValue(record); + + const updated = await request(app) + .patch(`/admin/audit-sinks/${sinkId}`) + .send({ settings: { kind: 'syslog', host: 'collector.example.com' } }); + + expect(updated.status).toBe(400); + expect(updated.body.error).toBe(SYSLOG_UNAVAILABLE); + expect(record.update).not.toHaveBeenCalled(); + }); + it('refuses plain TCP syslog in production', async () => { + gate.syslog = true; vi.stubEnv('NODE_ENV', 'production'); const res = await request(app) @@ -138,6 +167,7 @@ describe('audit sinks', () => { }); it('reads, updates and deletes a sink, auditing each write', async () => { + gate.syslog = true; const record = buildSink(); vi.mocked(AuditSink.findByPk).mockResolvedValue(record); diff --git a/tests/postgres/auditSinks.spec.ts b/tests/postgres/auditSinks.spec.ts index a94f5c91..6017d0f6 100644 --- a/tests/postgres/auditSinks.spec.ts +++ b/tests/postgres/auditSinks.spec.ts @@ -9,7 +9,13 @@ import { import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'; +import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; + +// The syslog transport stays tested end to end while the API refuses new syslog sinks (#586). +vi.mock('../../src/lib/auditSinkTransport.js', async (importOriginal) => ({ + ...(await importOriginal()), + SYSLOG_SINKS_AVAILABLE: true, +})); import { AuditSink } from '../../src/models/auditSinks.js'; import { getSequelize, initializeModels } from '../../src/models/index.js'; diff --git a/tests/unit/services/auditSinkService.spec.ts b/tests/unit/services/auditSinkService.spec.ts index 818e6868..a4ad284e 100644 --- a/tests/unit/services/auditSinkService.spec.ts +++ b/tests/unit/services/auditSinkService.spec.ts @@ -3,10 +3,20 @@ import type { AddressInfo } from 'node:net'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -const { query, transaction } = vi.hoisted(() => { +const { query, transaction, gate } = vi.hoisted(() => { const query = vi.fn(); const transaction = vi.fn(async (fn: (t: unknown) => unknown) => fn({ id: 'tx' })); - return { query, transaction }; + return { query, transaction, gate: { syslog: false } }; +}); + +vi.mock('../../../src/lib/auditSinkTransport.js', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + get SYSLOG_SINKS_AVAILABLE() { + return gate.syslog; + }, + }; }); vi.mock('../../../src/models/index.js', () => ({ @@ -45,6 +55,7 @@ let bodies: string[]; let status: number; beforeEach(async () => { + gate.syslog = false; bodies = []; status = 200; transaction.mockImplementation(async (fn: (t: unknown) => unknown) => fn({ id: 'tx' })); @@ -211,6 +222,7 @@ describe('sinks', () => { }); it('updates fields and clears the backoff, keeping the cursor', async () => { + gate.syslog = true; const record = sink({ failureCount: 4, nextAttemptAt: new Date(Date.now() + 60_000) }); vi.mocked(AuditSink.findByPk).mockResolvedValue(record); From 2cebd1f085f62518af434091bc25912061c4329a Mon Sep 17 00:00:00 2001 From: Brandon Corbett Date: Sun, 8 Nov 2026 07:09:54 -0500 Subject: [PATCH 2/2] fix(audit): refuse syslog sinks until 0.23.1 Syslog records carry seq and hash in an SD-ID that needs the Fells Code IANA enterprise number. Collectors key their parsing rules on it, so shipping the RFC 5612 documentation number and changing it later would break them. Creating or updating a syslog sink now returns 400 until 0.23.1 sets the real SD-ID. The transport stays in the code and its end to end test still runs. Refs #586 --- .changeset/audit-sinks.md | 2 +- docs/adr/0005-extensibility-callouts.md | 1 + docs/configuration.md | 4 ++++ openapi.json | 2 +- src/generated/api.ts | 2 +- src/lib/auditSinkTransport.ts | 10 ++++++++++ src/routes/auditSinks.routes.ts | 2 +- src/services/auditSinkService.ts | 5 +++++ 8 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.changeset/audit-sinks.md b/.changeset/audit-sinks.md index 693d5682..9ccd3323 100644 --- a/.changeset/audit-sinks.md +++ b/.changeset/audit-sinks.md @@ -5,7 +5,7 @@ Stream audit events to a SIEM (ADR 0005, #420). - Admin API under `/admin/audit-sinks`: create, update, disable and delete sinks, and send a test record. Every write takes step-up and is audited as `admin_audit_sink_created`, `admin_audit_sink_updated` or `admin_audit_sink_deleted`. -- OTLP/HTTP with JSON encoding to `/v1/logs`, and syslog (RFC 5424) over TLS with octet counting. Plain TCP syslog is refused in production. +- OTLP/HTTP with JSON encoding to `/v1/logs`. Syslog (RFC 5424 over TLS, octet counted) arrives in 0.23.1: creating or updating a syslog sink is refused with a 400 until its structured data ID carries the Fells Code IANA enterprise number (#586). - Every record carries the event's `seamless-auth-events/1` export line, so the hash chain verifies downstream as an export does. - Each sink has its own cursor and retries until its collector takes the events, backing off to one minute. There is no dead letter: a sink reports how far behind the chain head it is. - Credentials are never stored. A sink names env vars ending `_AUDIT_SINK_SECRET`, read at send time. diff --git a/docs/adr/0005-extensibility-callouts.md b/docs/adr/0005-extensibility-callouts.md index 20f5ce8c..cc9d64f0 100644 --- a/docs/adr/0005-extensibility-callouts.md +++ b/docs/adr/0005-extensibility-callouts.md @@ -101,6 +101,7 @@ Among roles of one kind, sets apply in role-name order, so the last name alphabe - Retention never deletes past the oldest sink cursor, and a disabled sink holds it too (decided 2026-11-07). An audit event deleted before a SIEM receives it cannot be recovered, so a disabled sink holds retention until it is deleted. Retention logs a warning naming the holding sink and saying to delete it to release retention. - An OTLP 2xx counts as delivered, including one whose `partialSuccess` reports rejected records (decided 2026-11-07). A collector rejects such records for their content, so retrying them would stall the sink forever. - Syslog records carry `seq` and `hash` in the SD-ID `seamless@32473`. 32473 is the RFC 5612 documentation number, a placeholder until Fells Code has an IANA Private Enterprise Number (#586). A release must not ship with it. +- 0.23.0 ships with OTLP only (decided 2026-11-08). Collectors key their parsing rules on the SD-ID, so shipping the placeholder and changing it later would break those rules. The syslog transport is in the code, but creating or updating a syslog sink is refused with a 400 until 0.23.1 sets the real SD-ID and lifts the refusal (#586). ### E8. Every callout follows the same reachability rules diff --git a/docs/configuration.md b/docs/configuration.md index 3f5f37e6..379fd871 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -127,6 +127,10 @@ export does. A sink retries until its collector takes the events, backing off to reports how far behind the chain head it is. Destinations follow the same rules as webhooks, including `CALLOUT_PRIVATE_HOSTS`, and plain TCP syslog is refused in production. +Syslog sinks arrive in 0.23.1. Until then the API refuses to create or update one with a 400, +because the syslog records' SD-ID needs the Fells Code IANA enterprise number first (#586). Use an +OTLP sink in the meantime. + | Variable | Required | Default | Notes | | -------------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `_AUDIT_SINK_SECRET` | No | - | Credentials a sink names rather than stores: an OTLP header value (`headersFromEnv`), or a PEM CA, client certificate or client key for syslog TLS. Names must end in `_AUDIT_SINK_SECRET`. Read at send time; a sink whose variable is unset fails with `refused` and sends nothing. | diff --git a/openapi.json b/openapi.json index 50d3a311..f62775ea 100644 --- a/openapi.json +++ b/openapi.json @@ -10391,7 +10391,7 @@ }, "post": { "summary": "Create an audit sink", - "description": "Starts after the newest event unless `startAfterSeq` replays from an earlier one. Credentials are named as `_AUDIT_SINK_SECRET` env vars, never stored.", + "description": "Starts after the newest event unless `startAfterSeq` replays from an earlier one. Credentials are named as `_AUDIT_SINK_SECRET` env vars, never stored. A syslog sink is refused with a 400 until 0.23.1.", "tags": ["Admin", "Audit sinks"], "security": [{ "bearerAuth": [] }], "requestBody": { diff --git a/src/generated/api.ts b/src/generated/api.ts index 715cdbb7..88abaffc 100644 --- a/src/generated/api.ts +++ b/src/generated/api.ts @@ -9838,7 +9838,7 @@ export interface paths { put?: never; /** * Create an audit sink - * @description Starts after the newest event unless `startAfterSeq` replays from an earlier one. Credentials are named as `_AUDIT_SINK_SECRET` env vars, never stored. + * @description Starts after the newest event unless `startAfterSeq` replays from an earlier one. Credentials are named as `_AUDIT_SINK_SECRET` env vars, never stored. A syslog sink is refused with a 400 until 0.23.1. */ post: { parameters: { diff --git a/src/lib/auditSinkTransport.ts b/src/lib/auditSinkTransport.ts index 6a3f5a4e..7a4bf91b 100644 --- a/src/lib/auditSinkTransport.ts +++ b/src/lib/auditSinkTransport.ts @@ -39,6 +39,16 @@ const MAX_RESPONSE_BYTES = 64 * 1024; // TODO(#586): replace 32473 with the Fells Code IANA enterprise number before release. export const SYSLOG_SD_ID = 'seamless@32473'; +/** + * Collectors key their parsing rules on the SD-ID, so changing it once adopters have written + * those rules is a breaking change. Syslog sinks stay refused until the real number is in. + */ +// TODO(#586): set to true in 0.23.1 together with the real SD-ID. +export const SYSLOG_SINKS_AVAILABLE = false; + +export const SYSLOG_UNAVAILABLE = + 'Syslog audit sinks are not available in this release; they arrive in Seamless Auth 0.23.1. Use an OTLP sink until then.'; + export const AUDIT_SINK_SCOPE = 'seamless-auth.audit'; /** diff --git a/src/routes/auditSinks.routes.ts b/src/routes/auditSinks.routes.ts index f8dea86e..c9598607 100644 --- a/src/routes/auditSinks.routes.ts +++ b/src/routes/auditSinks.routes.ts @@ -53,7 +53,7 @@ router.post( ...write, summary: 'Create an audit sink', description: - 'Starts after the newest event unless `startAfterSeq` replays from an earlier one. Credentials are named as `_AUDIT_SINK_SECRET` env vars, never stored.', + 'Starts after the newest event unless `startAfterSeq` replays from an earlier one. Credentials are named as `_AUDIT_SINK_SECRET` env vars, never stored. A syslog sink is refused with a 400 until 0.23.1.', schemas: { body: CreateAuditSinkRequestSchema, response: { 201: AuditSinkResponseSchema, 400: ErrorSchema, 403: StepUpRequiredErrorSchema }, diff --git a/src/services/auditSinkService.ts b/src/services/auditSinkService.ts index 88f88636..ad84ca98 100644 --- a/src/services/auditSinkService.ts +++ b/src/services/auditSinkService.ts @@ -16,6 +16,8 @@ import { eventRecord, sendToSink, sinkDestinationProblem, + SYSLOG_SINKS_AVAILABLE, + SYSLOG_UNAVAILABLE, testRecord, } from '../lib/auditSinkTransport.js'; import { AuditSink } from '../models/auditSinks.js'; @@ -84,6 +86,9 @@ export function serializeSink(sink: AuditSink, head: number) { } function assertSettings(settings: AuditSinkSettings) { + if (settings.kind === 'syslog' && !SYSLOG_SINKS_AVAILABLE) { + throw new AuditSinkError(400, SYSLOG_UNAVAILABLE); + } const problem = sinkDestinationProblem(settings); if (problem) throw new AuditSinkError(400, problem); }