Skip to content

Commit 6300b14

Browse files
authored
[Security Solution][Endpoint] Update additional endpoint management APIs to support spaces (#224141)
## Summary - Update the Action Status summary api to validate that agent IDs provided on the request are accessible from the space
1 parent d67c527 commit 6300b14

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/status.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import type {
3636
import { EndpointActionGenerator } from '../../../../common/endpoint/data_generators/endpoint_action_generator';
3737
import { ActionStatusRequestSchema } from '../../../../common/api/endpoint';
3838
import { AGENT_ACTIONS_RESULTS_INDEX } from '@kbn/fleet-plugin/common';
39+
import { AgentNotFoundError } from '@kbn/fleet-plugin/server';
3940

4041
describe('Endpoint Pending Action Summary API', () => {
4142
let endpointAppContextService: EndpointAppContextService;
@@ -395,4 +396,17 @@ describe('Endpoint Pending Action Summary API', () => {
395396
},
396397
});
397398
});
399+
400+
it('should return 404 when spaces is enabled and agent id is not accessible in space', async () => {
401+
// @ts-expect-error
402+
endpointAppContextService.experimentalFeatures.endpointManagementSpaceAwarenessEnabled = true;
403+
(
404+
endpointAppContextService.getInternalFleetServices().agent.getByIds as jest.Mock
405+
).mockRejectedValue(new AgentNotFoundError('agent not found'));
406+
const response = await getPendingStatus({
407+
query: { agent_ids: ['123'] },
408+
});
409+
410+
expect(response.notFound).toHaveBeenCalled();
411+
});
398412
});

x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/status.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ export const actionStatusRequestHandler = function (
7272
? [...new Set(req.query.agent_ids)]
7373
: [req.query.agent_ids];
7474

75+
if (endpointContext.service.experimentalFeatures.endpointManagementSpaceAwarenessEnabled) {
76+
await endpointContext.service
77+
.getInternalFleetServices(spaceId)
78+
.ensureInCurrentSpace({ agentIds: agentIDs });
79+
}
80+
7581
const response = await getPendingActionsSummary(endpointContext.service, spaceId, agentIDs);
7682

7783
return res.ok({

0 commit comments

Comments
 (0)