-
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
[index patterns] Add pattern validation method to index patterns fetcher #90170
Conversation
) | ||
); | ||
return result.reduce( | ||
(acc: string[], { body: indexLookup }, patternListIndex) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure this is exactly what elasticsearch would do if we would request fieldcaps for a comma seperated list of patterns ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code LGTM
const fieldCapsResponse = await getFieldCapabilities( | ||
this.elasticsearchClient, | ||
pattern, | ||
patternListActive.length > 0 ? patternListActive : patternList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add this as a comment to the code. It definitely makes sense but its not obvious why this is being done.
async validatePatternListActive(patternList: string[]) { | ||
const result = await Promise.all( | ||
patternList.map((pattern) => | ||
this.elasticsearchClient.count({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed from the _resolve/index
api to the count
api as read only users got 403'd on the resolve. count works well: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its annoying that the resolve endpoint works this way but this is a good choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is annoying. i would not have caught it if it weren't for that ML test!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also tried ElasticsearchClient.indices.exists
and it appears read-only users get 403'd on those indices
methods as well. I'm not sure if this has been taken into account for testing anywhere that uses the getFieldsForTimePattern
which eventually calls ElasticsearchClient.indices.getAlias
: https://github.com/elastic/kibana/blob/master/src/plugins/data/server/index_patterns/fetcher/lib/es_api.ts#L42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That code needs to be removed, time pattern index patterns were dropped in 7.x.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one request otherwise looks great!
src/plugins/data/server/index_patterns/fetcher/index_patterns_fetcher.ts
Outdated
Show resolved
Hide resolved
const fieldCapsResponse = await getFieldCapabilities( | ||
this.elasticsearchClient, | ||
pattern, | ||
patternListActive.length > 0 ? patternListActive : patternList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add this as a comment to the code. It definitely makes sense but its not obvious why this is being done.
async validatePatternListActive(patternList: string[]) { | ||
const result = await Promise.all( | ||
patternList.map((pattern) => | ||
this.elasticsearchClient.count({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its annoying that the resolve endpoint works this way but this is a good choice.
}) | ||
) | ||
.map((p) => | ||
p.catch((e) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the count
api will return count: 0
for a pattern like nothingbeat-*
but will throw the index_not_found_exception
on non-wildcard, like nothingbeat-exact
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
Summary
The
IndexPatternsFetcher.getFieldsForWildcard
method cannot handle an index pattern that contains patterns that do not match indices. The Security Solutions team needs to define a pattern list that will work whether or not the user has the matching indices for each pattern on the list.For example, given the pattern
auditbeat-*,fakebeat-*
:Adding a validation check in
IndexPatternsFetcher.getFieldsForWildcard
for each pattern and only querying patterns that match indices fixes the issue:Checklist
For maintainers