Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/audit-sinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<endpoint>/v1/logs`, and syslog (RFC 5424) over TLS with octet counting. Plain TCP syslog is refused in production.
- OTLP/HTTP with JSON encoding to `<endpoint>/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.
Expand Down
1 change: 1 addition & 0 deletions docs/adr/0005-extensibility-callouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| -------------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<NAME>_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. |
Expand Down
2 changes: 1 addition & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/auditSinkTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/routes/auditSinks.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
5 changes: 5 additions & 0 deletions src/services/auditSinkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
eventRecord,
sendToSink,
sinkDestinationProblem,
SYSLOG_SINKS_AVAILABLE,
SYSLOG_UNAVAILABLE,
testRecord,
} from '../lib/auditSinkTransport.js';
import { AuditSink } from '../models/auditSinks.js';
Expand Down Expand Up @@ -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);
}
Expand Down
36 changes: 33 additions & 3 deletions tests/integration/admin/auditSinks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('../../../src/models/index.js')>();
Expand All @@ -11,11 +11,17 @@ vi.mock('../../../src/models/index.js', async (importOriginal) => {

vi.mock('../../../src/lib/auditSinkTransport.js', async (importOriginal) => {
const actual = await importOriginal<typeof import('../../../src/lib/auditSinkTransport.js')>();
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';
Expand Down Expand Up @@ -62,6 +68,7 @@ beforeAll(async () => {

beforeEach(() => {
vi.clearAllMocks();
gate.syslog = false;
(Session.findOne as any).mockResolvedValue(buildFreshStepUpSession());
query.mockResolvedValue([{ head: '42', oldest: '1' }]);
});
Expand Down Expand Up @@ -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)
Expand All @@ -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);

Expand Down
8 changes: 7 additions & 1 deletion tests/postgres/auditSinks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('../../src/lib/auditSinkTransport.js')>()),
SYSLOG_SINKS_AVAILABLE: true,
}));

import { AuditSink } from '../../src/models/auditSinks.js';
import { getSequelize, initializeModels } from '../../src/models/index.js';
Expand Down
16 changes: 14 additions & 2 deletions tests/unit/services/auditSinkService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('../../../src/lib/auditSinkTransport.js')>();
return {
...actual,
get SYSLOG_SINKS_AVAILABLE() {
return gate.syslog;
},
};
});

vi.mock('../../../src/models/index.js', () => ({
Expand Down Expand Up @@ -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' }));
Expand Down Expand Up @@ -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);

Expand Down
Loading