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

Make the Chrome project API "protected" for the Serverless plugin #157307

Merged
merged 5 commits into from
May 16, 2023

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented May 10, 2023

Summary

Addresses #156600 (comment)

Let's think if there is a way to throw an error when core chrome api are called from invalid plugins (in this cases only the serverless plugin would be allowed.

This PR can be a starting point for discussion on the behavior we really want. This PR has a simple goal to ensure that non-serverless plugins do not call the chrome.projects API. However, it's not complete security, as the compile-time error would be easy to override.

cc @sebelga @Dosant @clintandrewhall



Checklist

Delete any items that are not applicable to this PR.

@tsullivan tsullivan changed the title Set the Chrome project API as protected for Serverless plugin Make the Chrome project API as "protected for Serverless plugin May 10, 2023
@tsullivan tsullivan changed the title Make the Chrome project API as "protected for Serverless plugin Make the Chrome project API "protected for usage only by the Serverless plugin May 10, 2023
): ServerlessSearchPluginStart {
core.chrome.project.setSideNavComponent(createComponent(core));
serverless.setSideNavComponent(createComponent(core));
Copy link
Member Author

Choose a reason for hiding this comment

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

@tsullivan tsullivan force-pushed the serverless/chrome-protected branch from 2bb0753 to 26e462c Compare May 10, 2023 18:02
@tsullivan tsullivan force-pushed the serverless/chrome-protected branch from 26e462c to 060f94a Compare May 11, 2023 19:46
@tsullivan tsullivan marked this pull request as ready for review May 11, 2023 19:47
@tsullivan tsullivan requested a review from a team as a code owner May 11, 2023 19:47
@tsullivan tsullivan added release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) Project:Serverless Work as part of the Serverless project for its initial release labels May 11, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/appex-sharedux (Team:SharedUX)

@tsullivan tsullivan requested review from kpatticha and sphilipse May 11, 2023 20:03
@tsullivan tsullivan changed the title Make the Chrome project API "protected for usage only by the Serverless plugin Make the Chrome project API "protected" for the Serverless plugin May 11, 2023
Copy link
Contributor

@clintandrewhall clintandrewhall left a comment

Choose a reason for hiding this comment

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

Great work.

@@ -64,7 +63,8 @@ export class ServerlessPlugin

return {
setSideNavComponent: (sideNavigationComponent) =>
core.chrome.project.setSideNavComponent(sideNavigationComponent),
// Casting the "chrome.projects" service to an "internal" type: it's intentional to call the service only from here.
(core.chrome as InternalChromeStart).project.setSideNavComponent(sideNavigationComponent),
Copy link
Contributor

Choose a reason for hiding this comment

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

We should couple this with a throw on these methods if chromeStyle is not set properly.

Copy link
Member Author

@tsullivan tsullivan May 15, 2023

Choose a reason for hiding this comment

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

@@ -64,7 +63,8 @@ export class ServerlessPlugin

return {
setSideNavComponent: (sideNavigationComponent) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I've always disliked abbreviations, (and Component feels redundant, as the parameter is a React component)... perhaps we could consider setSidebarNavigation...?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree w/ you, but serverless.setSideNavComponent already has presence in the 3 serverless project plugins. Let's find a new name at our next sync and change this in a standalone PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

setSidebarNavigation() is reserved (™) and will be used when there is no need to provide a component (UI) (define the navigation through an object - see first example in Proposal #157702).
Well actually it will even be shorter: setNavigation() 😊

I do think "Component" is explicit of the intent. It could be "UI" suffix instead.

@tsullivan tsullivan requested a review from a team May 15, 2023 22:24
@tsullivan tsullivan enabled auto-merge (squash) May 15, 2023 22:48
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #12 / home app add data tutorials directory should redirect to integrations app

Metrics [docs]

Page load bundle

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

id before after diff
core 365.1KB 365.4KB +314.0B
serverless 5.0KB 5.1KB +10.0B
serverlessSearch 23.3KB 23.3KB -2.0B
total +322.0B
Unknown metric groups

API count

id before after diff
@kbn/core-chrome-browser 136 135 -1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
securitySolution 400 404 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
securitySolution 480 484 +4
total +6

History

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

Copy link
Contributor

@TattdCodeMonkey TattdCodeMonkey left a comment

Choose a reason for hiding this comment

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

LGTM

@tsullivan tsullivan merged commit 4805421 into elastic:main May 16, 2023
@kibanamachine kibanamachine added v8.9.0 backport:skip This commit does not require backporting labels May 16, 2023
jasonrhodes pushed a commit that referenced this pull request May 17, 2023
…57307)

## Summary

Addresses
#156600 (comment)

> Let's think if there is a way to throw an error when core chrome api
are called from invalid plugins (in this cases only the serverless
plugin would be allowed.

This PR can be a starting point for discussion on the behavior we really
want. This PR has a simple goal to ensure that non-serverless plugins do
not call the `chrome.projects` API. However, it's not complete security,
as the compile-time error would be easy to override.

cc @sebelga @Dosant @clintandrewhall 

---
---


### Checklist

Delete any items that are not applicable to this PR.

- [x] Documentation was added for features that require explanation or
tutorials
Internal documentation:
https://docs.google.com/document/d/1ew8KYl6ROs_V7jeIXgeP_C9YgkYK2IPtuceo6KVF_jE/edit#

---------

Co-authored-by: Clint Andrew Hall <clint@clintandrewhall.com>
@tsullivan tsullivan deleted the serverless/chrome-protected branch November 21, 2023 23:24
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 Project:Serverless Work as part of the Serverless project for its initial release release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants