Repository navigation
[FIXED] Accept {{left}} and {{right}} mapping functions in ValidateMapping - #8568
Conversation
The subject transform has supported the left and right mapping functions since 2.10.16 (nats-io#5337), but the allowlist in ValidateMapping was never updated, so it rejects them with "unknown function". That makes them unusable on the path they were added for: a config file with an account mapping using {{right(1,2)}} fails to load and the server refuses to start, and a stream subject_transform is rejected with error 10156. The same destination is accepted by RePublish and by "nats server mapping", which call NewSubjectTransform directly. Add the two regexes to the allowlist, the same way random was added in nats-io#6950. As an alternative, the allowlist could be dropped altogether: ValidateMapping has ended with a NewSubjectTransform call since nats-io#5617, and the parser already returns ErrUnknownMappingDestinationFunction for an unknown function. Happy to do that instead if you prefer it. Signed-off-by: Madan Kumar <[email protected]>
|
@claude, brief review. |
|
Claude finished @MauriceVanVeen's task in 59s —— View job Brief Review
Fix is correct and minimal. The two regexes ( Test coverage is solid:
One minor note: the whitespace test The alternative the author raised (dropping the allowlist entirely since Overall: looks good to merge. |
|
Thanks @MauriceVanVeen! |
Problem
The
leftandrightmapping functions were added to the subject transform in #5337 and announced in the 2.10.16 release notes, but the allowlist inValidateMapping(server/sublist.go) was never updated. It still lists the other eight functions, so a destination using{{left(...)}}or{{right(...)}}is rejected withinvalid mapping destination: unknown function.That blocks them on the path they were added for. #5337's own description uses account-mapping config syntax (
foo.*: foo.{{Right(1,2)}}), and that config does not load:The server refuses to start. The same applies to
Account.AddMappingand to a streamsubject_transform, mirror or source transform, which fail withJSStreamTransformInvalidDestinationError(10156).Meanwhile
RePublishandnats server mappingcallNewSubjectTransformdirectly and accept the very same destination, and the transform itself works correctly (foo.1234->bar.34). So the function is implemented and shipped, just not reachable from config.Change
Add the two regexes to the allowlist, the same way
randomwas added in #6950 andsplit/slicein #3305. Two lines.Tests: the
left/rightcases inTestValidateDestinationSubject(I also addedslice,splitandrandomthere, which were untested), andTestAccountLeftRightMapping, which loads a config with both functions and checks the mapped subjects arrive asbar.34andqux.123. Both fail on main.One alternative worth mentioning: the allowlist looks redundant now. Since #5617
ValidateMappingends with aNewSubjectTransformcall, andindexPlaceHoldersalready returnsErrUnknownMappingDestinationFunctionfor an unknown function, so removing the eight regexes would give the same errors from a single source of truth and this class of drift could not happen again. I went with the smaller change to match precedent, but happy to switch if you prefer that.Not addressed here: left/right mappings pushed through JWT claims currently disappear silently because
AddWeightedMappings' error is discarded (#8468 / #8473). That is a separate defect.