Integrate Asset Inventory with backend#208417
Conversation
ad74938 to
b23c8a5
Compare
f4d14f9 to
b8ab5de
Compare
be08891 to
403a362
Compare
|
Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security) |
albertoblaz
left a comment
There was a problem hiding this comment.
Added some notes for reviewers down below
| // TODO We need this hard-coded id because `ASSET_INVENTORY_INDEX_PATTERN` does not populate the filter dropdowns | ||
| id: 'cloud_asset_inventory-2773feaf-50bb-43f8-9fa9-8f9a5f85e566', | ||
| name: ASSET_INVENTORY_INDEX_PATTERN, |
There was a problem hiding this comment.
Note: I needed to hard-code this value to populate the filters. However, in the future it should be ASSET_INVENTORY_INDEX_PATTERN, whose value is "logs-cloud_asset_inventory.asset_inventory-*"
| name: ASSET_INVENTORY_INDEX_PATTERN, | ||
| allowNoIndex: true, | ||
| title: indexPattern.title, | ||
| title: dataView.getIndexPattern(), |
There was a problem hiding this comment.
This tiny change happens because .title is a deprecated field
| const urlStorage = useMemo( | ||
| () => | ||
| createKbnUrlStateStorage({ | ||
| history, | ||
| useHash: false, | ||
| useHashQuery: false, | ||
| }), | ||
| [history] | ||
| ); | ||
| const filterControlsUrlState = useMemo( | ||
| () => | ||
| urlStorage.get<FilterControlConfig[] | undefined>(URL_PARAM_KEY.assetInventory) ?? undefined, | ||
| [urlStorage] | ||
| ); | ||
|
|
||
| const setFilterControlsUrlState = useCallback( | ||
| (newFilterControls: FilterControlConfig[]) => { | ||
| urlStorage.set(URL_PARAM_KEY.assetInventory, newFilterControls); | ||
| }, | ||
| [urlStorage] | ||
| ); |
There was a problem hiding this comment.
Previously I propagated showFilterBar={true} onto the <SearchBar> component. Using these props here broke the display value of the selected filter tags, rendering " - " instead.
Then, I switched showFilterBar={true} in <SearchBar> and this was not needed, so I removed it. Please let me know if this might cause an issue
| timeRange={{ | ||
| from, | ||
| to, | ||
| mode: 'absolute', | ||
| }} |
There was a problem hiding this comment.
@opauloh It seems the best way to solve the time range issue is simply not passing in any timeRange value. The filter dropdowns get populated correctly.
There was a problem hiding this comment.
Great, thanks for letting me know!
.../solutions/security/plugins/security_solution/public/asset_inventory/hooks/use_fetch_data.ts
Outdated
Show resolved
Hide resolved
.../solutions/security/plugins/security_solution/public/asset_inventory/hooks/use_fetch_data.ts
Outdated
Show resolved
Hide resolved
.../solutions/security/plugins/security_solution/public/asset_inventory/hooks/use_fetch_data.ts
Outdated
Show resolved
Hide resolved
.../solutions/security/plugins/security_solution/public/asset_inventory/hooks/use_fetch_data.ts
Outdated
Show resolved
Hide resolved
403a362 to
6f7f80a
Compare
|
@opauloh Addressed your comments. Thanks for your review! 🙏 |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Unknown metric groupsReferences to deprecated APIs
History
cc @albertoblaz |
## Summary Closes #201711. Implement "Top 10 Asset Types" bar chart. - The X-axis shows all assets grouped by category (`entity.category` field), one category per bar - Each bar shows stacked subgroups of assets by source (`entity.type` field) - The Y-axis shows the counts of assets ### Depends on - #208417 so that the chart renders data fetched dynamically. When it gets merged, this one will be rebased and will only contain the last commit as changes. ### Screenshots <details><summary>Loading state (animated spinner from <a href="https://eui.elastic.co/#/display/loading#chart" target="_blank">Elastic Charts</a>)</summary> <img width="1378" alt="Screenshot 2025-02-25 at 18 14 39" src="https://github.com/user-attachments/assets/553294e2-aaee-40c0-b1bb-de3e85f64d78" /> </details> <details><summary>Fetching state (animated progress bar)</summary> <img width="1376" alt="Screenshot 2025-02-25 at 18 14 58" src="https://github.com/user-attachments/assets/accdbc0e-40a2-4b30-9f4e-808a466be4d5" /> </details> <details><summary>Chart with fetched data</summary> <img width="1428" alt="Screenshot 2025-02-24 at 13 11 03" src="https://github.com/user-attachments/assets/3c455bc8-5bdd-4ea2-a946-53e138ae081b" /> </details> <details><summary>Chart with filtered, fetched data (by type: "Identity")</summary> <img width="1429" alt="Screenshot 2025-02-24 at 13 11 17" src="https://github.com/user-attachments/assets/a1e75210-757e-42d1-b852-945de5f3f44b" /> </details> <details><summary>Empty chart - no data</summary> <img width="1258" alt="Screenshot 2025-02-13 at 09 47 08" src="https://github.com/user-attachments/assets/c239a5a6-337e-41c9-a9a3-7cdc2c9b1e01" /> </details> ### Definition of done - [x] Add a bar chart titled "Top 10 Asset Types" to the "Asset Inventory" page. - [x] Use the `@elastic/charts` library to implement the visualization. - [x] Configure the chart with: - **X-axis:** Asset type categories - **Y-axis:** Count of assets - **Legend:** A color-coded key linking each bar to a specific category. - [x] Ensure the chart is responsive when resizing the screen and adheres to the [visual spec](https://www.figma.com/design/9zUqAhhglT1EGYG4LOl1X6/Asset-Management?node-id=2946-19648&t=FuD3BEY4FyxAKV38-4). - [x] Integrate the chart so that it updates based on the filters section and the Unified Header component. ### How to test Follow the instructions from [this PR](#208417) to prepare the local env with data. Alternatively, open the `asset_inventory/components/top_assets_bar_chart.tsx` file and edit yourself the `data` prop that we pass into `<BarSeries>` with mocked data. The data must have the following shape: ```js [ { category: 'cloud-compute', source: 'gcp-compute', count: 500, }, { category: 'cloud-compute', source: 'aws-security', count: 300, }, { category: 'cloud-storage', source: 'gcp-compute', count: 221, }, { category: 'cloud-storage', source: 'aws-security', count: 117, }, ]; ``` ### Checklist - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks No risks whatsoever.
## Summary Closes elastic#201711. Implement "Top 10 Asset Types" bar chart. - The X-axis shows all assets grouped by category (`entity.category` field), one category per bar - Each bar shows stacked subgroups of assets by source (`entity.type` field) - The Y-axis shows the counts of assets ### Depends on - elastic#208417 so that the chart renders data fetched dynamically. When it gets merged, this one will be rebased and will only contain the last commit as changes. ### Screenshots <details><summary>Loading state (animated spinner from <a href="https://eui.elastic.co/#/display/loading#chart" target="_blank">Elastic Charts</a>)</summary> <img width="1378" alt="Screenshot 2025-02-25 at 18 14 39" src="https://github.com/user-attachments/assets/553294e2-aaee-40c0-b1bb-de3e85f64d78" /> </details> <details><summary>Fetching state (animated progress bar)</summary> <img width="1376" alt="Screenshot 2025-02-25 at 18 14 58" src="https://github.com/user-attachments/assets/accdbc0e-40a2-4b30-9f4e-808a466be4d5" /> </details> <details><summary>Chart with fetched data</summary> <img width="1428" alt="Screenshot 2025-02-24 at 13 11 03" src="https://github.com/user-attachments/assets/3c455bc8-5bdd-4ea2-a946-53e138ae081b" /> </details> <details><summary>Chart with filtered, fetched data (by type: "Identity")</summary> <img width="1429" alt="Screenshot 2025-02-24 at 13 11 17" src="https://github.com/user-attachments/assets/a1e75210-757e-42d1-b852-945de5f3f44b" /> </details> <details><summary>Empty chart - no data</summary> <img width="1258" alt="Screenshot 2025-02-13 at 09 47 08" src="https://github.com/user-attachments/assets/c239a5a6-337e-41c9-a9a3-7cdc2c9b1e01" /> </details> ### Definition of done - [x] Add a bar chart titled "Top 10 Asset Types" to the "Asset Inventory" page. - [x] Use the `@elastic/charts` library to implement the visualization. - [x] Configure the chart with: - **X-axis:** Asset type categories - **Y-axis:** Count of assets - **Legend:** A color-coded key linking each bar to a specific category. - [x] Ensure the chart is responsive when resizing the screen and adheres to the [visual spec](https://www.figma.com/design/9zUqAhhglT1EGYG4LOl1X6/Asset-Management?node-id=2946-19648&t=FuD3BEY4FyxAKV38-4). - [x] Integrate the chart so that it updates based on the filters section and the Unified Header component. ### How to test Follow the instructions from [this PR](elastic#208417) to prepare the local env with data. Alternatively, open the `asset_inventory/components/top_assets_bar_chart.tsx` file and edit yourself the `data` prop that we pass into `<BarSeries>` with mocked data. The data must have the following shape: ```js [ { category: 'cloud-compute', source: 'gcp-compute', count: 500, }, { category: 'cloud-compute', source: 'aws-security', count: 300, }, { category: 'cloud-storage', source: 'gcp-compute', count: 221, }, { category: 'cloud-storage', source: 'aws-security', count: 117, }, ]; ``` ### Checklist - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks No risks whatsoever.
## Summary Fetch and render backend data upon opening the Asset Inventory page. ### Depends on - elastic/security-team#11270 - elastic#201709 - elastic#201710 - elastic/security-team#11687 ### Screenshots <details><summary>No applied filters</summary> <img width="1452" alt="Screenshot 2025-02-18 at 08 40 51" src="https://github.com/user-attachments/assets/e8970f92-701f-4bcf-9c43-8c1ce3155ba2" /> </details> <details><summary>Filtering through search bar with KQL</summary> <img width="1448" alt="Screenshot 2025-02-18 at 08 40 38" src="https://github.com/user-attachments/assets/fdffe535-bb76-44da-be43-096e3007e680" /> </details> <details><summary>Filtering through filter dropdowns</summary> <img width="1451" alt="Screenshot 2025-02-18 at 08 41 03" src="https://github.com/user-attachments/assets/ec68d9e8-5b4f-4c70-ba90-9fb7e4ddf18b" /> </details> <details><summary>Filtering through both search bar and filter dropdowns - no results found in this case</summary> <img width="1447" alt="Screenshot 2025-02-18 at 08 40 28" src="https://github.com/user-attachments/assets/2b2347e1-86fe-4d67-b859-0f84108c58bc" /> </details> <details><summary>Default empty state (no rows fetched)</summary> <img width="1452" alt="Screenshot 2025-02-18 at 09 39 49" src="https://github.com/user-attachments/assets/79876021-c09b-42a0-a776-5e5fde688994" /> </details> ### Definition of done - [x] Asset Inventory page fetches data prepared by the data-view that comes pre-installed with the "Cloud Asset Inventory" integration - [x] Search bar - [x] Filters - [x] Data Grid - [x] Empty state when number of fetched rows is zero ### How to test 1. Prepare cloud user - Go to [users page](https://keep-long-live-env-ess.kb.us-west2.gcp.elastic-cloud.com/app/management/security/users) on Elastic Cloud - Create a new user with a custom username and password - Copy the same roles from the user called `paulo_remote_dev` 2. Start local env running these commands - Run ES with `node scripts/es snapshot --license trial -E path.data=../default -E reindex.remote.whitelist=cb8e85476870428d8c796950e38a2eda.us-west2.gcp.elastic-cloud.com:443 -E xpack.security.authc.api_key.enabled=true` - Run Kibana with `yarn start --no-base-path` 3. Go to Integrations page, switch on the "*Display beta integrations*" control, then add the **Cloud Asset Inventory** integration on your local environment. Postpone Elastic Agent addition. 4. Go to Dev Tools page, click on the "config" tab and add the following environment variables: Use the dev tools config tab to save your as follows: - `${ES_REMOTE_HOST}`: [https://cb8e85476870428d8c796950e38a2eda.us-west2.gcp.elastic-cloud.com:443](https://cb8e85476870428d8c796950e38a2eda.us-west2.gcp.elastic-cloud.com/) - `${ES_REMOTE_USER}`: (the username you set for your user on step 0) - `${ES_REMOTE_PASS}`: (the pass you set for your user on step 0) 5. Run the following script: <details><summary>Script</summary> ``` POST _reindex?wait_for_completion=false { "conflicts": "proceed", "source": { "remote": { "host": "${ES_REMOTE_HOST}", "username": "${ES_REMOTE_USER}", "password": "${ES_REMOTE_PASS}" }, "index": "logs-cloud_asset_inventory*", "query": { "bool": { "must": [ { "range": { "@timestamp": { "gte": "now-1d" } } } ] } } }, "dest": { "op_type": "create", "index": "logs-cloud_asset_inventory.asset_inventory-default" }, "script": { "source": """ ctx._source['entity.category'] = ctx._source.asset.category; ctx._source['entity.name'] = ctx._source.asset.name; ctx._source['entity.type'] = ctx._source.asset.type; ctx._source['entity.sub_type'] = ctx._source.asset.sub_type; ctx._source['entity.sub_category'] = ctx._source.asset.sub_category; """ } } ``` </details> Finally, open Discover page and set the DataView filter on the top-right corner to `logs-cloud_asset_inventory.asset_inventory-*`, as in the screenshot below. If the grid is populated, you've got data and the whole setup worked! <details><summary>Discover page</summary>  </details> ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks No risks at all.
## Summary Closes elastic#201711. Implement "Top 10 Asset Types" bar chart. - The X-axis shows all assets grouped by category (`entity.category` field), one category per bar - Each bar shows stacked subgroups of assets by source (`entity.type` field) - The Y-axis shows the counts of assets ### Depends on - elastic#208417 so that the chart renders data fetched dynamically. When it gets merged, this one will be rebased and will only contain the last commit as changes. ### Screenshots <details><summary>Loading state (animated spinner from <a href="https://eui.elastic.co/#/display/loading#chart" target="_blank">Elastic Charts</a>)</summary> <img width="1378" alt="Screenshot 2025-02-25 at 18 14 39" src="https://github.com/user-attachments/assets/553294e2-aaee-40c0-b1bb-de3e85f64d78" /> </details> <details><summary>Fetching state (animated progress bar)</summary> <img width="1376" alt="Screenshot 2025-02-25 at 18 14 58" src="https://github.com/user-attachments/assets/accdbc0e-40a2-4b30-9f4e-808a466be4d5" /> </details> <details><summary>Chart with fetched data</summary> <img width="1428" alt="Screenshot 2025-02-24 at 13 11 03" src="https://github.com/user-attachments/assets/3c455bc8-5bdd-4ea2-a946-53e138ae081b" /> </details> <details><summary>Chart with filtered, fetched data (by type: "Identity")</summary> <img width="1429" alt="Screenshot 2025-02-24 at 13 11 17" src="https://github.com/user-attachments/assets/a1e75210-757e-42d1-b852-945de5f3f44b" /> </details> <details><summary>Empty chart - no data</summary> <img width="1258" alt="Screenshot 2025-02-13 at 09 47 08" src="https://github.com/user-attachments/assets/c239a5a6-337e-41c9-a9a3-7cdc2c9b1e01" /> </details> ### Definition of done - [x] Add a bar chart titled "Top 10 Asset Types" to the "Asset Inventory" page. - [x] Use the `@elastic/charts` library to implement the visualization. - [x] Configure the chart with: - **X-axis:** Asset type categories - **Y-axis:** Count of assets - **Legend:** A color-coded key linking each bar to a specific category. - [x] Ensure the chart is responsive when resizing the screen and adheres to the [visual spec](https://www.figma.com/design/9zUqAhhglT1EGYG4LOl1X6/Asset-Management?node-id=2946-19648&t=FuD3BEY4FyxAKV38-4). - [x] Integrate the chart so that it updates based on the filters section and the Unified Header component. ### How to test Follow the instructions from [this PR](elastic#208417) to prepare the local env with data. Alternatively, open the `asset_inventory/components/top_assets_bar_chart.tsx` file and edit yourself the `data` prop that we pass into `<BarSeries>` with mocked data. The data must have the following shape: ```js [ { category: 'cloud-compute', source: 'gcp-compute', count: 500, }, { category: 'cloud-compute', source: 'aws-security', count: 300, }, { category: 'cloud-storage', source: 'gcp-compute', count: 221, }, { category: 'cloud-storage', source: 'aws-security', count: 117, }, ]; ``` ### Checklist - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks No risks whatsoever.
Summary
Closes https://github.com/elastic/security-team/issues/11592.
Fetch and render backend data upon opening the Asset Inventory page.
Depends on
Screenshots
No applied filters
Filtering through search bar with KQL
Filtering through filter dropdowns
Filtering through both search bar and filter dropdowns - no results found in this case
Default empty state (no rows fetched)
Definition of done
How to test
node scripts/es snapshot --license trial -E path.data=../default -E reindex.remote.whitelist=<REMOTE_URL>:<REMOTE_PORT> -E xpack.security.authc.api_key.enabled=trueyarn start --no-base-pathUse the dev tools config tab to save your as follows:
${ES_REMOTE_HOST}: (the URL to the cloud instance)${ES_REMOTE_USER}: (the username you set for your user on step 0)${ES_REMOTE_PASS}: (the pass you set for your user on step 0)Script
Finally, open Discover page and set the DataView filter on the top-right corner to
logs-cloud_asset_inventory.asset_inventory-*, as in the screenshot below. If the grid is populated, you've got data and the whole setup worked!Discover page
Checklist
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesIdentify risks
No risks at all.