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 into Core] expose authc.getCurrentUser from core.security #177976

Merged
merged 52 commits into from
Mar 14, 2024

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Mar 5, 2024

Summary

First part of #174578

  • Introduce the new security core service, both on the browser and server-side.
    • In this first stage, this service only has a single API: authc.getCurrentUser
  • Have the security plugin register its API to Core for ex-exposition

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet pgayvallet added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! Feature:Security/Authentication Platform Security - Authentication release_note:skip Skip the PR/issue when compiling release notes v8.14.0 labels Mar 5, 2024
@pgayvallet
Copy link
Contributor Author

/ci

17 similar comments
@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet pgayvallet requested review from a team as code owners March 8, 2024 08:16
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

Copy link
Contributor

@juliaElastic juliaElastic left a comment

Choose a reason for hiding this comment

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

Fleet change LGTM

@botelastic botelastic bot added the Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team label Mar 8, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

Copy link
Member

@jgowdyelastic jgowdyelastic left a comment

Choose a reason for hiding this comment

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

ML changes LGTM

@legrego legrego requested a review from azasypkin March 8, 2024 15:49
Copy link
Contributor

@smith smith left a comment

Choose a reason for hiding this comment

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

Obs Exploratory view change looks good.

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.

Great start to moving security to core and thanks for making it easier to implement future changes to the packages.

I left a few non-blocking comments and questions around co-owners.

Nothing stands out that would prevent merging once all reviews are in.

LGTM

.github/CODEOWNERS Show resolved Hide resolved
Comment on lines 12 to 17
export const convertSecurityApi = (
privateApi: CoreInternalSecurityContract
): InternalSecurityServiceStart => {
// shapes are the same for now given we only have one API exposed.
return privateApi;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Double checking if I'm still following our intension: The contracts will diverge because we're not going to expose all of the security API's, correct?

Comment on lines +11 to +12
export type InternalSecurityServiceSetup = SecurityServiceSetup;
export type InternalSecurityServiceStart = SecurityServiceStart;
Copy link
Contributor

Choose a reason for hiding this comment

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

Double checking: They'll diverge because we only intend to expose authc and authz API's and not the full set that the security plugin currently exposes.

Comment on lines 11 to 19
/**
* The internal contract exposed by the security provider for Core to
* consume and re-expose via its security service.
*
* @public
*/
export interface CoreInternalSecurityContract {
authc: InternalAuthenticationServiceContract;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The types exposed from *-browser and *-server packages are intended to be public. Why then are we including Internal in CoreInternalSecurityContract and not using CoreSecurityContract?

Comment on lines 79 to 82
const services = {
...coreStart,
data,
maps,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we anticipate side effects from having security accessible in two ways? The reordering makes sense here because we'll overwrite core.security with security from the plugin. Once we start diverging the API's exposed from these, there might be some confusion as to why the API's (and types etc) are accessible from both. Unless, of course, we're moving the API's from the security plugin to core's security package.

Comment on lines 109 to +111
const core: Partial<CoreStart & ExploratoryViewPublicPluginsStart> = {
...defaultCore,
security: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

We're not going to expose all the types anyway. It's best to do that now.

*/
export interface SecurityServiceSetup {
/**
* Register the security implementation that then will be used and re-exposed by Core.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Register the security implementation that then will be used and re-exposed by Core.
* Register the security implementation that will be used by core and re-exposed from Core's security service.

Minor change to specify the intention of moving some pieces to core

/**
* Register the security implementation that then will be used and re-exposed by Core.
*
* @remark this should **exclusively** be used by the security plugin.
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish we had a simple-ish way of enforcing this....
💡 can we use a hash map perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we discussed about this, (iirc) we came to the conclusion that it was fine to not do any hard-checks, because

  1. it's already possible to hook up into security by mimicking what the security plugin does today
  2. the implementation remains in "xpack licensed" code
  3. ideally we would be avoided doing hard checks on plugin ids (and also it isn't really protecting against 3rd party replacement as they could just the same pluginId as our internal security plugin...

I'll let @elastic/kibana-security confirms that it's still fine

Copy link
Member

Choose a reason for hiding this comment

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

I'll let @elastic/kibana-security confirms that it's still fine

Yeah, I believe it's fine to keep what we have now. There are so many hurdles and restrictions at various levels to replace the built-in Security plugin with any alternative implementation that it sounds impractical for anyone to even consider.

Comment on lines +50 to +54
#elasticsearch?: CoreElasticsearchRouteHandlerContext;
#savedObjects?: CoreSavedObjectsRouteHandlerContext;
#uiSettings?: CoreUiSettingsRouteHandlerContext;
#deprecations?: CoreDeprecationsRouteHandlerContext;
#security?: CoreSecurityRouteHandlerContext;
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

{
"type": "shared-common",
"id": "@kbn/core-security-common",
"owner": "@elastic/kibana-core"
Copy link
Contributor

Choose a reason for hiding this comment

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

Kibana security owns @kbn/security-plugin-types-common. Should we add them as co-owners to catch unintended changes to the types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good remark, Any objections @elastic/kibana-security?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, commented in a different place. Yes, I agree, let's make our team as co-owners for this package.

@azasypkin
Copy link
Member

ACK: I'll start reviewing today, sorry for the delay!

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

Looks great, thank you! Just left a few notes.

Comment on lines +50 to +54
#elasticsearch?: CoreElasticsearchRouteHandlerContext;
#savedObjects?: CoreSavedObjectsRouteHandlerContext;
#uiSettings?: CoreUiSettingsRouteHandlerContext;
#deprecations?: CoreDeprecationsRouteHandlerContext;
#security?: CoreSecurityRouteHandlerContext;
Copy link
Member

Choose a reason for hiding this comment

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

Off-topic: Oh, native private fields. I remember there was some performance hit (around 2-3 years ago) related to them. Have things improved, and are private fields ready for wider adoption in Kibana now?

@@ -31,6 +32,7 @@ export interface CoreRequestHandlerContext {
elasticsearch: ElasticsearchRequestHandlerContext;
uiSettings: UiSettingsRequestHandlerContext;
deprecations: DeprecationsRequestHandlerContext;
security: SecurityRequestHandlerContext;
Copy link
Member

Choose a reason for hiding this comment

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

question: Thanks for adding security to the request context! Would you be open, in this PR, to update a single route (/me) in the Security plugin to use the Core's request context so that we have a real usage example (literally almost all tests in Security and beyond rely on this route, so it'd be a great indicator that everything works as expected)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was somewhat concerned that the PR didn't add/change any FTR tests, so I think this is a great idea.

{
"type": "shared-common",
"id": "@kbn/core-security-common",
"owner": "@elastic/kibana-core"
Copy link
Member

Choose a reason for hiding this comment

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

Ah, commented in a different place. Yes, I agree, let's make our team as co-owners for this package.

/**
* Register the security implementation that then will be used and re-exposed by Core.
*
* @remark this should **exclusively** be used by the security plugin.
Copy link
Member

Choose a reason for hiding this comment

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

I'll let @elastic/kibana-security confirms that it's still fine

Yeah, I believe it's fine to keep what we have now. There are so many hurdles and restrictions at various levels to replace the built-in Security plugin with any alternative implementation that it sounds impractical for anyone to even consider.

@pgayvallet pgayvallet enabled auto-merge (squash) March 14, 2024 07:55
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
core 504 509 +5
security 502 503 +1
total +6

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
@kbn/core-http-request-handler-context-server 11 12 +1
@kbn/core-security-browser - 3 +3
@kbn/core-security-browser-internal - 8 +8
@kbn/core-security-browser-mocks - 6 +6
@kbn/core-security-common - 6 +6
@kbn/core-security-server - 7 +7
@kbn/core-security-server-internal - 14 +14
@kbn/core-security-server-mocks - 7 +7
total +52

Page load bundle

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

id before after diff
core 387.8KB 388.6KB +829.0B
security 65.0KB 65.1KB +117.0B
total +946.0B
Unknown metric groups

API count

id before after diff
@kbn/core-http-request-handler-context-server 14 15 +1
@kbn/core-lifecycle-browser 32 34 +2
@kbn/core-lifecycle-server 36 38 +2
@kbn/core-security-browser - 10 +10
@kbn/core-security-browser-internal - 8 +8
@kbn/core-security-browser-mocks - 6 +6
@kbn/core-security-common - 20 +20
@kbn/core-security-server - 15 +15
@kbn/core-security-server-internal - 14 +14
@kbn/core-security-server-mocks - 7 +7
total +85

History

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

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 Feature:Security/Authentication Platform Security - Authentication release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants