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

[SecuritySolution] Register AI Assistant management settings according to productFeatureKeys #213105

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

angorayc
Copy link
Contributor

@angorayc angorayc commented Mar 4, 2025

Summary

Fixes: #212667

AI Assistant management is registered according to productFeatureKeys set by security_solution_ess or security_solution_serverless plugin.

To verify:

  • Security project
yarn es serverless --projectType security --kill --clean -E  —ssl xpack.security.authc.api_key.enabled=true
yarn serverless-security --no-base-path

Update xpack.securitySolutionServerless.productTypes in config/serverless.security.yml to switch between essentials and complete tier

Project essentials:

Screenshot 2025-03-04 at 17 05 59

Project complete:

Screenshot 2025-03-04 at 17 07 16
  • ESS

License trial and enterprise:

yarn es snapshot --license trial -E xpack.security.authc.api_key.enabled=true -E discovery.type=single-node -E network.host=0.0.0.0

Screen.Recording.2025-03-04.at.17.24.35.mov

License basic and others:

yarn es snapshot --license basic -E xpack.security.authc.api_key.enabled=true -E discovery.type=single-node -E network.host=0.0.0.0

Screen.Recording.2025-03-04.at.17.27.35.mov


this.experimentalFeatures = parseExperimentalConfigValue(
this.config.enableExperimental,
securitySolution.experimentalFeatures
).features;

console.log('serverless setup: setProductFeatureKeys====== ')
securitySolution.setProductFeatureKeys(getProductProductFeatures(productTypes));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It setProductFeatureKeys correctly for complete and essential tiers.

console.log('productFeatureKeys---',productFeatureKeys);
// This seemed to work with serverless but not sure how to deal with ess productFeatureKeys

const isInProductFeatureKeys = productFeatureKeys && productFeatureKeys.length > 0 && productFeatureKeys.includes(ProductFeatureAssistantKey.assistant);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Running sequence - serverless complete:

Screenshot 2025-03-04 at 14 35 07 Screenshot 2025-03-04 at 14 35 34

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Running sequence - serverless essentials:

Screenshot 2025-03-04 at 14 38 31 Screenshot 2025-03-04 at 14 38 20

console.log('productFeatureKeys---',productFeatureKeys);
// This seemed to work with serverless but not sure how to deal with ess productFeatureKeys

const isInProductFeatureKeys = productFeatureKeys && productFeatureKeys.length > 0 && productFeatureKeys.includes(ProductFeatureAssistantKey.assistant);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we define the productFeatureKeys$ as a Set<ProductFeatureKeyType>, so we can do:

Suggested change
const isInProductFeatureKeys = productFeatureKeys && productFeatureKeys.length > 0 && productFeatureKeys.includes(ProductFeatureAssistantKey.assistant);
const isInProductFeatureKeys = productFeatureKeys?.has(ProductFeatureAssistantKey.assistant);

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have some control to prevent registering this twice, in case more values are emitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@angorayc angorayc changed the title set product feature keys [SecuritySolution] Register AI Assistant management settings according to productFeatureKeys Mar 4, 2025
@angorayc angorayc added bug Fixes for quality problems that affect the customer experience Team:Threat Hunting:Explore Team:Security Generative AI Security Generative AI backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) labels Mar 4, 2025
@kibanamachine
Copy link
Contributor

Project deployed, see credentials at: https://buildkite.com/elastic/kibana-deploy-project-from-pr/builds/351

angorayc and others added 4 commits March 5, 2025 10:33
…gin_contract.ts

Co-authored-by: Sergi Massaneda <sergi.massaneda@gmail.com>
…gin.tsx

Co-authored-by: Sergi Massaneda <sergi.massaneda@gmail.com>
@angorayc angorayc marked this pull request as ready for review March 5, 2025 11:33
@angorayc angorayc requested a review from a team as a code owner March 5, 2025 11:33
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting-explore (Team:Threat Hunting:Explore)

Copy link
Contributor

@semd semd left a comment

Choose a reason for hiding this comment

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

LGTM! 💯

@angorayc angorayc enabled auto-merge (squash) March 5, 2025 11:50
Comment on lines +210 to +212
const isAssistantAvailable =
productFeatureKeys?.has(ProductFeatureAssistantKey.assistant) &&
license?.hasAtLeast('enterprise');
Copy link
Contributor

@semd semd Mar 5, 2025

Choose a reason for hiding this comment

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

I just realized that if productFeatureKeys is still null, or the license is not defined yet, this code will behave as if the assistant is not available, disabling the assistant management.
Can we add a check for at the beginning?

Suggested change
const isAssistantAvailable =
productFeatureKeys?.has(ProductFeatureAssistantKey.assistant) &&
license?.hasAtLeast('enterprise');
if (!productFeatureKeys || !license) {
return;
}
const isAssistantAvailable =
productFeatureKeys.has(ProductFeatureAssistantKey.assistant) &&
license.hasAtLeast('enterprise');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that as long as we use BehaviorSubject with an initial value, it will always emit the initial value as the first emission. To avoid that, I'd like to replace BehaviorSubject with Subject so the first emission will be the productFeatureKeys from ESS/serverless.
combineLatestWith waits for both productFeatureKeys$ and license$ to emit at least once before emitting a combined value.
In this case, we should be able to always receive the non null values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using Subject the subscribe handler will be called only if it is registered before the first next call. If the next happens before the handler is subscribed, it will never be called.
To avoid that, I'm sticking to BehaviorSubject and check if productFeatureKeys and license exists.

@angorayc angorayc disabled auto-merge March 5, 2025 12:29
@angorayc angorayc added the release_note:skip Skip the PR/issue when compiling release notes label Mar 5, 2025
@elasticmachine
Copy link
Contributor

elasticmachine commented Mar 5, 2025

💔 Build Failed

Failed CI Steps

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolutionEss 90 93 +3

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
securitySolution 125 127 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 8.9MB 8.9MB -1.5KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
securitySolution 85.5KB 87.5KB +2.1KB
securitySolutionEss 13.6KB 15.2KB +1.6KB
securitySolutionServerless 31.7KB 31.7KB +74.0B
total +3.7KB
Unknown metric groups

API count

id before after diff
securitySolution 193 195 +2

References to deprecated APIs

id before after diff
securitySolution 351 352 +1

History

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) bug Fixes for quality problems that affect the customer experience ci:project-deploy-security Create a Security Serverless Project release_note:skip Skip the PR/issue when compiling release notes Team:Security Generative AI Security Generative AI Team:Threat Hunting:Explore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution] [Bug] AI Assistant for Security setting should not be available from an essential project
4 participants