-
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] Support Fleet server system indices #89372
Merged
nchaulet
merged 20 commits into
elastic:master
from
nchaulet:feature-fleet-server-agent-routes
Feb 7, 2021
Merged
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
007690f
[Fleet] Install the Fleet Server package during setup
nchaulet 9e777e5
[Fleet] Support fleet server indices in agent routes ack, checkin, en…
nchaulet 11c7d5f
Merge branch 'master' of github.com:elastic/kibana into feature-fleet…
nchaulet 71b1942
Fix tests
nchaulet c59780a
Fix tests
nchaulet 59f9feb
Merge branch 'master' of github.com:elastic/kibana into feature-fleet…
nchaulet 9cf6cdd
Merge branch 'master' of github.com:elastic/kibana into feature-fleet…
nchaulet 8544acc
Merge branch 'master' of github.com:elastic/kibana into feature-fleet…
nchaulet ef9c9b6
Fix merge conflic
nchaulet faf4e65
Merge branch 'master' of github.com:elastic/kibana into feature-fleet…
nchaulet a4aa34b
Fix reassignment and unenroll delay
nchaulet 9749bb4
Fix ESSearchResponse type and action expiration
nchaulet c8e1f15
Handle bulk update errors
nchaulet 8e03379
Merge branch 'master' of github.com:elastic/kibana into feature-fleet…
nchaulet 9fa440b
Merge branch 'master' of github.com:elastic/kibana into feature-fleet…
nchaulet 3c839bb
Fix kuery issues after mergin master
nchaulet 8dd23bf
Merge branch 'master' of github.com:elastic/kibana into feature-fleet…
nchaulet 288c861
Fix tests after merge
nchaulet 915cea6
Merge branch 'master' of github.com:elastic/kibana into feature-fleet…
nchaulet 34af5f7
Merge branch 'master' into feature-fleet-server-agent-routes
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,43 +7,16 @@ | |
|
||
import uuid from 'uuid'; | ||
import Boom from '@hapi/boom'; | ||
import { GetResponse } from 'elasticsearch'; | ||
import { ResponseError } from '@elastic/elasticsearch/lib/errors'; | ||
import { SavedObjectsClientContract, ElasticsearchClient } from 'src/core/server'; | ||
import { ESSearchResponse as SearchResponse } from '../../../../../typings/elasticsearch'; | ||
import { EnrollmentAPIKey, FleetServerEnrollmentAPIKey } from '../../types'; | ||
import { ENROLLMENT_API_KEYS_INDEX } from '../../constants'; | ||
import { createAPIKey, invalidateAPIKeys } from './security'; | ||
import { agentPolicyService } from '../agent_policy'; | ||
import { escapeSearchQueryPhrase } from '../saved_object'; | ||
|
||
// TODO Move these types to another file | ||
interface SearchResponse<T> { | ||
took: number; | ||
timed_out: boolean; | ||
_scroll_id?: string; | ||
hits: { | ||
total: { | ||
value: number; | ||
relation: string; | ||
}; | ||
max_score: number; | ||
hits: Array<{ | ||
_index: string; | ||
_type: string; | ||
_id: string; | ||
_score: number; | ||
_source: T; | ||
_version?: number; | ||
fields?: any; | ||
highlight?: any; | ||
inner_hits?: any; | ||
matched_queries?: string[]; | ||
sort?: string[]; | ||
}>; | ||
}; | ||
} | ||
|
||
type SearchHit<T> = SearchResponse<T>['hits']['hits'][0]; | ||
|
||
export async function listEnrollmentApiKeys( | ||
esClient: ElasticsearchClient, | ||
options: { | ||
|
@@ -55,7 +28,7 @@ export async function listEnrollmentApiKeys( | |
): Promise<{ items: EnrollmentAPIKey[]; total: any; page: any; perPage: any }> { | ||
const { page = 1, perPage = 20, kuery } = options; | ||
|
||
const res = await esClient.search<SearchResponse<FleetServerEnrollmentAPIKey>>({ | ||
const res = await esClient.search<SearchResponse<FleetServerEnrollmentAPIKey, {}>>({ | ||
index: ENROLLMENT_API_KEYS_INDEX, | ||
from: (page - 1) * perPage, | ||
size: perPage, | ||
|
@@ -79,7 +52,7 @@ export async function getEnrollmentAPIKey( | |
id: string | ||
): Promise<EnrollmentAPIKey> { | ||
try { | ||
const res = await esClient.get<SearchHit<FleetServerEnrollmentAPIKey>>({ | ||
const res = await esClient.get<GetResponse<FleetServerEnrollmentAPIKey>>({ | ||
index: ENROLLMENT_API_KEYS_INDEX, | ||
id, | ||
}); | ||
|
@@ -187,7 +160,7 @@ export async function generateEnrollmentAPIKey( | |
} | ||
|
||
export async function getEnrollmentAPIKeyById(esClient: ElasticsearchClient, apiKeyId: string) { | ||
const res = await esClient.search<SearchResponse<FleetServerEnrollmentAPIKey>>({ | ||
const res = await esClient.search<SearchResponse<FleetServerEnrollmentAPIKey, {}>>({ | ||
index: ENROLLMENT_API_KEYS_INDEX, | ||
q: `api_key_id:${escapeSearchQueryPhrase(apiKeyId)}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once we move completely over to Fleet indices I think it would be nicer to use |
||
}); | ||
|
@@ -212,7 +185,10 @@ async function validateAgentPolicyId(soClient: SavedObjectsClientContract, agent | |
} | ||
} | ||
|
||
function esDocToEnrollmentApiKey(doc: SearchHit<FleetServerEnrollmentAPIKey>): EnrollmentAPIKey { | ||
function esDocToEnrollmentApiKey(doc: { | ||
_id: string; | ||
_source: FleetServerEnrollmentAPIKey; | ||
}): EnrollmentAPIKey { | ||
return { | ||
id: doc._id, | ||
...doc._source, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
wow that's a long expiration! 😄 what does tell fleet server to do?
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.
It's mandatory for Fleet server actions to have an expiration, it just say if the agent connect after more than 1 month to fleet server the agent will not get the action.