-
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
[Fleet] If we add an enrollment token with space, it does not create the enrollment token & throws an undefined error to the user #99895
Comments
Pinging @elastic/fleet (Team:Fleet) |
@manishgupta-qasource please review |
Reviewed & Assigned to @EricDavisX |
I bumped into this while working on #91454 I'll look more into it and try to fix or at least give more info |
…00056) ## Summary fixes #99895 Can reproduce #99895 with something like ```shell curl 'http://localhost:5601/api/fleet/enrollment-api-keys' \ -H 'content-type: application/json' \ -H 'kbn-version: 8.0.0' \ -u elastic:changeme \ --data-raw '{"name":"with spaces","policy_id":"d6a93200-b1bd-11eb-90ac-052b474d74cd"}' ``` Kibana logs this stack trace ``` server log [10:57:07.863] [error][fleet][plugins] KQLSyntaxError: Expected AND, OR, end of input but "\" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:with\ spaces* --------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:160:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "\\" found.' ``` the `kuery` value which causes the `KQLSyntaxError` is ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:with\\ spaces* ``` a value without spaces, e.g. `no_spaces` ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:no_spaces* ``` is converted to this query object ``` { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "no_spaces*" } } ], "minimum_should_match": 1 } } ] } ``` I tried some other approaches for handling the spaces based on what I saw in the docs like `name:"\"with spaces\"` and `name:(with spaces)*`but they all failed as well, like ``` KQLSyntaxError: Expected AND, OR, end of input but "*" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:(with spaces)* -----------------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:166:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "*" found.' ``` So I logged out the query object for a successful request, and put that in a function ``` { "query": { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "(with spaces) *" } } ], "minimum_should_match": 1 } } ] } } } ``` ### Checklist - [x] [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
…astic#100056) ## Summary fixes elastic#99895 Can reproduce elastic#99895 with something like ```shell curl 'http://localhost:5601/api/fleet/enrollment-api-keys' \ -H 'content-type: application/json' \ -H 'kbn-version: 8.0.0' \ -u elastic:changeme \ --data-raw '{"name":"with spaces","policy_id":"d6a93200-b1bd-11eb-90ac-052b474d74cd"}' ``` Kibana logs this stack trace ``` server log [10:57:07.863] [error][fleet][plugins] KQLSyntaxError: Expected AND, OR, end of input but "\" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:with\ spaces* --------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:160:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "\\" found.' ``` the `kuery` value which causes the `KQLSyntaxError` is ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:with\\ spaces* ``` a value without spaces, e.g. `no_spaces` ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:no_spaces* ``` is converted to this query object ``` { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "no_spaces*" } } ], "minimum_should_match": 1 } } ] } ``` I tried some other approaches for handling the spaces based on what I saw in the docs like `name:"\"with spaces\"` and `name:(with spaces)*`but they all failed as well, like ``` KQLSyntaxError: Expected AND, OR, end of input but "*" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:(with spaces)* -----------------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:166:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "*" found.' ``` So I logged out the query object for a successful request, and put that in a function ``` { "query": { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "(with spaces) *" } } ], "minimum_should_match": 1 } } ] } } } ``` ### Checklist - [x] [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
…00056) (#100091) ## Summary fixes #99895 Can reproduce #99895 with something like ```shell curl 'http://localhost:5601/api/fleet/enrollment-api-keys' \ -H 'content-type: application/json' \ -H 'kbn-version: 8.0.0' \ -u elastic:changeme \ --data-raw '{"name":"with spaces","policy_id":"d6a93200-b1bd-11eb-90ac-052b474d74cd"}' ``` Kibana logs this stack trace ``` server log [10:57:07.863] [error][fleet][plugins] KQLSyntaxError: Expected AND, OR, end of input but "\" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:with\ spaces* --------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:160:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "\\" found.' ``` the `kuery` value which causes the `KQLSyntaxError` is ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:with\\ spaces* ``` a value without spaces, e.g. `no_spaces` ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:no_spaces* ``` is converted to this query object ``` { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "no_spaces*" } } ], "minimum_should_match": 1 } } ] } ``` I tried some other approaches for handling the spaces based on what I saw in the docs like `name:"\"with spaces\"` and `name:(with spaces)*`but they all failed as well, like ``` KQLSyntaxError: Expected AND, OR, end of input but "*" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:(with spaces)* -----------------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:166:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "*" found.' ``` So I logged out the query object for a successful request, and put that in a function ``` { "query": { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "(with spaces) *" } } ], "minimum_should_match": 1 } } ] } } } ``` ### Checklist - [x] [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 Co-authored-by: John Schulz <john.schulz@elastic.co>
…astic#100056) ## Summary fixes elastic#99895 Can reproduce elastic#99895 with something like ```shell curl 'http://localhost:5601/api/fleet/enrollment-api-keys' \ -H 'content-type: application/json' \ -H 'kbn-version: 8.0.0' \ -u elastic:changeme \ --data-raw '{"name":"with spaces","policy_id":"d6a93200-b1bd-11eb-90ac-052b474d74cd"}' ``` Kibana logs this stack trace ``` server log [10:57:07.863] [error][fleet][plugins] KQLSyntaxError: Expected AND, OR, end of input but "\" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:with\ spaces* --------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:160:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "\\" found.' ``` the `kuery` value which causes the `KQLSyntaxError` is ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:with\\ spaces* ``` a value without spaces, e.g. `no_spaces` ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:no_spaces* ``` is converted to this query object ``` { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "no_spaces*" } } ], "minimum_should_match": 1 } } ] } ``` I tried some other approaches for handling the spaces based on what I saw in the docs like `name:"\"with spaces\"` and `name:(with spaces)*`but they all failed as well, like ``` KQLSyntaxError: Expected AND, OR, end of input but "*" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:(with spaces)* -----------------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:166:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "*" found.' ``` So I logged out the query object for a successful request, and put that in a function ``` { "query": { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "(with spaces) *" } } ], "minimum_should_match": 1 } } ] } } } ``` ### Checklist - [x] [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
…00056) (#100212) ## Summary fixes #99895 Can reproduce #99895 with something like ```shell curl 'http://localhost:5601/api/fleet/enrollment-api-keys' \ -H 'content-type: application/json' \ -H 'kbn-version: 8.0.0' \ -u elastic:changeme \ --data-raw '{"name":"with spaces","policy_id":"d6a93200-b1bd-11eb-90ac-052b474d74cd"}' ``` Kibana logs this stack trace ``` server log [10:57:07.863] [error][fleet][plugins] KQLSyntaxError: Expected AND, OR, end of input but "\" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:with\ spaces* --------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:160:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "\\" found.' ``` the `kuery` value which causes the `KQLSyntaxError` is ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:with\\ spaces* ``` a value without spaces, e.g. `no_spaces` ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:no_spaces* ``` is converted to this query object ``` { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "no_spaces*" } } ], "minimum_should_match": 1 } } ] } ``` I tried some other approaches for handling the spaces based on what I saw in the docs like `name:"\"with spaces\"` and `name:(with spaces)*`but they all failed as well, like ``` KQLSyntaxError: Expected AND, OR, end of input but "*" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:(with spaces)* -----------------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:166:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "*" found.' ``` So I logged out the query object for a successful request, and put that in a function ``` { "query": { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "(with spaces) *" } } ], "minimum_should_match": 1 } } ] } } } ``` ### Checklist - [x] [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 Co-authored-by: John Schulz <john.schulz@elastic.co>
Hi @jfsiii, We tested this ticket on the latest 7.13.0 BC9 build & found that issue is now fixed. Please find below the exact testing details: Build Details:
Screenshots Hence, marking it as "Validated". Thanks |
…astic#100056) ## Summary fixes elastic#99895 Can reproduce elastic#99895 with something like ```shell curl 'http://localhost:5601/api/fleet/enrollment-api-keys' \ -H 'content-type: application/json' \ -H 'kbn-version: 8.0.0' \ -u elastic:changeme \ --data-raw '{"name":"with spaces","policy_id":"d6a93200-b1bd-11eb-90ac-052b474d74cd"}' ``` Kibana logs this stack trace ``` server log [10:57:07.863] [error][fleet][plugins] KQLSyntaxError: Expected AND, OR, end of input but "\" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:with\ spaces* --------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:160:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "\\" found.' ``` the `kuery` value which causes the `KQLSyntaxError` is ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:with\\ spaces* ``` a value without spaces, e.g. `no_spaces` ``` policy_id:\"d6a93200-b1bd-11eb-90ac-052b474d74cd\" AND name:no_spaces* ``` is converted to this query object ``` { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "no_spaces*" } } ], "minimum_should_match": 1 } } ] } ``` I tried some other approaches for handling the spaces based on what I saw in the docs like `name:"\"with spaces\"` and `name:(with spaces)*`but they all failed as well, like ``` KQLSyntaxError: Expected AND, OR, end of input but "*" found. policy_id:"d6a93200-b1bd-11eb-90ac-052b474d74cd" AND name:(with spaces)* -----------------------------------------------------------------------^ at Object.fromKueryExpression (/Users/jfsiii/work/kibana/src/plugins/data/common/es_query/kuery/ast/ast.ts:52:13) at listEnrollmentApiKeys (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:37:69) at Object.generateEnrollmentAPIKey (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts:166:31) at processTicksAndRejections (internal/process/task_queues.js:93:5) at postEnrollmentApiKeyHandler (/Users/jfsiii/work/kibana/x-pack/plugins/fleet/server/routes/enrollment_api_key/handler.ts:53:20) at Router.handle (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:273:30) at handler (/Users/jfsiii/work/kibana/src/core/server/http/router/router.ts:228:11) at exports.Manager.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28) at Object.internals.handler (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20) at exports.execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20) at Request._lifecycle (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:370:32) at Request._execute (/Users/jfsiii/work/kibana/node_modules/@hapi/hapi/lib/request.js:279:9) { shortMessage: 'Expected AND, OR, end of input but "*" found.' ``` So I logged out the query object for a successful request, and put that in a function ``` { "query": { "bool": { "filter": [ { "bool": { "should": [ { "match_phrase": { "policy_id": "d6a93200-b1bd-11eb-90ac-052b474d74cd" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "query_string": { "fields": [ "name" ], "query": "(with spaces) *" } } ], "minimum_should_match": 1 } } ] } } } ``` ### Checklist - [x] [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
Describe the feature
If we add an enrollment token with space, it does not create the enrollment token & throws an undefined error to the user
Build Details:
Preconditions
Steps to Reproduce
Test data
N/A
Impacted Test case(s)
N/A
Actual Result
If we add an enrollment token with space, it does not create the enrollment token & throws an undefined error to the user
Expected Result
If we add an enrollment token with space, it should be created
What's Working
N/A
What's Not Working
N/A
Screenshot
The text was updated successfully, but these errors were encountered: