fix: prevent panic on invalid regex in reload annotation#1193
Open
nikolauspschuetz wants to merge 1 commit into
Open
fix: prevent panic on invalid regex in reload annotation#1193nikolauspschuetz wants to merge 1 commit into
nikolauspschuetz wants to merge 1 commit into
Conversation
ShouldReload compiled each comma-separated value of a named reload annotation (e.g. secret.reloader.stakater.com/reload) with regexp.MustCompile, which panics on an invalid pattern. The value comes straight from a user-set annotation on a watched workload, and the queue worker has no recover(), so a single malformed annotation (e.g. "app-config[") on any workload in any watched namespace crashes Reloader and stops reloads cluster-wide. Use regexp.Compile and, on error, log and skip that pattern instead of panicking.
1 task
nikolauspschuetz
marked this pull request as ready for review
July 22, 2026 21:40
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.
Problem
ShouldReloadcompiles each comma-separated value of a named reload annotation withregexp.MustCompile:The value comes directly from a user-set annotation on a watched workload (e.g.
secret.reloader.stakater.com/reload/configmap.reloader.stakater.com/reload, which support regex).regexp.MustCompilepanics on an invalid pattern, and the queue worker (wait.Until(c.runWorker, …)) has norecover(). So a single malformed annotation on any workload in any watched namespace — e.g.:crashes the Reloader process and stops reloads cluster-wide — a low-privilege, cross-namespace availability issue.
Fix
Use
regexp.Compileand, on error, log and skip that pattern instead of panicking. Valid patterns behave exactly as before; an invalid one is logged and simply doesn't match.Test
Added
TestShouldReload_InvalidRegexAnnotation_DoesNotPanicinpkg/common/common_test.go. It panics before this change and passes after (verified withgo test ./pkg/common/...).