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

Change server information endpoint / to only accept GET and HEAD requests #15976

Merged
merged 12 commits into from
Mar 5, 2025

Conversation

carsonip
Copy link
Member

@carsonip carsonip commented Mar 3, 2025

Motivation/summary

Breaking change to change server information endpoint / to only accept GET and HEAD requests, and return 405 Method Not Allowed otherwise. This will surface any agent misconfiguration, e.g. configuring otlphttp to send to / instead of /v1/traces.

Checklist

For functional changes, consider:

  • Is it observable through the addition of either logging or metrics?
  • Is its use being published in telemetry to enable product improvement?
  • Have system tests been added to avoid regression?

How to test these changes

curl -XGET -v http://apm-server/
curl -XHEAD -v http://apm-server/
curl -XPOST -v http://apm-server/

Confirm that GET and HEAD requests return 200, POST requests return 405.

Related issues

Fixes #15965

Copy link
Contributor

github-actions bot commented Mar 3, 2025

Warning

It looks like this PR modifies one or more .asciidoc files. These files are being migrated to Markdown, and any changes merged now will be lost. See the migration guide for details.

Copy link
Contributor

mergify bot commented Mar 3, 2025

This pull request does not have a backport label. Could you fix it @carsonip? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-7.17 is the label to automatically backport to the 7.17 branch.
  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit.
  • backport-9./d is the label to automatically backport to the 9./d branch. /d is the digit.
  • backport-8.x is the label to automatically backport to the 8.x branch.
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@carsonip carsonip added the backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches label Mar 3, 2025
@carsonip carsonip changed the title Change route / to only accept GET and HEAD method Change health check endpoint / to only accept GET and HEAD method Mar 3, 2025
Copy link
Contributor

github-actions bot commented Mar 3, 2025

Warning

It looks like this PR modifies one or more .asciidoc files. These files are being migrated to Markdown, and any changes merged now will be lost. See the migration guide for details.

c.Result.SetWithError(
request.IDResponseErrorsMethodNotAllowed,
// include a verbose error message to alert users about a common misconfiguration
errors.New("this is the health check endpoint; did you mean to send data to another endpoint instead?"),
Copy link
Member Author

Choose a reason for hiding this comment

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

[to reviewer] lmk if this is too verbose, I can revert the commit.

$ curl -XPOST -v localhost:8200/
* Host localhost:8200 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8200...
* connect to ::1 port 8200 from ::1 port 49848 failed: Connection refused
*   Trying 127.0.0.1:8200...
* Connected to localhost (127.0.0.1) port 8200
> POST / HTTP/1.1
> Host: localhost:8200
> User-Agent: curl/8.5.0
> Accept: */*
> 
< HTTP/1.1 405 Method Not Allowed
< Content-Type: application/json
< X-Content-Type-Options: nosniff
< Date: Mon, 03 Mar 2025 16:35:38 GMT
< Content-Length: 129
< 
{
  "error": "method not supported: this is the health check endpoint; did you mean to send data to another endpoint instead?"
}
* Connection #0 to host localhost left intact

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine.

Copy link
Contributor

github-actions bot commented Mar 3, 2025

Warning

It looks like this PR modifies one or more .asciidoc files. These files are being migrated to Markdown, and any changes merged now will be lost. See the migration guide for details.

Copy link
Contributor

github-actions bot commented Mar 3, 2025

Warning

It looks like this PR modifies one or more .asciidoc files. These files are being migrated to Markdown, and any changes merged now will be lost. See the migration guide for details.

@@ -15,11 +15,3 @@ get:
responses:
'200':
$ref: '../components/responses/200_server_info.yaml'
post:
Copy link
Member Author

Choose a reason for hiding this comment

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

[to reviewer] other than openapi spec, we'll also need to remove it from obs docs in a separate PR: https://www.elastic.co/guide/en/observability/current/apm-api-info.html

Copy link
Member

Choose a reason for hiding this comment

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

Why would you remove it? I would add a disclaimer that the / endpoint is to be used fr healthcheck or test only, but I think the use case of POST with credentials (to verify credentials) is a nice one to give our user guidance on. I would definitely clarify its purpose though.

Copy link
Member Author

Choose a reason for hiding this comment

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

the intention of this very PR is to remove the "functionality" to POST to /. As such, we are removing the corresponding part in the docs. If we don't remove it in the docs, we'll be left with docs that reference an endpoint that doesn't work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the use case of POST with credentials (to verify credentials) is a nice one to give our user guidance on

I agree that we should update the docs to state that we can optionally provide credentials on the GET request to get additional info about the server. But I'm not sure if OpenAPI spec supports that.

@carsonip carsonip changed the title Change health check endpoint / to only accept GET and HEAD method Change server information endpoint / to only accept GET and HEAD method Mar 3, 2025
@carsonip carsonip changed the title Change server information endpoint / to only accept GET and HEAD method Change server information endpoint / to only accept GET and HEAD requests Mar 3, 2025
@carsonip carsonip requested a review from simitt March 3, 2025 16:50
@carsonip carsonip marked this pull request as ready for review March 3, 2025 16:50
@carsonip carsonip requested a review from a team as a code owner March 3, 2025 16:50
Copy link
Contributor

github-actions bot commented Mar 3, 2025

Warning

It looks like this PR modifies one or more .asciidoc files. These files are being migrated to Markdown, and any changes merged now will be lost. See the migration guide for details.

1pkg
1pkg previously approved these changes Mar 4, 2025
endorama
endorama previously approved these changes Mar 4, 2025
Copy link
Member

@endorama endorama left a comment

Choose a reason for hiding this comment

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

Overall good to me, thanks Carson!

@carsonip carsonip dismissed stale reviews from endorama and 1pkg via 9a50ac8 March 4, 2025 12:52
kruskall
kruskall previously approved these changes Mar 4, 2025
simitt
simitt previously approved these changes Mar 5, 2025
@carsonip carsonip dismissed stale reviews from simitt and kruskall via 9a55507 March 5, 2025 13:47
@carsonip carsonip requested a review from simitt March 5, 2025 13:47
@carsonip carsonip enabled auto-merge (squash) March 5, 2025 13:58
@carsonip carsonip merged commit 2aaa73a into elastic:main Mar 5, 2025
14 checks passed
mergify bot pushed a commit that referenced this pull request Mar 5, 2025
…quests (#15976)

Breaking change to change server information endpoint / to only accept GET and HEAD requests, and return 405 Method Not Allowed otherwise. This will surface any agent misconfiguration, e.g. configuring otlphttp to send to / instead of /v1/traces.

(cherry picked from commit 2aaa73a)
mergify bot added a commit that referenced this pull request Mar 5, 2025
…quests (#15976) (#16016)

Breaking change to change server information endpoint / to only accept GET and HEAD requests, and return 405 Method Not Allowed otherwise. This will surface any agent misconfiguration, e.g. configuring otlphttp to send to / instead of /v1/traces.

(cherry picked from commit 2aaa73a)

Co-authored-by: Carson Ip <carsonip@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches test-plan v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return an error on POST requests to /
6 participants