Skip to content
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] Uninstalltoken saved object namespace agnostic and space aware #190741

Merged
merged 9 commits into from
Aug 28, 2024

Conversation

nchaulet
Copy link
Member

@nchaulet nchaulet commented Aug 19, 2024

Summary

Related to #184864

To avoid being in a state where user cannot uninstall their agent, that PR change the way we handle uninstall token for space awareness:

  • The uninstalltoken saved object stay space agnostic, but we had a namespaces attributes
  • We enforce the space check in the uninstall token service (the scope is relatively safe as their is only two public API reaching for those saved object)

Tests

Manually tests, you can enable space awareness by adding the flag to your config

xpack.fleet.enableExperimental: ['useSpaceAwareness']

Then using the API to opt-in for the feature

curl -u elastic:changeme -XPOST "http://localhost:5601/internal/fleet/enable_space_awareness" -H "kbn-xsrf: reporting" -H 'elastic-api-version: 1'

Then you can test creating policies in different space, create uninstall tokens only accessible in their respective space.

@nchaulet nchaulet added release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team labels Aug 19, 2024
@obltmachine
Copy link

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@nchaulet
Copy link
Member Author

/ci

kibanamachine and others added 3 commits August 19, 2024 20:50
… src/core/server/integration_tests/ci_checks'
…haulet/kibana into feature-uninstall-tokens-space-aware
@nchaulet
Copy link
Member Author

/ci

@nchaulet nchaulet self-assigned this Aug 20, 2024
@nchaulet nchaulet marked this pull request as ready for review August 20, 2024 13:24
@nchaulet nchaulet requested review from a team as code owners August 20, 2024 13:24
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@jeramysoucy jeramysoucy self-requested a review August 21, 2024 10:01
@@ -986,7 +986,7 @@ export const getSavedObjectTypes = (
name: MESSAGE_SIGNING_KEYS_SAVED_OBJECT_TYPE,
indexPattern: INGEST_SAVED_OBJECT_INDEX,
hidden: true,
namespaceType: useSpaceAwareness ? 'single' : 'agnostic',
namespaceType: 'agnostic',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the useSpaceAwareness experimental feature potentially being used anywhere of consequence (by customers, internal deployments, etc)?

Single space ESOs use the object's namespace when constructing AAD. Any instances of Kibana where useSpaceAwareness is active, that then upgrade to a version with this change, would cause existing message signing keys and uninstall token objects to be undecryptable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No useSpaceAwareness is not used in any long standing deployment, the feature is still in development, we used that feature flag more as an integration branch for now than a real feature flag

const tokenObjects = await this.getDecryptedTokenObjects({ filter });
const useSpaceAwareness = this.isScoped && (await isSpaceAwarenessEnabled());
const namespaceFilter = useSpaceAwareness
? getNamespaceFiltering(this.soClient.getCurrentNamespace() ?? DEFAULT_SPACE_ID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 676, the SO client is being initialized without the spaces extension. The return value for the call to getCurrentNamespace with no parameter will always be undefined. What is the intended behavior here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use that non space aware so client only when our service is not scoped (this.isScoped = false) (for background task, fleet setup) and if the service is not scoped we are not doing filtering see the line above. This is covered by integration test, but I could add some unit tests to make that behaviour more obvious.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh...thank you! I missed that.

@@ -9,7 +9,11 @@ import { createHash } from 'crypto';

import type { KibanaRequest } from '@kbn/core-http-server';

import type { SavedObjectsClientContract } from '@kbn/core/server';
import {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some more tests here? It would be great to cover some of the functionalities added below. It will give us more confidence, for instance in the event of the feature flag clean up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added some in 6aa8e8b

@@ -61,6 +62,14 @@ interface UninstallTokenSOAggregation {
by_policy_id: AggregationsMultiBucketAggregateBase<UninstallTokenSOAggregationBucket>;
}

function getNamespaceFiltering(namespace: string) {
if (namespace === DEFAULT_NAMESPACE_STRING) {
return `(${UNINSTALL_TOKENS_SAVED_OBJECT_TYPE}.attributes.namespaces:default) or (not ${UNINSTALL_TOKENS_SAVED_OBJECT_TYPE}.attributes.namespaces:*)`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a clarification, is the condition after the or needed to filter out those having namespace = *? I'm not totally sure about this condition, what is going to match.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want the token in the default space, we need to filter by object either not having namespaces set or where namespaces include `default, does it make sense to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't going to match also everything else that has any namespace set because of the wildcard *? But maybe I'm misunderstanding how this works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the condition is not namespaces:* easy to miss the not here

Copy link
Contributor

@criamico criamico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢

@nchaulet
Copy link
Member Author

@elasticmachine merge upstream

@nchaulet nchaulet requested a review from pgayvallet August 23, 2024 14:13
@nchaulet
Copy link
Member Author

@elasticmachine merge upstream

@nchaulet
Copy link
Member Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @nchaulet

@nchaulet nchaulet merged commit 2c50c45 into elastic:main Aug 28, 2024
25 checks passed
@nchaulet nchaulet deleted the feature-uninstall-tokens-space-aware branch August 28, 2024 12:20
@kibanamachine kibanamachine added v8.16.0 backport:skip This commit does not require backporting labels Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants