Repository navigation
feat: Add support for the web.cors.origin flag in alertmanager - #8933
Merged
simonpasquier merged 5 commits intoNov 6, 2026
Merged
Conversation
Alertmanager v0.34.2 (prometheus/alertmanager#5664) disables CORS by default and adds the --web.cors.origin flag so browser clients from matching origins can call the API. Expose it via the new spec.web.corsOrigin field, gated on Alertmanager >= v0.34.2 and validated with MinLength=1. Signed-off-by: dongjiang1989 <[email protected]>
web.cors.origin flag in alertmanager
| } | ||
|
|
||
| if version.GTE(semver.MustParse("0.34.2")) && web != nil && web.CORSOrigin != nil { | ||
| amArgs = append(amArgs, monitoringv1.Argument{Name: "web.cors.origin", Value: *web.CORSOrigin}) |
Contributor
There was a problem hiding this comment.
ideally we should validate the value like in https://github.com/prometheus/alertmanager/blob/47403693800ba753b79f61c0fbca5e7d1d74281c/api/api.go#L324-L327
Member
Author
There was a problem hiding this comment.
Thanks @simonpasquier
Add CEL rules and e2e case
Mirror the Alertmanager validation which compiles the value as the fully anchored '^(?:<origin>)$' regular expression. An invalid regex makes the CEL matches() call fail, so the API server rejects the object.
Signed-off-by: dongjiang1989 <[email protected]>
Member
Author
|
cc @simonpasquier @slashpai Please recheck it,thx |
simonpasquier
approved these changes
Nov 6, 2026
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.
Description
Alertmanager v0.34.2 disables CORS by default and adds the
--web.cors.originflag (prometheus/alertmanager#5664) so browser clients from matching origins can call the API.This exposes the flag via a new
spec.web.corsOriginfield on the Alertmanager CRD, gated on Alertmanager >= v0.34.2 and validated withMinLength=1.Type of change
CHANGE(fix or feature that would cause existing functionality to not work as expected)FEATURE(non-breaking change which adds functionality)BUGFIX(non-breaking change which fixes an issue)ENHANCEMENT(non-breaking change which improves existing functionality)NONE(if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)Verification
pkg/alertmanager/statefulset_test.go(TestMakeStatefulSetSpecWebCORSOrigin): arg is set for v0.34.2+, ignored for older versions, absent when unset.go vet,gofmt,make generate,make test-unitpass locally; CRDs, bundle and docs regenerated.Changelog entry