-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Telemetry] Check permissions when requesting telemetry #126238
Conversation
@@ -126,11 +126,10 @@ export class TelemetryCollectionManagerPlugin | |||
const esClient = this.getElasticsearchClient(config); | |||
const soClient = this.getSavedObjectsClient(config); | |||
// Provide the kibanaRequest so opted-in plugins can scope their custom clients only if the request is not encrypted | |||
const kibanaRequest = config.unencrypted ? config.request : void 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main reason for allowing admin only to retrieve the sampled data. There's no longer a need to scope the requests. It may also help us with #84183 because kibanaRequest
won't be needed in the context anymore.
return config.unencrypted | ||
? this.elasticsearchClient?.asScoped(config.request).asCurrentUser | ||
: this.elasticsearchClient?.asInternalUser; | ||
return this.elasticsearchClient?.asInternalUser; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can now rely on the internal user only 🎉
constructor( | ||
log: Logger, | ||
// Needed because it doesn't affect on anything here but being explicit creates a lot of pain down the line | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing any
s 🥳
@@ -9,7 +9,7 @@ import { merge } from 'lodash'; | |||
import { loggingSystemMock } from 'src/core/server/mocks'; | |||
import { | |||
Collector, | |||
createCollectorFetchContextWithKibanaMock, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the collector and they don't require the KibanaRequest mock.
security
dependency@@ -24,6 +24,7 @@ | |||
{ "path": "../navigation/tsconfig.json" }, | |||
{ "path": "../saved_objects_tagging_oss/tsconfig.json" }, | |||
{ "path": "../saved_objects/tsconfig.json" }, | |||
{ "path": "../screenshot_mode/tsconfig.json" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why it failed in this PR. But dashboard
is importing types from screenshot_mode
and it was missing this line.
@elastic/kibana-operations probably a bug in the type_check
script that didn't catch it earlier in main
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not totally sure how TypeScript validates that projects have the references they need, it seems to validate it most of the time but there are edge cases where you can import from another project even when it's not listed in the projects deps. We are on the cusp of moving away from relative plugin imports to imported based on global module IDs for packages which will make this a non-problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a strange situation, but I'm glad we'll be moving away from it in the future. Thanks for adding the project to our tsconfig though!
@@ -47,7 +37,7 @@ export class Welcome extends React.Component<Props> { | |||
} | |||
}; | |||
|
|||
private redirecToAddData() { | |||
private redirectToAddData() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just fixing a typo here 😇
const { hasAllRequested } = await security.authz | ||
.checkPrivilegesWithRequest(req) | ||
.globally({ kibana: 'decryptedTelemetry' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check the serialized privilege string here. I'd suggest adding a comment to clarify this design decision for future maintainers, too 😄
const { hasAllRequested } = await security.authz | |
.checkPrivilegesWithRequest(req) | |
.globally({ kibana: 'decryptedTelemetry' }); | |
// Normally we would use `options: { tags: ['access:decryptedTelemetry'] }` in the route definition to check authorization for an | |
// API action, however, we want to check this conditionally based on the `unencrypted` parameter. In this case we need to use the | |
// security API directly to check privileges for this action. Note that the 'decryptedTelemetry' API privilege string is only | |
// granted to users that have "Global All" or "Global Read" privileges in Kibana. | |
const { checkPrivilegesWithRequest, actions } = security.authz; | |
const privileges = { kibana: actions.api.get('decryptedTelemetry') }; | |
const { hasAllRequested } = await checkPrivilegesWithRequest(req).globally(privileges); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works! Thank you! Is there any documentation I could have gone to earlier so I wouldn't bother you with this wrong usage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're welcome!
Here's where we have an example of securing an HTTP route with an API privilege string via an access:
tag: https://www.elastic.co/guide/en/kibana/current/development-security.html#example-2-dev-tools
Unfortunately you couldn't use an access:
tag here.
AFAIK we don't really have any dev docs or TS docs that explain how to use the Security plugin's API to check privileges directly. The only TS docs I could find is this snippet:
/** Actions are used to create the "actions" that are associated with Elasticsearch's | |
* application privileges, and are used to perform the authorization checks implemented | |
* by the various `checkPrivilegesWithRequest` derivatives. | |
*/ |
That's not too helpful 😅
I added an issue for us to add docs for the authorization service: #126355
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TM changes LGTM :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presentation team changes LGTM
@@ -24,6 +24,7 @@ | |||
{ "path": "../navigation/tsconfig.json" }, | |||
{ "path": "../saved_objects_tagging_oss/tsconfig.json" }, | |||
{ "path": "../saved_objects/tsconfig.json" }, | |||
{ "path": "../screenshot_mode/tsconfig.json" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a strange situation, but I'm glad we'll be moving away from it in the future. Thanks for adding the project to our tsconfig though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits and comments, but overall LGTM
src/plugins/home/public/application/components/welcome.test.tsx
Outdated
Show resolved
Hide resolved
src/plugins/home/public/services/welcome/welcome_service.test.ts
Outdated
Show resolved
Hide resolved
src/plugins/telemetry/server/routes/telemetry_usage_stats.test.ts
Outdated
Show resolved
Hide resolved
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VisEditors changes LGTM, code review only
💚 Build SucceededMetrics [docs]Module Count
Public APIs missing comments
Async chunks
Public APIs missing exports
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Infra changes LGTM 👍🏼
…ed-unexpectedly-error * 'main' of github.com:elastic/kibana: (46 commits) Fix copy and pasted renderer user_name test (elastic#126663) [Gauge] Vis editors gauge legacy percent mode. (elastic#126318) Remove all cases related code from timelines (elastic#127003) Hide Enterprise search panel when no nodes are present (elastic#127100) [Lens] Fixed flakiness on runtime fields' appearance on the list (elastic#126945) [Security Solution][Lists] - Add missing privileges callout to exception lists page (elastic#126874) [Security Solution][Lists] - Updates exception flyout edit error messages (elastic#126875) [Security Solution][Rules] - Remove rule selection for read only users (elastic#126827) Fix session cleanup test (elastic#126966) [ftr] implement support for accessing ES through CCS (elastic#126547) [type-summarizer] always use normalized paths, fix windows compat (elastic#127055) Revert "[ci] Configure hourly pipeline for a small spot instance trial (elastic#126824)" Revert "[CI] Expand spot instance trial a bit (elastic#126928)" [Alerting] Adding functional tests for alerting and actions telemetry (elastic#126528) [Telemetry] Check permissions when requesting telemetry (elastic#126238) Don't submit empty seed_urls or sitemap_urls when making a partial crawl request (elastic#126972) Remove License Requirement for Enterprise Search App Search Meta Engines (elastic#127046) [ML] Adding data recognizer module config cache (elastic#126338) skip flaky suite (elastic#126027) [Reporting] Improve error logging for rescheduled jobs (elastic#126737) ... # Conflicts: # x-pack/plugins/reporting/server/core.ts # x-pack/plugins/reporting/server/lib/tasks/execute_report.ts
…re-browser-errors * 'main' of github.com:elastic/kibana: (46 commits) Fix copy and pasted renderer user_name test (elastic#126663) [Gauge] Vis editors gauge legacy percent mode. (elastic#126318) Remove all cases related code from timelines (elastic#127003) Hide Enterprise search panel when no nodes are present (elastic#127100) [Lens] Fixed flakiness on runtime fields' appearance on the list (elastic#126945) [Security Solution][Lists] - Add missing privileges callout to exception lists page (elastic#126874) [Security Solution][Lists] - Updates exception flyout edit error messages (elastic#126875) [Security Solution][Rules] - Remove rule selection for read only users (elastic#126827) Fix session cleanup test (elastic#126966) [ftr] implement support for accessing ES through CCS (elastic#126547) [type-summarizer] always use normalized paths, fix windows compat (elastic#127055) Revert "[ci] Configure hourly pipeline for a small spot instance trial (elastic#126824)" Revert "[CI] Expand spot instance trial a bit (elastic#126928)" [Alerting] Adding functional tests for alerting and actions telemetry (elastic#126528) [Telemetry] Check permissions when requesting telemetry (elastic#126238) Don't submit empty seed_urls or sitemap_urls when making a partial crawl request (elastic#126972) Remove License Requirement for Enterprise Search App Search Meta Engines (elastic#127046) [ML] Adding data recognizer module config cache (elastic#126338) skip flaky suite (elastic#126027) [Reporting] Improve error logging for rescheduled jobs (elastic#126737) ... # Conflicts: # x-pack/plugins/reporting/server/lib/tasks/execute_report.ts
Summary
POST /api/telemetry/v2/clusters/_stats
now checks that the user has the permissionsdecryptedTelemetry
added in #96571 to only allow admins to retrieve telemetry. It returns 403 otherwise.Adding
security
as a dependency totelemetry
created a circular dependency becausehome
relies ontelemetry
to set decide on whether to show the telemetry notice. I moved that logic to the telemetry plugin and registered the "renderer" via a new API exposed by the home plugin.Resolves #96538.
Side wins
As we no longer need to scope the requests, I removed the
kibanaRequest
from thefetch
context. Simplifying a lot the types in theusageCollection
plugin.Resolves #84183.
How to test
Locally
Create a user with a role that has read-only access to all spaces. Then, log in with that user and head to Advanced Settings > Usage Data (at the bottom), and attempt to retrieve the telemetry sample. You'll see it gets a 403.
Cloud
Using the auto-deployed Kibana 🧡
Since Cloud hides the section Advanced Settings > Usage Data, we need to
curl
the deployment to test this feature:200
403
200
Checklist
Delete any items that are not applicable to this PR.
For maintainers