elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.65k stars 8.23k forks source link

[Security Solution] There was an error uploading the value list / Data stream does not exist (400) error for a user with correct permissions #170590

Open andrew-goldstein opened 1 year ago

andrew-goldstein commented 1 year ago

A user reported they received an unexpected error (detailed below) while uploading a value list when both of the following are true:

When this issue occurs, the following 400 (bad request) error is displayed:

There was an error uploading the value list.

To import a list item, the data steam must exist first. Data stream ".lists-try_again" does not exist (400)

{
  "name": "Error",
  "body": {
    "message": "To import a list item, the data steam must exist first. Data stream \".lists-try_again\" does not exist",
    "status_code": 400
  },
  "message": "Bad Request",
  "stack": "Error: Bad Request\n    at Fetch.fetchResponse (http://localhost:5601/9007199254740991/bundles/core/core.entry.js:15494:13)\n    at async interceptResponse (http://localhost:5601/9007199254740991/bundles/core/core.entry.js:15802:10)\n    at async http://localhost:5601/9007199254740991/bundles/core/core.entry.js:15391:39"
}

The error above appears in the screenshot below:

05_error_details

Workaround

To workaround for this error / issue:

  1. Login to the Kibana space as a superuser (e.g. the elastic user)

  2. Import a value list to the space while logged in as a superuser

  3. Logout the superuser

  4. Login to Kibana as a user with fewer permissions (to the same space)

  5. Import a value list (to the same space) as a user with fewer permissions

Kibana/Elasticsearch Stack version:

A user reported this issue in Kibana version 8.8.2. The error may also be reproduced in main via a local Kibana development environment, per the 50 reproduction steps in this issue.

Steps to reproduce:

  1. Login to the Default space as the elastic user

  2. Navigate to Stack Management

  3. Click Spaces

  4. Click Create space

  5. Enter the following space name: try_again

  6. Click Create space to create the try_again space

  7. In Stack Management, click Roles

  8. Click Create role

  9. Enter the following role name: testing_value_list_role

  10. In the Index privileges / Indices section of Create role, enter the following Indices:

.lists-try_again
.alerts-security.alerts-try_again
.alerts-security.alerts-try_again
  1. In the Index privileges / Privileges section of Create role, enter the following Privileges:
read
write
write
view_index_metadata
maintenance
create
create_index
delete_index
index
  1. In the Kibana section of Create role, click Add Kibana privilege

  2. In the Kibana privileges flyout, select the try_again space

  3. In the Kibana privileges flyout, click Bulk actions > All, to grant Custom access to a features

Expected result:

01_kibana_privileges

  1. Click Add Kibana privilege

Expected result:

02_create_role

  1. Click the Create role button

Expected result:

  1. In Stack Management, click Users

  2. In Users, click Create user

  3. Enter the following username: testing_value_list

  4. Enter and confirm a password

  5. Select the testing_value_list_role from the Roles dropdown

  6. Click Create user

Expected result:

  1. Log out the elastic user from Kibana

  2. Login to Kibana as the new testing_value_list user

  3. Navigate to Security > Alerts

  4. Click Manage rules

  5. Click Import value lists

Expected result:

  1. Click the Select or drag and drop a file button

  2. On your local file system, create a file named joe_list.csv, with the following contents:

127.0.0.1
  1. Select the joe_list.csv file in the web browser's Open dialog, then click the Open button

  2. In the Import value lists flyout, select IP addresses from the Type of value list dropdown

Expected result:

03_import_value_lists

  1. Open the browser's developer tools

  2. Navigate to the browser developer tools Network tab

  3. Clear the Network tab's history of previous requests

  4. Click the Import value list button

Expected result:

Actual results:

04_error_uploading_value_list

  1. Click See the full error

Expected result:

{
  "name": "Error",
  "body": {
    "message": "To import a list item, the data steam must exist first. Data stream \".lists-try_again\" does not exist",
    "status_code": 400
  },
  "message": "Bad Request",
  "stack": "Error: Bad Request\n    at Fetch.fetchResponse (http://localhost:5601/9007199254740991/bundles/core/core.entry.js:15494:13)\n    at async interceptResponse (http://localhost:5601/9007199254740991/bundles/core/core.entry.js:15802:10)\n    at async http://localhost:5601/9007199254740991/bundles/core/core.entry.js:15391:39"
}

per the following screenshot:

05_error_details

  1. On the local file system, make a copy of the file joe_list.csv. Name the new file tuesdays.csv.

  2. Log out the testing_value_list user from Kibana

  3. Once again, login to Kibana as the elastic (superuser)

  4. Select the try_again space

  5. Navigate to Security > Alerts

  6. Click Manage rules

  7. Click Import value lists

  8. Click the Select or drag and drop a file button

  9. Select the tuesdays.csv file, then click Open

  10. In the Import value lists flyout, select IP addresses from the Type of value list dropdown

  11. Click the Import value list button

Expected results:

06_list_created_by_elastic_user

  1. Log out the elastic user from Kibana

  2. Once again, Login to Kibana as the new testing_value_list user

  3. One more time, attempt to upload joe_list.csv as the testing_value_list user

Expected result:

07_joe_list_created

Note that the issue may only be reproduced ONCE per newly created space. The issue may NOT be reproduced again for the same space, even that space is deleted, and another space with the same name is (re)created.

Server side error thrown from import_list_item_route.ts

The error appears to be thrown by the following code in x-pack/plugins/lists/server/routes/list/import_list_item_route:

            const listIndexExists = await lists.getListIndexExists();
            if (!listIndexExists) {
              return siemResponse.error({
                body: `To import a list item, the data steam must exist first. Data stream "${lists.getListName()}" does not exist`,
                statusCode: 400,
              });
            }

The above was determined by adding the following console.trace to the code above:

            if (!listIndexExists) {
              console.trace('--> A: listIndexExists', listIndexExists);

              return siemResponse.error({
                body: `To import a list item, the data steam must exist first. Data stream "${lists.getListName()}" does not exist`,
                statusCode: 400,
              });
            }
            // otherwise migration is needed
            await lists.migrateListIndexToDataStream();
          }

The following console.trace was logged (on the server):

Trace: --> A: listIndexExists false
    at Object.fn (import_list_item_route.ts:58:23)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at core_versioned_route.ts:179:22
    at Router.handle (router.ts:228:30)
    at handler (router.ts:162:13)
    at exports.Manager.execute (/Users/andrew.goldstein/Projects/forks/andrew-goldstein/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28)
    at Object.internals.handler (/Users/andrew.goldstein/Projects/forks/andrew-goldstein/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20)
    at exports.execute (/Users/andrew.goldstein/Projects/forks/andrew-goldstein/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20)
    at Request._lifecycle (/Users/andrew.goldstein/Projects/forks/andrew-goldstein/kibana/node_modules/@hapi/hapi/lib/request.js:371:32)
    at Request._execute (/Users/andrew.goldstein/Projects/forks/andrew-goldstein/kibana/node_modules/@hapi/hapi/lib/request.js:281:9)
elasticmachine commented 1 year ago

Pinging @elastic/security-solution (Team: SecuritySolution)

elasticmachine commented 1 year ago

Pinging @elastic/response-ops (Team:ResponseOps)

vitaliidm commented 1 year ago

The role setup does not have all required privileges

According to https://www.elastic.co/guide/en/security/current/detections-permissions-section.html, it needs cluster privilege manage and index privilege manage, which were not added in 11 step of reproduction. When I added manage to both index and cluster, it started to work as expected.

The component, responsible to display warning, is out of date: https://github.com/elastic/kibana/blob/8.11/x-pack/plugins/security_solution/public/detections/components/callouts/missing_privileges_callout/use_missing_privileges.ts#L14

It checks for wrong privileges on index and seems does do any checks on cluster privilege. So, as solution I see, we need to update that component with the right index privileges and also start to show missing cluster privilege as well

elasticmachine commented 1 year ago

Pinging @elastic/security-detections-response (Team:Detections and Resp)