Skip to content

feat: Add support for the web.cors.origin flag in alertmanager - #8933

Merged
simonpasquier merged 5 commits into
prometheus-operator:mainfrom
kubeservice-stack:up-am-cors
Nov 6, 2026
Merged

simonpasquier merged 5 commits into
prometheus-operator:mainfrom
kubeservice-stack:up-am-cors

Conversation

@dongjiang1989

Copy link
Copy Markdown
Member

Description

Alertmanager v0.34.2 disables CORS by default and adds the --web.cors.origin flag (prometheus/alertmanager#5664) so browser clients from matching origins can call the API.

This exposes the flag via a new spec.web.corsOrigin field on the Alertmanager CRD, gated on Alertmanager >= v0.34.2 and validated with MinLength=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

  • Unit tests added in 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-unit pass locally; CRDs, bundle and docs regenerated.

Changelog entry

Add `spec.web.corsOrigin` field to the Alertmanager CRD to set the `--web.cors.origin` flag (requires Alertmanager >= v0.34.2).

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]>
@dongjiang1989
dongjiang1989 requested a review from a team as a code owner November 2, 2026 04:15
@dongjiang1989 dongjiang1989 changed the title [pkg/alertmanager] Add support for the web.cors.origin flag feat: Add support for the web.cors.origin flag in alertmanager Nov 2, 2026
}

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})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dongjiang1989 dongjiang1989 Nov 4, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @simonpasquier
Add CEL rules and e2e case

@pull-request-size pull-request-size Bot added size/L and removed size/M labels Nov 2, 2026
@pull-request-size pull-request-size Bot added size/M and removed size/L labels Nov 2, 2026
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]>
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Nov 4, 2026
@dongjiang1989

dongjiang1989 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member Author

cc @simonpasquier @slashpai Please recheck it,thx

@simonpasquier
simonpasquier merged commit 2110bfd into prometheus-operator:main Nov 6, 2026
23 checks passed
@dongjiang1989
dongjiang1989 deleted the up-am-cors branch November 6, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants