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

[stats] fix error when requesting extended stats by unauth users #160520

Merged

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Jun 26, 2023

Summary

Fix #160385

Use the internal client instead of the scoped one for the extended stats ES requests to avoid an error with unauthenticated users (when anonymous access is allowed)

@pgayvallet pgayvallet added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes v8.10.0 labels Jun 26, 2023
if (isExtended) {
const core = await context.core;
const { asCurrentUser } = core.elasticsearch.client;
const { asInternalUser } = core.elasticsearch.client;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual change: using the internal client and not the scoped one, as using the scoped client when no user is authenticated returns 401/403 error from ES.

@pgayvallet pgayvallet marked this pull request as ready for review June 26, 2023 17:38
@pgayvallet pgayvallet requested review from a team as code owners June 26, 2023 17:38
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

Comment on lines +33 to +35
it('should return 200 for extended', async () => {
const { body } = await supertestNoAuth.get('/api/stats').expect(200);
expect(isUUID(body.kibana.uuid)).to.be.ok();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote a new FTR suite before discovering that there was one already (fun fact, the 401 caused by the ES client for extended stats was a "feature" not a bug). Given they don't test exactly the same things, I kept mine after discovering this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

The behavior is different and easy to miss. ++ to adding the new API integration test

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +33 to +35
it('should return 200 for extended', async () => {
const { body } = await supertestNoAuth.get('/api/stats').expect(200);
expect(isUUID(body.kibana.uuid)).to.be.ok();
Copy link
Contributor

Choose a reason for hiding this comment

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

The behavior is different and easy to miss. ++ to adding the new API integration test

@pgayvallet
Copy link
Contributor Author

@elasticmachine merge upstream

@pgayvallet pgayvallet enabled auto-merge (squash) June 27, 2023 07:54
@pgayvallet pgayvallet merged commit 7fb8f6b into elastic:main Jun 27, 2023
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #24 / cloud_security_posture GET internal/cloud_security_posture/rules/_find Should return 200 status code and paginate rules with a limit of PerPage

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 14 16 +2
securitySolution 413 417 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 15 17 +2
securitySolution 492 496 +4
total +6

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[usageCollection] /api/stats endpoint throw errors for unauth users when asking for extended stats
6 participants