Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-api): require the Host uid and reject unknown reference keys

Alfredo Lopezeba164563c0f
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index c76225829..461945ecf 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.588",
+ "version": "0.1.589",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.588",
+ "version": "0.1.589",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --git a/control-api/package.json b/control-api/package.json
index d3cc0edd9..a518fab2a 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.588",
+ "version": "0.1.589",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/services/tracing/hccHealthTransitionBindingResolver.ts b/control-api/src/services/tracing/hccHealthTransitionBindingResolver.ts
index a0da0b6d0..714a50a8d 100644
--- a/control-api/src/services/tracing/hccHealthTransitionBindingResolver.ts
+++ b/control-api/src/services/tracing/hccHealthTransitionBindingResolver.ts
@@ -4,7 +4,10 @@ import type {
InfrastructureTelemetryServerBindingV1,
} from './contracts.js'
import { canonicalTracingClusterName, canonicalTracingEnvironment } from './environment.js'
-import type { InfrastructureWorkloadBindingResolver } from './routeSubmissionService.js'
+import {
+ type InfrastructureWorkloadBindingResolver,
+ InvalidTracingInputError,
+} from './routeSubmissionService.js'
export const HCC_HEALTH_TRANSITION_BINDING_BLOCKER =
'hcc_telemetry_requires_server_verifiable_host_reference'
@@ -73,6 +76,16 @@ export class HccHealthTransitionBindingResolver implements InfrastructureWorkloa
) {
throw new HccHealthTransitionBindingUnavailableError()
}
+ if (reference.uid === undefined) {
+ // The uid became mandatory once HCC started sending it: a Host deleted
+ // and recreated under the same name restarts at generation 1, so without
+ // it an event observed on the old object can bind to its successor. This
+ // is a 400 rather than the 403 above because the caller can fix it, and
+ // HCC treats a 400 as terminal instead of retrying forever (#693).
+ throw new InvalidTracingInputError(
+ 'hostLookupReference.uid is required for host-context-controller telemetry'
+ )
+ }
let host: AuthoritativeHost
try {
@@ -94,7 +107,7 @@ export class HccHealthTransitionBindingResolver implements InfrastructureWorkloa
// A Host deleted and recreated under the same name restarts at generation 1;
// only the uid tells the objects apart, so an event observed on the old
// object must not bind to its successor (#691).
- (reference.uid !== undefined && metadata.uid !== reference.uid)
+ metadata.uid !== reference.uid
) {
return null
}
diff --git a/control-api/src/services/tracing/routeSubmissionService.ts b/control-api/src/services/tracing/routeSubmissionService.ts
index 19b7cc5f1..1049a5bc0 100644
--- a/control-api/src/services/tracing/routeSubmissionService.ts
+++ b/control-api/src/services/tracing/routeSubmissionService.ts
@@ -156,6 +156,7 @@ const ADMIN_FIELDS = new Set([
'reasonCode',
'sourceStatusRef',
])
+const HOST_LOOKUP_REFERENCE_KEYS = new Set(['name', 'namespace', 'generation', 'uid'])
const INFRA_FIELDS = new Set([
'sourceEventId',
'occurredAt',
@@ -300,6 +301,12 @@ function normalizeInfra(
(!hostLookupReference ||
typeof hostLookupReference !== 'object' ||
Array.isArray(hostLookupReference) ||
+ // An unknown key is a caller that believes it is sending something the
+ // server reads. Accepting it silently would bind the event on the keys
+ // that did parse, so the reference is refused instead (#693).
+ Object.keys(hostLookupReference as Record<string, unknown>).some(
+ key => !HOST_LOOKUP_REFERENCE_KEYS.has(key)
+ ) ||
typeof (hostLookupReference as Record<string, unknown>).name !== 'string' ||
typeof (hostLookupReference as Record<string, unknown>).namespace !== 'string' ||
((hostLookupReference as Record<string, unknown>).generation !== undefined &&
diff --git a/control-api/test/routes.tracingSubmissionBoundary.test.ts b/control-api/test/routes.tracingSubmissionBoundary.test.ts
index 24ff23150..7151a370c 100644
--- a/control-api/test/routes.tracingSubmissionBoundary.test.ts
+++ b/control-api/test/routes.tracingSubmissionBoundary.test.ts
@@ -3,6 +3,7 @@ import express from 'express'
import jwt from 'jsonwebtoken'
import request from 'supertest'
import { config } from '../src/config.js'
+import type { DbClient } from '../src/db.js'
import { clerumErrorHandler } from '../src/http/errorHandler.js'
import { createInternalAdministrativeEventsRouter } from '../src/routes/internal/administrativeEvents.js'
import { createInternalAgentRunEventsRouter } from '../src/routes/internal/agentRunEvents.js'
@@ -11,8 +12,11 @@ import {
TracingIdempotencyConflictError,
UnsafeTracingInputError,
} from '../src/services/tracing/append.js'
+import type { TracingTransactionRunner } from '../src/services/tracing/contracts.js'
+import { HccHealthTransitionBindingResolver } from '../src/services/tracing/hccHealthTransitionBindingResolver.js'
import {
InvalidTracingInputError,
+ RouteTracingSubmissionService,
TracingBindingUnavailableError,
} from '../src/services/tracing/routeSubmissionService.js'
import { issueMcpHostAccessJwt } from '../src/utils/auth/mcpHostJwtToken.js'
@@ -296,6 +300,62 @@ describe('internal tracing submission routers', () => {
// HCC settles a submission without retry only on these (status, code) pairs
// (#326), so the code has to survive the real router and the global handler.
describe('internal tracing submission routers — rejection code on the wire', () => {
+ const HOST_UID = '6f1c2f3a-2f4b-4d3a-9b2e-7c0d1a5e8b44'
+
+ /**
+ * The real router over the real submission service, the real HCC resolver and
+ * the global handler. Only the API-server read and the database append are
+ * doubles, so everything the request actually has to pass through is wired.
+ */
+ function realInfrastructureApp() {
+ const getResource = vi.fn().mockResolvedValue({
+ apiVersion: 'clerum.io/v1alpha1',
+ kind: 'Host',
+ metadata: { name: 'chatllm', namespace: 'mcp-host', uid: HOST_UID, generation: 7 },
+ })
+ const appendManyInTransaction = vi.fn().mockResolvedValue([
+ {
+ kind: 'accepted' as const,
+ accepted: 1,
+ replayed: 0,
+ family: 'infrastructure_telemetry' as const,
+ eventId: '11111111-1111-4111-8111-111111111111',
+ streamSequence: '41',
+ payloadSha256: 'a'.repeat(64),
+ ingestedAt: '2026-07-10T10:00:00.000Z',
+ },
+ ])
+ const db = { query: vi.fn() } as unknown as DbClient
+ const service = new RouteTracingSubmissionService({
+ transaction: (async (work: (client: DbClient) => Promise<unknown>) =>
+ work(db)) as unknown as TracingTransactionRunner,
+ infrastructureWorkloadBindingResolver: new HccHealthTransitionBindingResolver({
+ getResource,
+ }),
+ infrastructureTelemetryAppender: { appendManyInTransaction },
+ })
+ const app = express()
+ app.use(createInternalInfrastructureTelemetryEventsRouter(service))
+ app.use(clerumErrorHandler)
+ return { app, getResource, appendManyInTransaction }
+ }
+
+ function postTelemetry(app: express.Express, hostLookupReference: Record<string, unknown>) {
+ return request(app)
+ .post('/internal/tracing/infrastructure-telemetry-events')
+ .set('Authorization', `Bearer ${signInternalControl('hcc')}`)
+ .send({
+ events: [
+ {
+ telemetryType: 'health_transition',
+ sourceEventId: `health-${JSON.stringify(hostLookupReference).length}`,
+ occurredAt: '2026-07-10T09:59:59.000Z',
+ hostLookupReference,
+ },
+ ],
+ })
+ }
+
type RejectingService = { submit: () => Promise<never> }
function rejectingApp(router: (service: RejectingService) => express.Router, err: unknown) {
const service = { submit: vi.fn<() => Promise<never>>(async () => Promise.reject(err)) }
@@ -343,6 +403,52 @@ describe('internal tracing submission routers — rejection code on the wire', (
expect(response.body).toMatchObject({ code, correlationId: expect.any(String) })
})
+ // The rows above stub the service, so they only prove the handler forwards a
+ // code it is handed. These two rejections have to be reached through the real
+ // normalizer and the real resolver, or the validation could be absent from
+ // the wired route while every unit test stayed green (#693).
+ it.each([
+ ['without a uid', { name: 'chatllm', namespace: 'mcp-host', generation: 7 }],
+ [
+ 'with an unknown key',
+ {
+ name: 'chatllm',
+ namespace: 'mcp-host',
+ generation: 7,
+ uid: HOST_UID,
+ resourceVersion: '1',
+ },
+ ],
+ ] as const)(
+ 'refuses a Host reference %s as 400 invalid_tracing_input through the real route',
+ async (_label, hostLookupReference) => {
+ const { app, getResource, appendManyInTransaction } = realInfrastructureApp()
+
+ // Liveness: the same app, principal and route accept the uid-bearing
+ // reference, so a 400 below is this reference being refused, not the
+ // wiring refusing everything.
+ const accepted = await postTelemetry(app, {
+ name: 'chatllm',
+ namespace: 'mcp-host',
+ generation: 7,
+ uid: HOST_UID,
+ })
+ expect(accepted.status).toBe(200)
+ expect(accepted.body).toMatchObject({ accepted: 1, replayed: 0 })
+
+ const response = await postTelemetry(app, hostLookupReference)
+
+ expect(response.status).toBe(400)
+ expect(response.body).toMatchObject({
+ code: 'invalid_tracing_input',
+ correlationId: expect.any(String),
+ })
+ // Neither rejection consults the API server or opens a transaction.
+ expect(getResource).toHaveBeenCalledOnce()
+ expect(appendManyInTransaction).toHaveBeenCalledOnce()
+ }
+ )
+
it('keeps a binding 403 without a code, so HCC keeps retrying it', async () => {
const { app, service } = rejectingApp(
createInternalAdministrativeEventsRouter,
diff --git a/control-api/test/services.firstVerticalBindingResolvers.test.ts b/control-api/test/services.firstVerticalBindingResolvers.test.ts
index 78047388c..e61ab3a24 100644
--- a/control-api/test/services.firstVerticalBindingResolvers.test.ts
+++ b/control-api/test/services.firstVerticalBindingResolvers.test.ts
@@ -109,7 +109,12 @@ describe('first vertical trusted binding resolvers', () => {
sourceEventId: 'health-1',
occurredAt: NOW,
telemetryType: 'health_transition',
- hostLookupReference: { name: 'chatllm', namespace: 'mcp-host', generation: 7 },
+ hostLookupReference: {
+ name: 'chatllm',
+ namespace: 'mcp-host',
+ generation: 7,
+ uid: 'host-uid',
+ },
})
expect(hostLookup.getResource).toHaveBeenCalledWith('hosts', 'chatllm', 'mcp-host')
@@ -149,7 +154,12 @@ describe('first vertical trusted binding resolvers', () => {
sourceEventId: `${telemetryType}-1`,
occurredAt: NOW,
telemetryType,
- hostLookupReference: { name: 'chatllm', namespace: 'mcp-host', generation: 7 },
+ hostLookupReference: {
+ name: 'chatllm',
+ namespace: 'mcp-host',
+ generation: 7,
+ uid: 'host-uid',
+ },
...(telemetryType === 'reconcile_outcome'
? { payload: { status: 'succeeded', reason_code: 'ready' } }
: telemetryType === 'controller_error'
@@ -204,7 +214,12 @@ describe('first vertical trusted binding resolvers', () => {
sourceEventId: `reconcile-${status}`,
occurredAt: NOW,
telemetryType: 'reconcile_outcome',
- hostLookupReference: { name: 'chatllm', namespace: 'mcp-host', generation: 7 },
+ hostLookupReference: {
+ name: 'chatllm',
+ namespace: 'mcp-host',
+ generation: 7,
+ uid: 'host-uid',
+ },
payload: { status, reason_code: status === 'succeeded' ? 'ready' : 'not_ready' },
})
).resolves.toMatchObject({ outcome })
@@ -217,7 +232,7 @@ describe('first vertical trusted binding resolvers', () => {
getResource: vi.fn().mockResolvedValue({
apiVersion: 'clerum.io/v1alpha1',
kind: 'Host',
- metadata: { name: 'chatllm', namespace: 'mcp-host', generation: 7 },
+ metadata: { name: 'chatllm', namespace: 'mcp-host', uid: 'host-uid', generation: 7 },
}),
}
const principal = {
@@ -234,7 +249,12 @@ describe('first vertical trusted binding resolvers', () => {
sourceEventId: `reconcile-${status ?? 'missing'}`,
occurredAt: NOW,
telemetryType: 'reconcile_outcome',
- hostLookupReference: { name: 'chatllm', namespace: 'mcp-host', generation: 7 },
+ hostLookupReference: {
+ name: 'chatllm',
+ namespace: 'mcp-host',
+ generation: 7,
+ uid: 'host-uid',
+ },
...(status === undefined ? {} : { payload: { status } }),
})
).resolves.toBeNull()
@@ -281,16 +301,22 @@ describe('first vertical trusted binding resolvers', () => {
getResource: vi.fn().mockResolvedValue({
apiVersion: 'clerum.io/v1alpha1',
kind: 'Host',
- metadata: { name: 'chatllm', namespace: 'mcp-host', generation: 8 },
+ metadata: { name: 'chatllm', namespace: 'mcp-host', uid: 'host-uid', generation: 8 },
}),
})
+ const reference = {
+ name: 'chatllm',
+ namespace: 'mcp-host',
+ generation: 7,
+ uid: 'host-uid',
+ }
await expect(
unavailable.resolve(principal, {
sourceEventId: 'health-1',
occurredAt: NOW,
telemetryType: 'health_transition',
- hostLookupReference: { name: 'chatllm', namespace: 'mcp-host', generation: 7 },
+ hostLookupReference: reference,
})
).resolves.toBeNull()
await expect(
@@ -298,7 +324,7 @@ describe('first vertical trusted binding resolvers', () => {
sourceEventId: 'health-1',
occurredAt: NOW,
telemetryType: 'health_transition',
- hostLookupReference: { name: 'chatllm', namespace: 'mcp-host', generation: 7 },
+ hostLookupReference: reference,
})
).resolves.toBeNull()
await expect(
@@ -346,12 +372,65 @@ describe('first vertical trusted binding resolvers', () => {
metadataGeneration: 1,
})
await expect(resolver.resolve(principal, event('old-uid'))).resolves.toBeNull()
- // A reference without uid (HCC before this change) still binds.
- await expect(resolver.resolve(principal, event())).resolves.toMatchObject({
- kubernetesUid: 'new-uid',
+ // A reference without uid was accepted while HCC was still rolling out
+ // (#691). It is now refused as invalid input, not silently bound to
+ // whichever Host answers to the name (#693).
+ await expect(resolver.resolve(principal, event())).rejects.toMatchObject({
+ code: 'invalid_tracing_input',
+ status: 400,
})
- // Liveness: the authoritative Host read ran for all three references.
- expect(hostLookup.getResource).toHaveBeenCalledTimes(3)
+ // Liveness: the authoritative Host read ran for both uid-bearing
+ // references, and not for the one refused before the lookup.
+ expect(hostLookup.getResource).toHaveBeenCalledTimes(2)
+ })
+
+ it('refuses an unresolvable Host reference before reading the API server (#693)', async () => {
+ const hostLookup = { getResource: vi.fn() }
+ const principal = {
+ kind: 'hcc_internal_control',
+ sourceService: 'host-context-controller',
+ serviceSub: 'hcc-provisioner',
+ credentialId: 'hcc-1',
+ resourceAuthority: 'hcc_managed',
+ allowedTelemetryTypes: ['health_transition'],
+ } as const
+
+ await expect(
+ new HccHealthTransitionBindingResolver(hostLookup).resolve(principal, {
+ sourceEventId: 'health-no-uid',
+ occurredAt: NOW,
+ telemetryType: 'health_transition',
+ hostLookupReference: { name: 'chatllm', namespace: 'mcp-host', generation: 7 },
+ })
+ ).rejects.toMatchObject({ code: 'invalid_tracing_input', status: 400 })
+ // A 400 is terminal for HCC, so the rejection has to be decidable from the
+ // request alone: no authoritative read, no dependence on cluster state.
+ expect(hostLookup.getResource).not.toHaveBeenCalled()
+ })
+
+ it('leaves a non-HCC event to the next resolver instead of rejecting it (#693)', async () => {
+ // The uid requirement sits behind the principal guard on purpose. The
+ // chain does not catch exceptions, so a throw here would abort a WRC batch
+ // before wrcInfrastructureBindingResolver ever saw it.
+ const hostLookup = { getResource: vi.fn() }
+ const principal = {
+ kind: 'wrc_internal_control',
+ sourceService: 'workflow-recipes',
+ serviceSub: 'wrc-provisioner',
+ credentialId: 'wrc-1',
+ resourceAuthority: 'wrc_managed',
+ allowedTelemetryTypes: ['health_transition'],
+ } as const
+
+ await expect(
+ new HccHealthTransitionBindingResolver(hostLookup).resolve(principal, {
+ sourceEventId: 'health-wrc',
+ occurredAt: NOW,
+ telemetryType: 'health_transition',
+ hostLookupReference: { name: 'chatllm', namespace: 'mcp-host', generation: 7 },
+ })
+ ).resolves.toBeNull()
+ expect(hostLookup.getResource).not.toHaveBeenCalled()
})
it('resolves WRC infrastructure batches from authoritative workflow rows in one query', async () => {
diff --git a/scripts/e2e/e2e-governed-tracing-operations.sh b/scripts/e2e/e2e-governed-tracing-operations.sh
index 5efc5b0a3..f14636e58 100755
--- a/scripts/e2e/e2e-governed-tracing-operations.sh
+++ b/scripts/e2e/e2e-governed-tracing-operations.sh
@@ -63,6 +63,9 @@ TMP_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/clerum-governed-tracing-operations.XXXXXX
AUTH_CONFIG="$TMP_ROOT/curl-auth.conf"
OVERSIZED_BODY="$TMP_ROOT/oversized.json"
VALID_BODY="$TMP_ROOT/valid.json"
+MISSING_UID_BODY="$TMP_ROOT/missing-uid.json"
+UNKNOWN_KEY_BODY="$TMP_ROOT/unknown-key.json"
+LEGACY_STATUS_REF_BODY="$TMP_ROOT/legacy-status-ref.json"
RESPONSE_BODY="$TMP_ROOT/response.json"
PLAYWRIGHT_RESULT="$TMP_ROOT/playwright-result.json"
cleanup() { rm -rf "$TMP_ROOT"; }
@@ -111,12 +114,43 @@ if (body.error !== 'payload_too_large' || body.maxBytes !== expectedMax) {
NODE
}
-assert_valid_ingestion_response() {
- node - "$RESPONSE_BODY" <<'NODE'
+assert_ingestion_counts() {
+ node - "$RESPONSE_BODY" "$1" "$2" <<'NODE'
const fs = require('node:fs')
-const body = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'))
-if (body.accepted !== 1 || body.replayed !== 0) {
- throw new Error(`unexpected valid-ingestion response: ${JSON.stringify(body)}`)
+const [target, accepted, replayed] = process.argv.slice(2)
+const body = JSON.parse(fs.readFileSync(target, 'utf8'))
+if (body.accepted !== Number(accepted) || body.replayed !== Number(replayed)) {
+ throw new Error(
+ `expected accepted:${accepted} replayed:${replayed}, got ${JSON.stringify(body)}`
+ )
+}
+NODE
+}
+
+# A 400 only proves the request was refused; the code proves it was refused by
+# the tracing input validation reached through the real route, which is the
+# signal HCC keys its terminal-versus-retryable decision on (#693).
+assert_rejection_code() {
+ node - "$RESPONSE_BODY" "$1" <<'NODE'
+const fs = require('node:fs')
+const [target, expected] = process.argv.slice(2)
+const body = JSON.parse(fs.readFileSync(target, 'utf8'))
+if (body.code !== expected) {
+ throw new Error(`expected code ${expected}, got ${JSON.stringify(body)}`)
+}
+NODE
+}
+
+# The administrative 403 carries no machine-readable code, so the message is
+# what tells a refused binding from a refused credential. Without it an
+# authentication failure would satisfy the same status assertion.
+assert_rejection_message() {
+ node - "$RESPONSE_BODY" "$1" <<'NODE'
+const fs = require('node:fs')
+const [target, expected] = process.argv.slice(2)
+const body = JSON.parse(fs.readFileSync(target, 'utf8'))
+if (typeof body.error !== 'string' || !body.error.includes(expected)) {
+ throw new Error(`expected an error mentioning ${expected}, got ${JSON.stringify(body)}`)
}
NODE
}
@@ -157,22 +191,58 @@ log "authenticated 413 incremented the existing body-limit metric to $COUNT_AFTE
HOST_RECORD="$(
kubectl --context="$KCTX" get hosts.clerum.io -A \
- -o jsonpath='{.items[0].metadata.namespace}{"|"}{.items[0].metadata.name}{"|"}{.items[0].metadata.generation}'
+ -o jsonpath='{.items[0].metadata.namespace}{"|"}{.items[0].metadata.name}{"|"}{.items[0].metadata.generation}{"|"}{.items[0].metadata.uid}'
)"
-IFS='|' read -r HOST_NAMESPACE HOST_NAME HOST_GENERATION <<<"$HOST_RECORD"
+IFS='|' read -r HOST_NAMESPACE HOST_NAME HOST_GENERATION HOST_UID <<<"$HOST_RECORD"
[[ -n "$HOST_NAMESPACE" && -n "$HOST_NAME" ]] || die 'the profile has no Host for valid tracing ingestion'
[[ "$HOST_GENERATION" =~ ^[1-9][0-9]*$ ]] || die 'the selected Host has no valid generation'
+# The uid is mandatory since #693: namespace/name/generation alone can name a
+# Host and its same-name successor, so control-api refuses the reference.
+[[ "$HOST_UID" =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ ]] || \
+ die 'the selected Host has no valid metadata.uid'
-node - "$VALID_BODY" "$HOST_NAMESPACE" "$HOST_NAME" "$HOST_GENERATION" "$REQUEST_STARTED_AT_MS" <<'NODE'
+write_host_telemetry_body() {
+ node - "$1" "$HOST_NAMESPACE" "$HOST_NAME" "$HOST_GENERATION" "$HOST_UID" \
+ "$REQUEST_STARTED_AT_MS" "$2" "$3" <<'NODE'
const fs = require('node:fs')
-const [target, namespace, name, generation, startedAt] = process.argv.slice(2)
+const [target, namespace, name, generation, uid, startedAt, suffix, variant] =
+ process.argv.slice(2)
+const reference = { namespace, name, generation: Number(generation), uid }
+if (variant === 'missing-uid') delete reference.uid
+if (variant === 'unknown-key') reference.resourceVersion = '1'
const body = {
events: [
{
telemetryType: 'health_transition',
- sourceEventId: `e2e-governed-tracing-operations-${startedAt}`,
+ sourceEventId: `e2e-governed-tracing-operations-${startedAt}${suffix}`,
occurredAt: new Date().toISOString(),
- hostLookupReference: { namespace, name, generation: Number(generation) },
+ hostLookupReference: reference,
+ },
+ ],
+}
+fs.writeFileSync(target, JSON.stringify(body), { mode: 0o600 })
+NODE
+}
+
+write_host_telemetry_body "$VALID_BODY" '' 'full'
+write_host_telemetry_body "$MISSING_UID_BODY" '-missing-uid' 'missing-uid'
+write_host_telemetry_body "$UNKNOWN_KEY_BODY" '-unknown-key' 'unknown-key'
+
+node - "$LEGACY_STATUS_REF_BODY" "$HOST_NAMESPACE" "$HOST_NAME" "$HOST_GENERATION" \
+ "$REQUEST_STARTED_AT_MS" <<'NODE'
+const fs = require('node:fs')
+const [target, namespace, name, generation, startedAt] = process.argv.slice(2)
+// The pre-#694 sourceStatusRef, without the `:uid=` suffix. It needs no
+// durable intent: the reference never parses, so the binding is refused first.
+const body = {
+ events: [
+ {
+ kind: 'linked_outcome',
+ sourceEventId: `e2e-governed-tracing-operations-${startedAt}-legacy-status-ref`,
+ occurredAt: new Date().toISOString(),
+ reasonCode: 'e2e_legacy_status_ref',
+ sourceStatusRef: `host:${namespace}/${name}:generation=${generation}`,
+ payload: { resource_class: 'Host', status: 'succeeded' },
},
],
}
@@ -183,16 +253,49 @@ HCC_TOKEN="$(sign_internal_control_jwt hcc)"
[[ -n "$HCC_TOKEN" ]] || die 'could not mint the HCC InternalControl JWT'
write_auth_config "$HCC_TOKEN"
unset HCC_TOKEN
-STATUS="$(post_json "$CONTROL_API_URL/api/v1/internal/tracing/infrastructure-telemetry-events" "$VALID_BODY")"
+TELEMETRY_URL="$CONTROL_API_URL/api/v1/internal/tracing/infrastructure-telemetry-events"
+STATUS="$(post_json "$TELEMETRY_URL" "$VALID_BODY")"
[[ "$STATUS" == '200' ]] || die "valid tracing request returned HTTP $STATUS instead of 200"
-assert_valid_ingestion_response
+assert_ingestion_counts 1 0
[[ "$(read_body_limit_count)" == "$COUNT_AFTER" ]] || \
die 'valid tracing unexpectedly changed the body-limit error count'
log "valid tracing ingestion succeeded immediately after the rejected request"
+# A 200 alone would also come back if the row were stored under some other
+# identity. Resending the identical event proves the stored identity is the one
+# the uid-bearing reference produces: the server recognises it as a replay.
+STATUS="$(post_json "$TELEMETRY_URL" "$VALID_BODY")"
+[[ "$STATUS" == '200' ]] || die "replayed tracing request returned HTTP $STATUS instead of 200"
+assert_ingestion_counts 0 1
+log 'resending the identical event was recorded as a replay, not a second row'
+
+STATUS="$(post_json "$TELEMETRY_URL" "$MISSING_UID_BODY")"
+[[ "$STATUS" == '400' ]] || die "hostLookupReference without uid returned HTTP $STATUS instead of 400"
+assert_rejection_code invalid_tracing_input
+log 'hostLookupReference without uid was refused as invalid_tracing_input'
+
+STATUS="$(post_json "$TELEMETRY_URL" "$UNKNOWN_KEY_BODY")"
+[[ "$STATUS" == '400' ]] || \
+ die "hostLookupReference with an unknown key returned HTTP $STATUS instead of 400"
+assert_rejection_code invalid_tracing_input
+log 'hostLookupReference with an unknown key was refused as invalid_tracing_input'
+
+# The administrative route refuses an unparseable reference with 403
+# `tracing_binding_unavailable`, which HCC retries rather than dropping: that is
+# what makes the control-api-first rollout order safe (#694).
+STATUS="$(
+ post_json "$CONTROL_API_URL/api/v1/internal/tracing/administrative-events" \
+ "$LEGACY_STATUS_REF_BODY"
+)"
+[[ "$STATUS" == '403' ]] || \
+ die "sourceStatusRef without :uid= returned HTTP $STATUS instead of 403"
+assert_rejection_message 'trusted operation binding is unavailable'
+log 'administrative outcome with the pre-uid sourceStatusRef was refused with 403'
+
# The browser receives only the non-sensitive count and timestamp. Delete the
# authenticated-request artifacts and launch Playwright with a minimal env.
-rm -f "$AUTH_CONFIG" "$OVERSIZED_BODY" "$VALID_BODY" "$RESPONSE_BODY"
+rm -f "$AUTH_CONFIG" "$OVERSIZED_BODY" "$VALID_BODY" "$MISSING_UID_BODY" \
+ "$UNKNOWN_KEY_BODY" "$LEGACY_STATUS_REF_BODY" "$RESPONSE_BODY"
log 'launching the focused Control UI operator journey'
(
@@ -217,4 +320,4 @@ if (stats.expected !== 1 || stats.skipped !== 0 || stats.unexpected !== 0) {
}
NODE
-log 'PASS: 413, existing metric, valid ingestion, admin snapshot, and Control UI agree'
+log 'PASS: 413, metric, uid-bound ingestion, replay, both reference rejections, the administrative 403, and the Control UI agree'