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

Allow SOC wrappers to be excluded #40275

Merged
merged 7 commits into from
Jul 15, 2019
Merged

Conversation

legrego
Copy link
Member

@legrego legrego commented Jul 3, 2019

Summary

Currently, the saved objects client wrappers come as a transparent package that the consumers has no control over. This is very useful for most scenarios, where the consumer does not care how the client is augmented.

However, there are special cases (such as #37286) where bypassing specific wrappers is beneficial. In the case of #37286, excluding the spaces wrapper will allow us to implement an API endpoint which can work across multiple spaces, while still honoring the constraints placed by the security wrapper.

This PR adds an optional parameter when requesting a SOC instance which allows the consumer to specify which wrappers are to be excluded. See example here:

https://github.com/elastic/kibana/blob/816a3f457bf3e2debae3b8981ee1393029308a4f/x-pack/legacy/plugins/spaces/server/routes/api/v1/example.ts#L17:L19

@legrego
Copy link
Member Author

legrego commented Jul 3, 2019

@kobelb @skaapgif @restrry

Here is the POC we talked about which allows consumers to choose which SOC wrappers to exclude.

No tests yet, see example usage here: https://github.com/elastic/kibana/pull/40275/files#diff-1edef6db6e7b5243c656d0d63ea99d32

If we're all on board with this approach, then I'll add tests and get this ready for a proper review. Looking forward to your feedback!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@mshustov mshustov left a comment

Choose a reason for hiding this comment

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

The problem that I have reading this code is to understand the order of all wrappers. This knowledge is spread across the code base. Given the possibility to disable any wrapper I have even more combinations, as any client can specify any number of wrappers.

const { getScopedSavedObjectsClient } = savedObjects;

const savedObjectsClient = getScopedSavedObjectsClient(request, {
excludedWrappers: ['spaces'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I haven't worked with SavedObjectClient so far. Why we need this functionality?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are very limited use-cases for excluding wrappers.
We are trying to use this for the Copy to Space feature. Specifically, we will be introducing an API endpoint within the Spaces plugin which needs to be able to reach across spaces. By removing the spaces wrapper from that specific endpoint's instance, we can control which space (or, namespace) the SavedObjectsClient is targeting for each request.

@legrego
Copy link
Member Author

legrego commented Jul 8, 2019

The problem that I have reading this code is to understand the order of all wrappers. This knowledge is spread across the code base. Given the possibility to disable any wrapper I have even more combinations, as any client can specify any number of wrappers.

Yeah, that's a valid concern, which we briefly talked about on our call last week. The wrappers have all been written with the assumption that there may or may not be other wrappers defined. For example, the security wrapper can work with the spaces wrapper, but it doesn't assume that the spaces wrapper will in fact be there. The reverse also applies. The ordering of the wrappers is somewhat "magical" in that it's not immediately clear why the wrappers are ordered in any particular way. That hasn't changed with this PR, but the ability to omit wrappers does add to the complexity.

@kobelb
Copy link
Contributor

kobelb commented Jul 8, 2019

@restrry @rudolf while this solution isn't perfect, and I do agree with @restrry's concerns, do we prefer this approach to the "symbols approach" and the "class based approach" which we discussed last week and have been implemented in #38444?

@legrego
Copy link
Member Author

legrego commented Jul 9, 2019

I personally prefer this approach over the others that we've attempted in #38444. It feels like a cleaner implementation than what we have in that other PR. I agree with everyone that it's not perfect though.

Any strong objections from anyone to moving forward with this?

@kobelb
Copy link
Contributor

kobelb commented Jul 9, 2019

Any strong objections from anyone to moving forward with this?

No objections from me, I also prefer this approach to the others that we've explored.

@mshustov
Copy link
Contributor

mshustov commented Jul 9, 2019

no objections

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@legrego legrego marked this pull request as ready for review July 9, 2019 17:43
@legrego legrego requested review from a team as code owners July 9, 2019 17:43
@legrego legrego added release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! labels Jul 9, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@legrego legrego added the review label Jul 9, 2019
@legrego
Copy link
Member Author

legrego commented Jul 11, 2019

@restrry or @rudolf would either of you be interested in reviewing this?

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@joshdover
Copy link
Contributor

@legrego They're both out today, but will be back on Monday

@legrego
Copy link
Member Author

legrego commented Jul 12, 2019

Thanks for the heads-up @joshdover!

@elasticmachine
Copy link
Contributor

💔 Build Failed

@legrego
Copy link
Member Author

legrego commented Jul 15, 2019

retest

Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

I like it more than I thought I would 😂

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@legrego legrego merged commit 73a6b72 into elastic:master Jul 15, 2019
@legrego legrego deleted the so/exclude-wrappers branch July 15, 2019 13:25
legrego added a commit to legrego/kibana that referenced this pull request Jul 15, 2019
* allow SOC wrappers to be excluded

* remove example route

* add tests

* more testing
legrego added a commit that referenced this pull request Jul 15, 2019
* allow SOC wrappers to be excluded

* remove example route

* add tests

* more testing
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 review Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.4.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants