-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution][Endpoint][Admin][Policy List] GET endpoint package policy api #119545
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
Changes from 6 commits
74ba729
b195533
a0e7470
b4cbe40
074a51f
efb6b85
06fc5cb
dbd2072
e8497a1
8df1bc9
7f672d3
c4b4845
d52464a
c885bb5
7405ead
7c189d1
d1e827a
14980a1
7a7ae9b
1695276
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |||||
| */ | ||||||
|
|
||||||
| import { schema } from '@kbn/config-schema'; | ||||||
| import type { TypeOf } from '@kbn/config-schema'; | ||||||
|
|
||||||
| export const GetPolicyResponseSchema = { | ||||||
| query: schema.object({ | ||||||
|
|
@@ -19,3 +20,21 @@ export const GetAgentPolicySummaryRequestSchema = { | |||||
| policy_id: schema.nullable(schema.string()), | ||||||
| }), | ||||||
| }; | ||||||
|
|
||||||
| const ListWithKuerySchema = schema.object({ | ||||||
| page: schema.maybe(schema.number({ defaultValue: 1 })), | ||||||
| perPage: schema.maybe(schema.number({ defaultValue: 20 })), | ||||||
|
Member
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. can we rename this to pageSize for consistency
|
||||||
| sortField: schema.maybe(schema.string()), | ||||||
|
Member
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. I think we agreed on |
||||||
| sortOrder: schema.maybe(schema.oneOf([schema.literal('desc'), schema.literal('asc')])), | ||||||
| showUpgradeable: schema.maybe(schema.boolean()), | ||||||
| kuery: schema.maybe( | ||||||
| schema.oneOf([ | ||||||
| schema.string(), | ||||||
| schema.any(), // KueryNode | ||||||
| ]) | ||||||
| ), | ||||||
| }); | ||||||
|
|
||||||
| export const GetEndpointPackagePolicyRequestSchema = { | ||||||
| query: ListWithKuerySchema, | ||||||
| }; | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,10 @@ import { | |||||||||||||||||||
| import { EndpointAppContext } from '../../types'; | ||||||||||||||||||||
| import { getAgentPolicySummary, getPolicyResponseByAgentId } from './service'; | ||||||||||||||||||||
| import { GetAgentSummaryResponse } from '../../../../common/endpoint/types'; | ||||||||||||||||||||
| import { GetPackagePoliciesRequest } from '../../../../../fleet/common/types/rest_spec'; | ||||||||||||||||||||
| import { EndpointError } from '../../../../common/endpoint/errors'; | ||||||||||||||||||||
| import { wrapErrorIfNeeded } from '../../utils'; | ||||||||||||||||||||
| import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../../fleet/common'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export const getHostPolicyResponseHandler = function (): RequestHandler< | ||||||||||||||||||||
| undefined, | ||||||||||||||||||||
|
|
@@ -63,3 +67,25 @@ export const getAgentPolicySummaryHandler = function ( | |||||||||||||||||||
| }); | ||||||||||||||||||||
| }; | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export const getPolicyListHandler = function ( | ||||||||||||||||||||
| endpointAppContext: EndpointAppContext | ||||||||||||||||||||
| ): RequestHandler<undefined, GetPackagePoliciesRequest['query'], undefined> { | ||||||||||||||||||||
| return async (context, request, response) => { | ||||||||||||||||||||
| const soClient = context.core.savedObjects.client; | ||||||||||||||||||||
| const packagePolicyService = endpointAppContext.service.getPackagePolicyService(); | ||||||||||||||||||||
| const endpointFilteredKuery = `${ | ||||||||||||||||||||
|
Contributor
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. This does not look correct - you need to ensure that both side of the
Suggested change
Here is a test that you can do to see why this is important (note: i did not actually execute this, but you should be able to and get the results I'm thinking you should get):
This will likely match and return package policies for
Contributor
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. I worked with @parkiino yesterday on this and we validated that what i thought was going to happen (retrieval of non-endpoint package policies) did not actually happen. that's because even if a user of the API ends their |
||||||||||||||||||||
| request?.query?.kuery ? `${request.query.kuery} and ` : '' | ||||||||||||||||||||
| }${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: endpoint`; | ||||||||||||||||||||
| request.query.kuery = endpointFilteredKuery; | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| const listResponse = await packagePolicyService.list(soClient, request.query); | ||||||||||||||||||||
|
Contributor
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. See my prior comment around ensuring we are not creating a path to retrieve non-endpoint packages with this API. All calls to this API need to ensure they are being wrapped with a filter that looks only at endpoint integrations. I'm ok if you want to do that here for now, but we may want to create a service module in our code base that can do that. |
||||||||||||||||||||
|
|
||||||||||||||||||||
| return response.ok({ | ||||||||||||||||||||
| body: listResponse, | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||
| throw wrapErrorIfNeeded(error); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+72
to
+97
Contributor
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. this should be wrapped in a
Suggested change
Which does a few thing:
|
||||||||||||||||||||
| }; | ||||||||||||||||||||
| }; | ||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
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 tests for these. I have a suspicion that these default values might not work since they're wrapped in a maybe.
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.
example schema tests: https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/common/endpoint/schema/metadata.test.ts.