Skip to content

[Saved Object Aggregation View] Use namespace registry to add tenant filter#1169

Merged
cliu123 merged 16 commits intoopensearch-project:mainfrom
cwperks:register-namespaces
Nov 2, 2022
Merged

[Saved Object Aggregation View] Use namespace registry to add tenant filter#1169
cliu123 merged 16 commits intoopensearch-project:mainfrom
cwperks:register-namespaces

Conversation

@cwperks
Copy link
Member

@cwperks cwperks commented Oct 28, 2022

Signed-off-by: Craig Perkins cwperx@amazon.com

Description

Corresponding PR in OSD: opensearch-project/OpenSearch-Dashboards#2656

This PR uses the new namespace filter to add a tenant filter on the Saved Objects screen of OSD if the saved object aggregation view flag is enabled.

This PR also addresses logic on the typeToNamespacesMap to only include type for config when all namespaces are requested or the current tenant is in the list of requested namespaces.

Opening this as a Draft until corresponding PR is merged.

Category

[Enhancement, New feature, Bug fix, Test fix, Refactoring, Maintenance, Documentation]

Enhancement

Why these changes are required?

What is the old behavior before changes and new behavior after changes?

Issues Resolved

The first milestone of opensearch-project/security#1869.

Testing

Manual UI testing with many scenarios:

  1. Aggregation view enabled
  2. Aggregation view disabled
  3. Aggregation view disabled -> Aggregation view enabled -> Aggregation view disabled
  4. Tested without security plugin

Unit Tests

Check List

  • New functionality includes testing
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…nant filter

Signed-off-by: Craig Perkins <cwperx@amazon.com>
name: tenant,
};
});
namespacesToRegister.push({
Copy link
Member Author

Choose a reason for hiding this comment

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

This will always include default in the dropdown. default comes into play when OSD deployments with existing saved objects enable the saved object aggregation view feature. These objects do not have the namespace of the saved object populated and will be given the default (or null) namespace.

Signed-off-by: Craig Perkins <cwperx@amazon.com>
@codecov-commenter
Copy link

codecov-commenter commented Oct 28, 2022

Codecov Report

Merging #1169 (e946d2f) into main (f815e3c) will decrease coverage by 0.02%.
The diff coverage is 68.75%.

@@            Coverage Diff             @@
##             main    #1169      +/-   ##
==========================================
- Coverage   71.80%   71.78%   -0.03%     
==========================================
  Files          88       88              
  Lines        2011     2027      +16     
  Branches      265      274       +9     
==========================================
+ Hits         1444     1455      +11     
- Misses        505      509       +4     
- Partials       62       63       +1     
Impacted Files Coverage Δ
public/plugin.ts 13.11% <20.00%> (+0.61%) ⬆️
public/apps/configuration/utils/tenant-utils.tsx 70.88% <90.90%> (+3.23%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@cliu123
Copy link
Member

cliu123 commented Oct 28, 2022

@cwperks Is this ready for review?

@cwperks cwperks marked this pull request as ready for review October 28, 2022 21:12
@cwperks cwperks requested a review from a team October 28, 2022 21:12
@cwperks
Copy link
Member Author

cwperks commented Oct 28, 2022

@cliu123 This is ready for review now that the companion PR is merged.

}

export function getNamespacesToRegister(accountInfo: any) {
const tenants = accountInfo.tenants || {};
Copy link
Member Author

Choose a reason for hiding this comment

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

@cliu123 I noticed when testing this change that the following data structure comes out as:

{
    "global_tenant": true,
    "admin_tenant": true,
    "admin": true
}

Will the values in this map of tenants ever contain false? If so, should this skip over the tenants where the value in this object is false?

Copy link
Member

Choose a reason for hiding this comment

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

@cwperks You might have logged in as admin, then you are expected to have all tenant permissions. If you create a role, grant permission to a specific tenant, create a user, map the role to the user, and log in as the user, then you'll see the difference.

RyanL1997
RyanL1997 previously approved these changes Oct 31, 2022
cliu123
cliu123 previously approved these changes Oct 31, 2022
@cwperks cwperks dismissed stale reviews from cliu123 and RyanL1997 via ee9ead0 October 31, 2022 22:38
Copy link
Member

@cliu123 cliu123 left a comment

Choose a reason for hiding this comment

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

@cwperks The changes in saved_objects_wrapper.ts would break the aggregation functionality. With the changes, the Saved Objects table no longer aggregates object from all namespaces. Please consider the following changes:

      if ('namespaces' in options && !options.namespaces) {
        // Requests coming from "Index Patterns" table have "namespaces: undefined" in the options.
        _.assign(options, { namespaces: availableTenantNames });
      }  else {
        // Requests coming from "Save Objects" table do not have namespaces in the options.
        // Move the logic with `typeToNamespacesMap` to here.
        const typeToNamespacesMap: any = {};
        ...
        ...
      }

Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
@cwperks
Copy link
Member Author

cwperks commented Nov 1, 2022

@cliu123 I updated this to:

if (options.namespaces !== undefined) {
  const typeToNamespacesMap: any = {};
  ...

  options.typeToNamespacesMap = new Map(Object.entries(typeToNamespacesMap));
  options.type = '';
  options.namespaces = [];
} else {
  options.namespaces = [namespaceValue];
}

The else in this clause scopes the request not explicitly containing namespaces to use the current namespace (tenant). This is similar to what you have above, but just includes the current namespace.

cliu123
cliu123 previously approved these changes Nov 1, 2022
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Copy link
Member

@cliu123 cliu123 left a comment

Choose a reason for hiding this comment

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

@cwperks With the changes in this PR, the Saved Object table does not aggregate saved objects. It only shows the saved objects in the selected tenant.

@cwperks
Copy link
Member Author

cwperks commented Nov 2, 2022

@cliu123 This PR in OSD Core needs to be merged first: opensearch-project/OpenSearch-Dashboards#2696

The old behavior would send an empty array to signal to the saved_objects_wrapper that it should include all namespaces, but this was inconsistent with the behavior expected of the find API. Since this PR will register namespaces with the new extension point in OSD core, OSD core will ship either all registered namespaces or the list of requested namespaces (if the filter is selected or search text includes namespaces) with each request to find.

This PR has been updated to treat lack of namespaces (undefined, null or empty array of options.namespaces) as a request without namespaces and will only perform the request for the current tenant.

This will help with the issue of determining which page a request comes from. Since this change targets the Saved Objects screen we will expect that requests from that page will provide namespaces and similar find requests coming from other pages will not have namespaces in the request.

@cwperks cwperks added the backport 2.4 backport to 2.4 branch label Nov 2, 2022
DarshitChanpura
DarshitChanpura previously approved these changes Nov 2, 2022
Signed-off-by: Chang Liu <lc12251109@gmail.com>
Signed-off-by: Chang Liu <lc12251109@gmail.com>
@cliu123 cliu123 removed backport 2.x backport to 2.x branch backport 2.4 backport to 2.4 branch labels Nov 2, 2022
@cliu123
Copy link
Member

cliu123 commented Nov 2, 2022

Removing the backport labels for now and will add them back after backporting #1146

@cliu123
Copy link
Member

cliu123 commented Nov 2, 2022

@cwperks UTs and ITs failed. Could you please check?

Signed-off-by: Chang Liu <lc12251109@gmail.com>
@cwperks
Copy link
Member Author

cwperks commented Nov 2, 2022

@cliu123 re-ran UT and IT and they are passing now. The failures were on flaky tests.

Copy link
Member

@cliu123 cliu123 left a comment

Choose a reason for hiding this comment

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

Let's hold off the merge on this PR till merging the other one moving the utils. There could be some conflicts that need to be resolved on this one.

@cwperks cwperks dismissed stale reviews from DarshitChanpura and RyanL1997 via c5a3a0f November 2, 2022 21:42
Signed-off-by: Craig Perkins <cwperx@amazon.com>
@cliu123 cliu123 merged commit 24807bb into opensearch-project:main Nov 2, 2022
cliu123 added a commit to cliu123/security-dashboards-plugin that referenced this pull request Nov 3, 2022
…filter (opensearch-project#1169)

Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Chang Liu <lc12251109@gmail.com>
Co-authored-by: Chang Liu <lc12251109@gmail.com>
Co-authored-by: Darshit Chanpura <35282393+DarshitChanpura@users.noreply.github.com>
(cherry picked from commit 24807bb)
cliu123 added a commit to cliu123/security-dashboards-plugin that referenced this pull request Nov 3, 2022
…filter (opensearch-project#1169)

Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Chang Liu <lc12251109@gmail.com>
Co-authored-by: Chang Liu <lc12251109@gmail.com>
Co-authored-by: Darshit Chanpura <35282393+DarshitChanpura@users.noreply.github.com>
(cherry picked from commit 24807bb)
peternied pushed a commit that referenced this pull request Nov 3, 2022
* Saved Object Aggregation View (#1146)
* Move tenant-related utils to common folder (#1184)
* [Saved Object Aggregation View] Use namespace registry to add tenant filter (#1169)

Signed-off-by: Chang Liu <lc12251109@gmail.com>
Signed-off-by: Ryan Liang <jiallian@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Yan Zeng <zengyan@amazon.com>

Co-authored-by: Ryan Liang <jiallian@amazon.com>
Co-authored-by: Ryan Liang <109499885+RyanL1997@users.noreply.github.com>
Co-authored-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Yan Zeng <zengyan@amazon.com>
peternied pushed a commit that referenced this pull request Nov 3, 2022
* Saved Object Aggregation View (#1146)
* Move tenant-related utils to common folder (#1184)
* [Saved Object Aggregation View] Use namespace registry to add tenant filter (#1169)

Signed-off-by: Chang Liu <lc12251109@gmail.com>
Signed-off-by: Ryan Liang <jiallian@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Yan Zeng <zengyan@amazon.com>

Co-authored-by: Ryan Liang <jiallian@amazon.com>
Co-authored-by: Ryan Liang <109499885+RyanL1997@users.noreply.github.com>
Co-authored-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Yan Zeng <zengyan@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants