receive: validate remote write v2 symbol references - #8976
Open
r0h1tb wants to merge 3 commits into
Open
Conversation
translateV2ToV1 resolved label references by indexing the request's symbols table directly. Both the references and the table come from the remote write client, so a payload whose labels_refs point past the end of symbols panics the request goroutine with an index out of range. Prometheus enforces two invariants when desymbolizing (labels_refs must have an even length, and every reference must address the table) and returns an error for either. The v2 to v1 translation reimplemented that lookup without them. Reject both as bad requests instead of indexing blindly, and cover the translation, which had no unit test. Signed-off-by: Rohit Behera <126186063+r0h1tb@users.noreply.github.com>
Signed-off-by: Rohit Behera <126186063+r0h1tb@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8976 +/- ##
==========================================
- Coverage 64.54% 63.39% -1.16%
==========================================
Files 289 289
Lines 37359 46004 +8645
==========================================
+ Hits 24115 29166 +5051
- Misses 11151 14740 +3589
- Partials 2093 2098 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The snippet embeds pkg/receive/handler.go by line number and the symbol validation added earlier in this PR shifted writeQuorum down, so make docs regenerated the block with tryWrite instead. Signed-off-by: Rohit Behera <126186063+r0h1tb@users.noreply.github.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.
Changes
translateV2ToV1resolves remote write v2 label references by indexing the request'ssymbols table directly:
Both the references and the table come from the client, so a payload whose
labels_refspoint past the end ofsymbolspanics the request goroutine with anindex out of range. Same pattern for exemplar refs.
handleV2HTTPunmarshals andcalls the translation with no validation in between, so any v2 client can trigger it.
net/httprecovers the panic per connection, so the process survives, but therequest is dropped and a stack trace is logged.
Prometheus enforces two invariants when desymbolizing and returns an error for
either —
labels_refsmust have even length, and every reference must address thetable (
prompb/io/prometheus/write/v2.desymbolizeLabels). The v2 to v1 translationreimplemented that lookup without them.
desymbolizeLabelswith both checks and use it for series and exemplar labels.translateV2ToV1returns an error;handleV2HTTPmaps it to 400.Odd-length
labels_refspreviously dropped the trailing element silently; it is nowa 400, matching Prometheus.
Verification
Without the fix, a ref past the end panics:
translateV2ToV1had no unit test, which is why this went unnoticed; the new filecovers the happy path and four malformed-reference cases.
go test -tags slicelabels -race ./pkg/receive/passes and matches the baseline(
ok, 166s).golangci-lint run --build-tags=slicelabels ./pkg/receive/...reportsnothing for the changed or added files; the package's existing goconst findings are
unchanged.