fix(security): tenant ID validation + self-instrumentation guard#64
Merged
Conversation
Closes two production-readiness gaps from the brainstorm: 1. Tenant ID validation. SanitizeTenantID rejects empty / over-128-char / control-character values, applied at every transport boundary: - HTTP X-Tenant-ID header (api/tenant_middleware.go) - gRPC x-tenant-id metadata (ingest/otlp.go) - OTLP resource attribute tenant.id (ingest/otlp.go, trusted-resource path) Without this, a tenant ID of "foo\nbar" would inject a newline into slog structured fields, and 8KB tenant IDs would silently truncate at the GORM VARCHAR(64) layer. 2. Self-instrumentation feedback loop guard. When OTEL_EXPORTER_OTLP_ENDPOINT resolves to a loopback host (the binary's own gRPC port), the OTel SDK would otherwise emit a span on every Export call, re-entering Export and amplifying without bound. Config.GuardSelfInstrumentation auto-prepends the own service name to IngestExcludedServices and warns the operator. Both fixes are non-breaking — sanitization rejects only inputs that were never valid, and the guard only fires on loopback endpoints. Tests: 26 new test cases across config / storage / api packages covering the happy path, every rejection branch, and idempotency on re-runs. go test ./... → 438 passed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
PR B of 6 from the production-readiness brainstorm.
Tenant ID validation — `storage.SanitizeTenantID` rejects empty / >128-char / control-character values, applied at every transport boundary:
Closes the log-injection / VARCHAR-truncation vector identified by codex round 1.
Self-instrumentation feedback loop guard — when `OTEL_EXPORTER_OTLP_ENDPOINT` resolves to a loopback host, `Config.GuardSelfInstrumentation` auto-prepends the own service name (`config.SelfServiceName`) to `IngestExcludedServices` so SDK-emitted spans don't re-enter Export. Closes codex round 2 finding F.
Both fixes are non-breaking — rejection only catches inputs that were never valid, and the guard only fires on loopback endpoints.
Test plan
🤖 Generated with Claude Code