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

[Security Solution] Use authc.getCurrentUser from core.security in browser #187042

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Jun 27, 2024

follows #187004

Summary

This PR migrates the Security Solution Plugin's browser-side code that consume authc.getCurrentUser to use coreStart.security

Background: This PR serves as an example of a plugin migrating away from depending on the Security plugin, which is a high priority effort for the last release before 9.0.

Checklist

Delete any items that are not applicable to this PR.

@tsullivan tsullivan added release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. labels Jun 27, 2024
@tsullivan tsullivan force-pushed the security-in-core/security-solution-server-plugin-browser branch from a952436 to c64368f Compare June 28, 2024 00:15
@tsullivan tsullivan marked this pull request as ready for review June 28, 2024 00:15
@tsullivan tsullivan requested review from a team as code owners June 28, 2024 00:15
@tsullivan tsullivan requested review from pzl and joeypoon June 28, 2024 00:15
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@tsullivan
Copy link
Member Author

/ci

@tsullivan tsullivan force-pushed the security-in-core/security-solution-server-plugin-browser branch from c64368f to aa82d28 Compare June 28, 2024 00:17
lookupRealm: { name: '', type: '' },
authenticationProvider: '',
});
const response = await security.authc.getCurrentUser();
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the else because it would have been dead code. SecurityServiceStart comes from CoreStart and is always present.

@tsullivan tsullivan requested a review from TinaHeiligers June 28, 2024 00:18
@tsullivan
Copy link
Member Author

/ci

@pzl pzl requested review from paul-tavares and removed request for pzl June 28, 2024 11:53
Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

LGTM on CI green

@kibana-ci
Copy link
Collaborator

kibana-ci commented Jun 29, 2024

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #49 / @skipInServerless endpoint @ess @serverless When on the Endpoint Policy Details Page when on Ingest Policy Edit Package Policy page should allow updates to policy items
  • [job] [logs] FTR Configs #49 / @skipInServerless endpoint @ess @serverless When on the Endpoint Policy Details Page when on Ingest Policy Edit Package Policy page should allow updates to policy items

Metrics [docs]

Async chunks

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

id before after diff
securitySolution 15.5MB 15.5MB -256.0B

Page load bundle

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

id before after diff
securitySolution 83.6KB 83.6KB +7.0B
Unknown metric groups

References to deprecated APIs

id before after diff
securitySolution 571 569 -2

History

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

@tsullivan
Copy link
Member Author

The functional tests failures currently in this PR are pointing to an issue in the code that is hard to debug. In the following code change:

-  const { security } = useKibana().services;
+  const { securityService: security } = useKibana().services;

We expect that the securityService field of StartServices is available from services that have been passed to KibanaContextProvider. However, somewhere in the code there is a call KibanaContextProvider that doesn't have that field. Ideally, a problem like this would be caught by in type-check, but KibanaContextProvider isn't type-safe. The solution would be to restructure the code to use specific providers and hooks, and avoid using useKibana for services that come from plugins.

Example:
In a high-level application tsx:

<SecuritySolutionProvider services={{ securityService: coreStart.security, ... }}>
  // ... application code
</SecuritySolutionProvider>

In a low-level lib:

const { securityService } = useSecuritySolution(); // the services coming out of this hook would be guaranteed to exist

This is the same complication that I encountered with #187190. Same as that PR, I'm choosing to close this PR for now.

@tsullivan tsullivan closed this Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants