elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.76k stars 8.17k forks source link

[Fleet] Make Fleet agents write APIs space aware #185040

Closed nchaulet closed 1 month ago

nchaulet commented 3 months ago

Description

Related to https://github.com/elastic/ingest-dev/issues/2893 Similar to https://github.com/elastic/kibana/pull/184869

As part of making Fleet space aware we should make the Fleet agent APIs space aware (the read API should already be done in https://github.com/elastic/kibana/pull/184869)

Details

When the useSpaceAwareness feature flag is enabled we shoud do:

Access validation

For every API we should ensure the user only access agent in the current space, this mean:

The saved object client used in those API should be scoped to the current space (if we need an internal client we could use appContextService.getInternalUserSOClientForSpaceId(spaceId?), this should ensure we access related object like agent policy in the same space only.

Write namespaces for related action

All the .fleet-actions and .fleet-action-results should be created with the namespaces: [currentSpaceId] property

APIs

Agent Action

Agents Bulk API

Agent Misc

Agent Actions

Implementation details/guideline

With a scoped saved objet client space could be retrieved with the soClient.getCurrentNamespace()

To write API integration test for this, I created a new tests suite with the space awarness flag enabled in x-pack/test/fleet_api_integration/apis/space_awarness/

elasticmachine commented 3 months ago

Pinging @elastic/fleet (Team:Fleet)