Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ingester: allow only POST method on /ingester/shutdown #7707

Conversation

kevinmingtarja
Copy link
Contributor

@kevinmingtarja kevinmingtarja commented Mar 23, 2024

What this PR does

Previously, we allow both POST and GET /ingester/shutdown, which makes it too easy to accidentally trigger, i.e. internal scanners that traverse links can trigger shutdown of ingester just by visiting the link.

This PR makes that less likely to happen by only allowing POST requests on /ingester/shutdown. At the same time, if users still want to opt in to the existing behavior, we allow that by adding a new -ingester.get-request-for-shutdown-enabled flag (defaults to false). But this flag is also temporary and will be removed after two Mimir releases (2.15).

Which issue(s) this PR fixes or relates to

Fixes #7623

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

@kevinmingtarja kevinmingtarja requested review from jdbaldry and a team as code owners March 23, 2024 20:43
@CLAassistant
Copy link

CLAassistant commented Mar 23, 2024

CLA assistant check
All committers have signed the CLA.

@kevinmingtarja kevinmingtarja force-pushed the kevinmingtarja/allow-only-post-for-ingester-shutdown branch from 20bcfa5 to 26ea0af Compare March 23, 2024 20:44
Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

There are a few tools and docs that will need updating to use POST:

https://github.com/grafana/mimir/blob/main/tools/migrate-ingester-statefulsets.sh#L46

https://github.com/grafana/mimir/blob/main/docs/sources/mimir/manage/run-production-environment/scaling-out.md?plain=1 (where it says invoke it should probably say POST).

https://github.com/grafana/mimir/blob/main/docs/sources/mimir/references/http-api/index.md?plain=1#L51 (and L412)

It would also be good to see a test to make sure GET is disabled unless the config flag is set.

Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thank you for working on this!

@kevinmingtarja
Copy link
Contributor Author

Hi @jhesketh, @pstibrany, thank you as well for the comments!

I have updated the docs/tools that I missed, and addressed the comments in a follow-up commit. Please let me know if this is okay.

Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thank you very much for working on this! I've left few minor comments.

Copy link
Member

@jdbaldry jdbaldry left a comment

Choose a reason for hiding this comment

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

docs changes LGTM

@kevinmingtarja kevinmingtarja requested a review from pstibrany April 4, 2024 12:20
Signed-off-by: Kevin Mingtarja <[email protected]>
Signed-off-by: Kevin Mingtarja <[email protected]>
Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thank you very much!

Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

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

Thank you for the improvements!

Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

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

I think this will fix the unit test

Fix missing [deprecated] tag
@jhesketh jhesketh enabled auto-merge (squash) April 5, 2024 02:57
@jhesketh jhesketh disabled auto-merge April 5, 2024 03:50
Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

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

.

pkg/api/api.go Outdated
@@ -71,6 +74,7 @@ type Config struct {
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&cfg.SkipLabelNameValidationHeader, "api.skip-label-name-validation-header-enabled", false, "Allows to skip label name validation via X-Mimir-SkipLabelNameValidation header on the http write path. Use with caution as it breaks PromQL. Allowing this for external clients allows any client to send invalid label names. After enabling it, requests with a specific HTTP header set to true will not have label names validated.")
f.BoolVar(&cfg.EnableOtelMetadataStorage, "distributor.enable-otlp-metadata-storage", true, "If true, store metadata when ingesting metrics via OTLP. This makes metric descriptions and types available for metrics ingested via OTLP.")
f.BoolVar(&cfg.GETRequestForIngesterShutdownEnabled, "get-request-for-ingester-shutdown-enabled", false, "Enable GET requests to the /ingester/shutdown endpoint to trigger an ingester shutdown. This is a potentially dangerous operation and should only be enabled consciously.")
Copy link
Contributor

Choose a reason for hiding this comment

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

On re-review, this should probably be:

Suggested change
f.BoolVar(&cfg.GETRequestForIngesterShutdownEnabled, "get-request-for-ingester-shutdown-enabled", false, "Enable GET requests to the /ingester/shutdown endpoint to trigger an ingester shutdown. This is a potentially dangerous operation and should only be enabled consciously.")
f.BoolVar(&cfg.GETRequestForIngesterShutdownEnabled, "ingester.get-request-for-shutdown-enabled", false, "Enable GET requests to the /ingester/shutdown endpoint to trigger an ingester shutdown. This is a potentially dangerous operation and should only be enabled consciously.")

And the corresponding changes to the docs.

Copy link
Contributor Author

@kevinmingtarja kevinmingtarja Apr 5, 2024

Choose a reason for hiding this comment

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

Got it, should the yaml field name stay the same though?

Right now it's get_request_for_ingester_shutdown_enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, initially I did as you suggested, but then Peter suggested to make it consistent so I changed it: #7707 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right, I missed that conversation sorry. Looking at the distributor.enable-otlp-metadata-storage flag (just above) it exists as both distributor.enable-otlp-metadata-storage as the flag and enable_otel_metadata_translation as the yaml. @pstibrany Just want to double check your opinion here please.

Copy link
Member

@pstibrany pstibrany Apr 5, 2024

Choose a reason for hiding this comment

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

I'm sorry for confusion here. The problem here comes from the fact that config option is defined in api config block in YAML, but we're trying to use ingester. prefix for CLI flag. At the same time, we're triyng to make CLI flag and yaml field name consistent (this was goal of my previous comment, without realizing it's causing more confusion).

I think we should settle on:

  • -api.get-request-for-ingester-shutdown-enabled for CLI flag
  • get_request_for_ingester_shutdown_enabled as YAML field name (it's already under api section)

WDYT?

If we want to use -ingester. prefix for CLI flag, then we should put this into ingester config struct.

Unfortunately I think enable_otel_metadata_translation was a mistake, as it doesn't follow our practices. ("enabled" suffix, consistent CLI and YAML names)

Copy link
Member

@pstibrany pstibrany Apr 5, 2024

Choose a reason for hiding this comment

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

@jhesketh thanks for catching this. My suggestion was not to remove -ingester. prefix (only to add ingester in the middle of the name), and I missed that this is what happened. 🤦

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry for the misunderstanding too. So should we keep going with the -ingester. prefix or -api. instead? As you mentioned, I think the latter makes more sense as it's already under the api section in the yaml.

Copy link
Member

Choose a reason for hiding this comment

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

Hi Kevin, with Josh we agreed to go with -api.get-request-for-ingester-shutdown-enabled CLI flag and get_request_for_ingester_shutdown_enabled YAML field name. Thank you very much for your patience with us!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Peter, no worries! Let me quickly do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@kevinmingtarja kevinmingtarja requested a review from jhesketh April 11, 2024 14:21
Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for persisting with our miss on the naming :-). Will leave it for Peter to do final look+merge.

@kevinmingtarja
Copy link
Contributor Author

Hang on did i miss something, somehow one of the test fails with this, even though (default false) is there in help-all.txt.tmpl.

Diff:
            	            	--- Expected
            	            	+++ Actual
            	            	@@ -282,3 +282,3 @@
            	            	   -api.get-request-for-ingester-shutdown-enabled
            	            	-    	[deprecated] Enable GET requests to the /ingester/shutdown endpoint to trigger an ingester shutdown. This is a potentially dangerous operation and should only be enabled consciously. (default false)
            	            	+    	[deprecated] Enable GET requests to the /ingester/shutdown endpoint to trigger an ingester shutdown. This is a potentially dangerous operation and should only be enabled consciously.
            	            	   -api.skip-label-name-validation-header-enabled
            	Test:       	TestHelp/all
            	Messages:   	./cmd/mimir/mimir -help-all output changed; try `make reference-help`

Signed-off-by: Peter Štibraný <[email protected]>
Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution and patience with us!

@pstibrany
Copy link
Member

pstibrany commented Apr 12, 2024

Hang on did i miss something, somehow one of the test fails with this, even though (default false) is there in help-all.txt.tmpl.

I've regenerated help (using make reference-help) and pushed that change to resolve this problem.

@pstibrany pstibrany enabled auto-merge (squash) April 12, 2024 07:30
@pstibrany pstibrany merged commit d484152 into grafana:main Apr 12, 2024
29 checks passed
@kevinmingtarja kevinmingtarja deleted the kevinmingtarja/allow-only-post-for-ingester-shutdown branch April 13, 2024 03:59
@kevinmingtarja
Copy link
Contributor Author

No worries, thanks as well for the review Peter and Joshua!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make /ingester/shutdown react on POST method only
5 participants