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

[Telemetry] Settings Collector: redact sensitive reported values #88675

Merged
merged 18 commits into from
Jan 27, 2021

Conversation

Bamieh
Copy link
Member

@Bamieh Bamieh commented Jan 19, 2021

The Usage Collector stack_management reports user changed settings.

This PR adds a new config to registered UI settings sensitive: boolean. The value of any UI setting marked as sensitive will be reported as a keyword [REDACTED] instead of the actual value. This hides the actual sensitive information while giving us some intelligence over which fields the users are interactive with the most.

Changes

Core Features:

  • A new sensitive: true config to the method core.uiSettings.register.

    uiSettings.register({
      [NEWS_FEED_URL_SETTING]: {
        name: i18n.translate('xpack.securitySolution.uiSettings.newsFeedUrl', {
          defaultMessage: 'News feed URL',
        }),
        value: NEWS_FEED_URL_SETTING_DEFAULT,
    
        description: i18n.translate('xpack.securitySolution.uiSettings.newsFeedUrlDescription', {
          defaultMessage: '<p>News feed content will be retrieved from this URL</p>',
        }),
        category: [APP_ID],
        requiresPageReload: true,
        sensitive: true,
        schema: schema.string(),
      },
    }),
    
  • Add isSensitive method to uiSettings plugin contract.

  • Values of UI Settings marked as sensitive will be reported reported as [REDACTED]

Schema updates:

  • UI Settings collector schema is not up to date with all the ui settings we have and it is evergreen!

  • Updated schema Typescript type MakeSchemaFrom to fail when the Usage TS type does not match the schema type property.

    ```
    interface UsageStats {
      someProp: number;
    }
    
    const schema: MakeSchemaFrom<UsageStats> = {
      someProp': { type: 'long' },
    }
    ```	  
    

    Changing long to keyword for example will fail the type check
    (in IDE as well) and not just the telemetry_check.ts.

  • Telemetry checker for UsageStats types now support the syntax Array<T> instead of only supporting T[].

    ```
    interface UsageStats {
      someProp: number[];
      // this is now supported too!
      someProp2: Array<number>;
    }
    ```
    

Tests:

  • Added tests for the ui settings collector function.
  • Add functional tests to make sure all UI Settings are mapped in the schema.
  • Add functional tests to make sure all sensitive UI settings are mapped as keywords. This will help us make sure we dont accidentally report sensitive fields to telemetry since this will trigger a code review from the telemetry team.

Current Sensitive UI Settings:

{
  'timelion:quandl.key'
  'securitySolution:defaultIndex'
  'securitySolution:newsFeedUrl'
  'xpackReporting:customPdfLogo'
  'notifications:banner'
  'timelion:graphite.url'
  'xpackDashboardMode:roles'
}

Got pinged for a codereview?

It is most likely a change adding sensitive: true to one of the registered ui settings your team owns. Please filter by codeowners and check for the changes.

Closes #85811

@Bamieh Bamieh added release_note:skip Skip the PR/issue when compiling release notes Team:KibanaTelemetry v7.12.0 labels Jan 19, 2021
@Bamieh Bamieh requested a review from afharo January 19, 2021 13:45
@Bamieh Bamieh requested a review from a team as a code owner January 19, 2021 13:45
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-telemetry (Team:KibanaTelemetry)

Copy link
Member

@afharo afharo 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 type fixes ❤️

I think this list is a great starting point to unblock the works in the banners. However, I think we discussed an alternative approach during our grooming sessions. Are you planning on a follow-up PR to implement it?

@wylieconlon wylieconlon added v8.0.0 and removed 8.0.0 labels Jan 20, 2021
@Bamieh Bamieh requested a review from a team as a code owner January 26, 2021 10:42
@Bamieh Bamieh requested a review from a team January 26, 2021 10:42
@Bamieh Bamieh requested review from a team as code owners January 26, 2021 10:42
Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

I love the new implementation! Thank you!

Although, I have some concerns about how the tests were implemented (needing to change an existing public API only for test purposes). Can we talk about other options before approving this PR?

path: '/api/kibana/settings',
validate: {
query: schema.object({
_allRegistered: schema.maybe(schema.boolean()),
Copy link
Member

@afharo afharo Jan 26, 2021

Choose a reason for hiding this comment

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

We are exposing this only for test purposes. What do you think about following a similar approach to the Application Usage's functional tests?

  1. A test plugin uses core's public APIs, and calls the existing method uiSettingsClient.getAll() and saves it in the window object.
  2. Then the mocha tests retrieve that property and validate their content.

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 agree exposing an API just for testing might not be ideal. I'm curious if anyone else from the team ( @elastic/kibana-core ) has different ideas.

Using the browser might be ok, even an api in the test plugin that exposes those settings might be even better too. Since api_integration tests dont open the browser and using an API is more reliable.

test/api_integration/apis/telemetry/index.js Outdated Show resolved Hide resolved
Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

LGTM for Kibana app changes, didn't run the code. Makes timelion quandl key sensitive

@Bamieh Bamieh requested a review from afharo January 26, 2021 16:05
Copy link
Member

@afharo afharo 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 this humongous effort!

Just added a couple of Super-NITs 😇

@afharo afharo changed the title [Telemetry] Settings Collector: use a whitelist for reported values [Telemetry] Settings Collector: redact sensitive reported values Jan 26, 2021
Copy link
Contributor

@rylnd rylnd left a comment

Choose a reason for hiding this comment

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

I believe that we need one additional setting to be marked as sensitive in SecSol.

@rylnd
Copy link
Contributor

rylnd commented Jan 26, 2021

@Bamieh in discussing this with the team a potential feature enhancement was mentioned that I wanted to relay here: the ability to only redact sensitive values if they are not the default values.

This could maybe be inferred from other UI settings telemetry (e.g. "setting changed"), but in the case of multiple change events that would be ambiguous, so this would mainly answer the question "What proportion of users have modified values?"

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM. Only comment I'd like to see addressed before merging is #88675 (comment)

Comment on lines +170 to +173
if (symbolName === 'Array') {
if (node.typeArguments?.length !== 1) {
throw Error('Array type only supports 1 type parameter Array<T>');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

UltraNIT: better safe than sorry I guess, but I still wonder if this assertion is really useful.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not needed but to stay consistent with other symbols we check for.

Comment on lines +135 to +136
const definition = this.defaults[key];
return !!definition?.sensitive;
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT (and personal opinion): Now that we have the ?? operator, I think definition?.sensitive ?? false would be slightly more explicit.

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 might change my opinion about this in the future but the I think using ?? with false is redundan. I find !! more explicit and succent

Comment on lines +128 to +131
const uiSettingsClient = uiSettingsServiceMock.createClient();
const getUiSettingsClient = jest.fn(() => uiSettingsClient);
uiSettingsClient.getUserProvided.mockResolvedValue(mockUserSettings);
uiSettingsClient.isSensitive.mockImplementation(mockIsSensitive);
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: these 4 lines are duplicated in all the tests of this describe section. Could probably be extracted to beforeEach or a function.

@Bamieh Bamieh requested a review from rylnd January 27, 2021 12:37
Copy link
Contributor

@rylnd rylnd left a comment

Choose a reason for hiding this comment

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

SecSol changes LGTM. Thank you for adding that additional field!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

@Bamieh Bamieh merged commit 82902e8 into elastic:master Jan 27, 2021
@Bamieh Bamieh deleted the telemetry/ui_settings_enhancement branch January 27, 2021 15:57
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jan 27, 2021
…y-tests

* 'master' of github.com:elastic/kibana: (276 commits)
  [Telemetry] Settings Collector: redact sensitive reported values (elastic#88675)
  [CI] Combines Jest test jobs (elastic#85850)
  [Upgrade Assistant] Migrate server to new es-js client (elastic#89207)
  Migrate maps_legacy, maps_oss, region_map, and tile_map plugions to TS projects (elastic#89351)
  [Vega Docs] Add experimental flag on the vega maps title (elastic#89402)
  Increase the time needed to locate the save viz toast (elastic#89301)
  [Enterprise Search] Add links to doc links service (elastic#89260)
  Fixed regex bug in Safari (elastic#89399)
  [Lens] Fix indexpattern checks for missing references (elastic#88840)
  [Lens] Clean up usage collector (elastic#89109)
  update apm index pattern (elastic#89395)
  [APM] Upgrade ES client (elastic#86594)
  Enable v2 so migrations, disable in FTR tests (elastic#89297)
  [Search Sessions] Make search session indicator UI opt-in, refactor per-app capabilities (elastic#88699)
  Cleanup OSS code from visualizations wizard (elastic#89092)
  [APM] Optimize API test order (elastic#88654)
  Rename conversion function, extract to module scope and add tests. (elastic#89018)
  [core.logging] Add ops logs to the KP logging system (elastic#88070)
  chore(NA): improve ts build refs performance on kbn bootstrap (elastic#89333)
  skip flaky suite (elastic#89379)
  ...

# Conflicts:
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.tsx
#	x-pack/test/accessibility/config.ts
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 27, 2021
…ana into task-manager/shift-on-trend

* 'task-manager/shift-on-trend' of github.com:gmmorris/kibana: (74 commits)
  [Metrics UI] Fix Host Overview boxes in Host Detail page (elastic#89299)
  [Telemetry] Settings Collector: redact sensitive reported values (elastic#88675)
  [CI] Combines Jest test jobs (elastic#85850)
  [Upgrade Assistant] Migrate server to new es-js client (elastic#89207)
  Migrate maps_legacy, maps_oss, region_map, and tile_map plugions to TS projects (elastic#89351)
  [Vega Docs] Add experimental flag on the vega maps title (elastic#89402)
  Increase the time needed to locate the save viz toast (elastic#89301)
  [Enterprise Search] Add links to doc links service (elastic#89260)
  Fixed regex bug in Safari (elastic#89399)
  [Lens] Fix indexpattern checks for missing references (elastic#88840)
  [Lens] Clean up usage collector (elastic#89109)
  update apm index pattern (elastic#89395)
  [APM] Upgrade ES client (elastic#86594)
  Enable v2 so migrations, disable in FTR tests (elastic#89297)
  [Search Sessions] Make search session indicator UI opt-in, refactor per-app capabilities (elastic#88699)
  Cleanup OSS code from visualizations wizard (elastic#89092)
  [APM] Optimize API test order (elastic#88654)
  Rename conversion function, extract to module scope and add tests. (elastic#89018)
  [core.logging] Add ops logs to the KP logging system (elastic#88070)
  chore(NA): improve ts build refs performance on kbn bootstrap (elastic#89333)
  ...
Bamieh added a commit that referenced this pull request Jan 29, 2021
#88675) (#89434)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@lukeelmers lukeelmers added Feature:Telemetry Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc labels Oct 1, 2021
@elasticmachine
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Telemetry 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 v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stack_management collector: review implementation
9 participants