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

[Security Solution] Put Artifacts by Policy feature behind a feature flag #95284

Conversation

dasansol92
Copy link
Contributor

@dasansol92 dasansol92 commented Mar 24, 2021

Summary

This pr includes code from this branch that allows users assign artifacts by policy.

It also includes feature flag management on Ui with a new custom hook that checks if the desired feature is enabled or not.
This hook uses a new key on redux state inside the app namespace making it available for all security plugins.
In order to use this hook under security app you have to import it and call it on this way:

import { useIsExperimentalFeatureEnabled } from '*/common/hooks/use_experimental_features';
const isSomeFeatureFlagYouWantToCheckEnabled: boolean = useIsExperimentalFeatureEnabled(
      'someFeatureFlagYouWantToCheck'
    );

To enable this feature flag in dev env just write this into your kibana.dev.yml:

xpack.securitySolution.enableExperimental:
- trustedAppsByPolicyEnabled

Behind the scenes it uses enableExperimental plugin configuration
On the BE, it forces the default value for effectScope when feature flag is not enabled.

Feature Flag:
artifactsByPolicyUnderFeatureFlag

Edit action:
editTrustedApp

It also includes unit tests.

Checklist

For maintainers

paul-tavares and others added 24 commits March 24, 2021 11:14
* Initial version of API for trusted apps per policy.

* Fixed compilation errors because of missing new property.

* Mapping from tags to policies and back. (No testing)

* Fixed compilation error after pulling in main.

* Fixed failing tests.

* Separated out the prefix in tag for policy reference into constant.

Co-authored-by: Kibana Machine <[email protected]>
…er Global or Policy Specific (elastic#88707)

* Create form supports selecting policies or making Trusted app global
* New component `EffectedPolicySelect` - for selecting policies
* Enhanced `waitForAction()` test utility to provide a `validate()` option
elastic#89479)

* Add Edit button to TA card UI
* Support additional url params (`show`, `id`)
* Refactor TrustedAppForm to support Editing of an existing entry
…lastic#90333)

* New API route for Update (`PUT`)
* Connect UI to Update (PUT) API
* Add `version` to TrustedApp type and return it on the API responses
* Refactor - moved some public/server shared modules to top-level `common/*`
…rusted App item (elastic#90842)

* Get One Trusted App API - route, service, handler
* Adjust UI to call GET api to retrieve trusted app for edit
* Deleted ununsed trusted app types file
* Add UI handling of non-existing TA for edit or when id is missing in url
…rusted Apps (elastic#91656)

* correct trusted app schema to ensure `version` is not exposed on TS type for POST
* Added updated_by, updated_on properties to TrustedApp
* Refactored TA List view to fix bug where card was not updated on a successful edit
* Test cases for card interaction from the TA List view
* Change title of policy selection to `Assignment`
* Selectable Policy CSS adjustments based on UX feedback
…port (elastic#92611)

* Fix bad merge from master
* Fix trusted apps generator
* Add `kuery` to the GET (list) Trusted Apps api
@dasansol92 dasansol92 added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v7.13.0 labels Mar 24, 2021
@dasansol92 dasansol92 requested review from a team as code owners March 24, 2021 10:57
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-onboarding-and-lifecycle-mgt (Team:Onboarding and Lifecycle Mgt)

@kevinlog
Copy link
Contributor

I checked it out and did a test run. Find a summary of what I did below. Based on this quick run, things look like they're working as expected!

with feature flag turned OFF:

  • Add some new trusted apps
  • Ensure policies are updated
  • Edit a trusted app
  • Delete a trusted app
  • Ensure policies update

with feature flag turned ON:

  • Add a new trusted app for a single policy
  • Add a new trusted app for a different single policy
  • Ensure policies update correctly (i.e. one updates for a per Policy change)
  • Edit trusted apps
  • Delete trusted apps
  • Ensure policies update accordingly

Some screenshots:
Feature Flag OFF
image

Feature Flag ON
image

@kevinlog
Copy link
Contributor

Functionally, things look like they're working from my perspective, so it's a 👍 from me. @paul-tavares should give the code a closer look - I know a lot of this code was previously reviewed when we were working on the feature branch.

Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

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

Looks awesome.
I did not run it locally, but did review all code. Left just a few comments that I would like to hear back from you on.

thanks for taking this on :)

@@ -65,14 +65,19 @@ import {
import { SecurityAppStore } from './common/store/store';
import { getCaseConnectorUI } from './cases/components/connectors';
import { licenseService } from './common/hooks/use_license';
import { SecuritySolutionConfigType } from './common/types';
Copy link
Contributor

Choose a reason for hiding this comment

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

(optional) consider renaming so that its clear this is only a subset of the security soluton configuration (the properties exposed to the UI). Maybe SecuritySolutionUiConfigType?

endpointAppContext: EndpointAppContext
): Promise<PutTrustedAppUpdateRequest | PostTrustedAppCreateRequest> => {
const config = await endpointAppContext.config();
const isTrustedAppsByPolicyEnabled = parseExperimentalConfigValue(config.enableExperimental)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we should avoid the constant parsing and instead do it once in the EndpointAppContext and expose it there. Doing the parsing there would hepefully avoid having this function here be async as well, since we would not have to retrieve the .config() again.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean move this into x-pack/plugins/security_solution/server/plugin.ts and add the parsed enableExperimental on the EndpointAppContext type?
Make sense for me since it will be available everywhere with the context,

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, thats what I mean. I think that might be ok because we're not using the Observable approach to sync up with the config.

@dasansol92
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@FrankHassanabad FrankHassanabad left a comment

Choose a reason for hiding this comment

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

LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2209 2214 +5

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 7.2MB 7.2MB +6.1KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
securitySolution 211.3KB 212.5KB +1.3KB
Unknown metric groups

async chunk count

id before after diff
securitySolution 25 26 +1

History

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

Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

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

🚢 🚀

@dasansol92 dasansol92 merged commit 2af094a into elastic:master Mar 26, 2021
dasansol92 added a commit to dasansol92/kibana that referenced this pull request Mar 26, 2021
…flag (elastic#95284)

* Added sync_master file for tracking/triggering PRs for merging master into feature branch

* removed unnecessary (temporary) markdown file

* Trusted apps by policy api (elastic#88025)

* Initial version of API for trusted apps per policy.

* Fixed compilation errors because of missing new property.

* Mapping from tags to policies and back. (No testing)

* Fixed compilation error after pulling in main.

* Fixed failing tests.

* Separated out the prefix in tag for policy reference into constant.

Co-authored-by: Kibana Machine <[email protected]>

* [SECURITY_SOLUTION][ENDPOINT] Ability to create a Trusted App as either Global or Policy Specific (elastic#88707)

* Create form supports selecting policies or making Trusted app global
* New component `EffectedPolicySelect` - for selecting policies
* Enhanced `waitForAction()` test utility to provide a `validate()` option

* [SECURITY SOLUTION][ENDPOINT] UI for editing Trusted Application items (elastic#89479)

* Add Edit button to TA card UI
* Support additional url params (`show`, `id`)
* Refactor TrustedAppForm to support Editing of an existing entry

* [SECURITY SOLUTION][ENDPOINT] API (`PUT`) for Trusted Apps Edit flow (elastic#90333)

* New API route for Update (`PUT`)
* Connect UI to Update (PUT) API
* Add `version` to TrustedApp type and return it on the API responses
* Refactor - moved some public/server shared modules to top-level `common/*`

* [SECURITY SOLUTION][ENDPOINT] Trusted Apps API to retrieve a single Trusted App item (elastic#90842)

* Get One Trusted App API - route, service, handler
* Adjust UI to call GET api to retrieve trusted app for edit
* Deleted ununsed trusted app types file
* Add UI handling of non-existing TA for edit or when id is missing in url

* [Security Solution][Endpoint] Multiple misc. updates/fixes for Edit Trusted Apps (elastic#91656)

* correct trusted app schema to ensure `version` is not exposed on TS type for POST
* Added updated_by, updated_on properties to TrustedApp
* Refactored TA List view to fix bug where card was not updated on a successful edit
* Test cases for card interaction from the TA List view
* Change title of policy selection to `Assignment`
* Selectable Policy CSS adjustments based on UX feedback

* Fix failing server tests

* [Security Solution][Endpoint] Trusted Apps list API KQL filtering support (elastic#92611)

* Fix bad merge from master
* Fix trusted apps generator
* Add `kuery` to the GET (list) Trusted Apps api

* Refactor schema with Put method after merging changes with master

* WIP: allow effectScope only when feature flag is enabled

* Fixes errors with non declared logger

* Uses experimental features module to allow or not effectScope on create/update trusted app schema

* Set default value for effectScope when feature flag is disabled

* Adds experimentals into redux store. Also creates hook to retrieve a feature flag value from state

* Hides effectPolicy when feature flag is not enabled

* Fixes unit test mocking hook and adds new test case

* Changes file extension for custom hook

* Adds new unit test for custom hook

* Hides horizontal bar with feature flag

* Compress text area depending on feature flag

* Fixes failing test because feature flag

* Fixes wrong import and unit test

* Thwrows error if invalid feature flag check

* Adds snapshoot checks with feature flag enabled/disabled

* Test snapshots

* Changes type name

* Add experimentalFeatures in app context

* Fixes type checks due AppContext changes

* Fixes test due changes on custom hook

Co-authored-by: Paul Tavares <[email protected]>
Co-authored-by: Bohdan Tsymbala <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Paul Tavares <[email protected]>
dasansol92 added a commit that referenced this pull request Mar 26, 2021
…flag (#95284) (#95497)

* Added sync_master file for tracking/triggering PRs for merging master into feature branch

* removed unnecessary (temporary) markdown file

* Trusted apps by policy api (#88025)

* Initial version of API for trusted apps per policy.

* Fixed compilation errors because of missing new property.

* Mapping from tags to policies and back. (No testing)

* Fixed compilation error after pulling in main.

* Fixed failing tests.

* Separated out the prefix in tag for policy reference into constant.

Co-authored-by: Kibana Machine <[email protected]>

* [SECURITY_SOLUTION][ENDPOINT] Ability to create a Trusted App as either Global or Policy Specific (#88707)

* Create form supports selecting policies or making Trusted app global
* New component `EffectedPolicySelect` - for selecting policies
* Enhanced `waitForAction()` test utility to provide a `validate()` option

* [SECURITY SOLUTION][ENDPOINT] UI for editing Trusted Application items (#89479)

* Add Edit button to TA card UI
* Support additional url params (`show`, `id`)
* Refactor TrustedAppForm to support Editing of an existing entry

* [SECURITY SOLUTION][ENDPOINT] API (`PUT`) for Trusted Apps Edit flow (#90333)

* New API route for Update (`PUT`)
* Connect UI to Update (PUT) API
* Add `version` to TrustedApp type and return it on the API responses
* Refactor - moved some public/server shared modules to top-level `common/*`

* [SECURITY SOLUTION][ENDPOINT] Trusted Apps API to retrieve a single Trusted App item (#90842)

* Get One Trusted App API - route, service, handler
* Adjust UI to call GET api to retrieve trusted app for edit
* Deleted ununsed trusted app types file
* Add UI handling of non-existing TA for edit or when id is missing in url

* [Security Solution][Endpoint] Multiple misc. updates/fixes for Edit Trusted Apps (#91656)

* correct trusted app schema to ensure `version` is not exposed on TS type for POST
* Added updated_by, updated_on properties to TrustedApp
* Refactored TA List view to fix bug where card was not updated on a successful edit
* Test cases for card interaction from the TA List view
* Change title of policy selection to `Assignment`
* Selectable Policy CSS adjustments based on UX feedback

* Fix failing server tests

* [Security Solution][Endpoint] Trusted Apps list API KQL filtering support (#92611)

* Fix bad merge from master
* Fix trusted apps generator
* Add `kuery` to the GET (list) Trusted Apps api

* Refactor schema with Put method after merging changes with master

* WIP: allow effectScope only when feature flag is enabled

* Fixes errors with non declared logger

* Uses experimental features module to allow or not effectScope on create/update trusted app schema

* Set default value for effectScope when feature flag is disabled

* Adds experimentals into redux store. Also creates hook to retrieve a feature flag value from state

* Hides effectPolicy when feature flag is not enabled

* Fixes unit test mocking hook and adds new test case

* Changes file extension for custom hook

* Adds new unit test for custom hook

* Hides horizontal bar with feature flag

* Compress text area depending on feature flag

* Fixes failing test because feature flag

* Fixes wrong import and unit test

* Thwrows error if invalid feature flag check

* Adds snapshoot checks with feature flag enabled/disabled

* Test snapshots

* Changes type name

* Add experimentalFeatures in app context

* Fixes type checks due AppContext changes

* Fixes test due changes on custom hook

Co-authored-by: Paul Tavares <[email protected]>
Co-authored-by: Bohdan Tsymbala <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Paul Tavares <[email protected]>

Co-authored-by: Paul Tavares <[email protected]>
Co-authored-by: Bohdan Tsymbala <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Paul Tavares <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants