Skip to content

Commit

Permalink
[Workspace][Feature] Add ACL related functions (opensearch-project#5084
Browse files Browse the repository at this point in the history
…) (opensearch-project#287)

* [Workspace] Add ACL related functions for workspace (opensearch-project#146)

* [Workspace] Add acl related functions for workspace



* Minor change



---------



* Modify changelog



* Add more unit test cases



* Modify test case



* Some minor change



* Add more test cases



* Optimize some code and the comments of the functions



* Add more comments for some basic functions



* Export more interfaces



* consume permissions in repository



* feat: consume permissions in serializer



* Add unit tests for consuming permissions in repository



* Remove double exclamation



* Rename some variables



* Remove duplicated semicolon



* Add permissions field to the mapping only if the permission control is enabled



* Fix test failure



* Add feature flag config to the yml file



* Make the comment of feature flag more clear



* Make comment more clear



* Remove management permission type



* Fix test failure



---------

Signed-off-by: gaobinlong <[email protected]>
Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Josh Romero <[email protected]>
Co-authored-by: SuZhou-Joe <[email protected]>
  • Loading branch information
3 people authored Mar 8, 2024
1 parent 1e582e2 commit e4ce3e0
Show file tree
Hide file tree
Showing 20 changed files with 518 additions and 396 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Replace OuiSelect component with OuiSuperSelect in data-source plugin ([#5315](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5315))
- [Workspace] Add core workspace service module to enable the implementation of workspace features within OSD plugins ([#5092](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5092))
- [Workspace] Setup workspace skeleton and implement basic CRUD API ([#5075](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5075))
- [Workspace] Add ACL related functions ([#5084](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5084/))
- [Decouple] Add new cross compatibility check core service which export functionality for plugins to verify if their OpenSearch plugin counterpart is installed on the cluster or has incompatible version to configure the plugin behavior([#4710](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4710))
- [Discover] Add long numerals support [#5592](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5592)
- [Discover] Display inner properties in the left navigation bar [#5429](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5429)
Expand Down
8 changes: 5 additions & 3 deletions config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@
# Set the value of this setting to true to enable plugin augmentation on Dashboard
# vis_augmenter.pluginAugmentationEnabled: true

# Set the value to true to enable permission control for saved objects
# Permission control depends on OpenSearch Dashboards has authentication enabled, set it to false when the security plugin is not installed,
# if the security plugin is not installed and this config is true, permission control takes no effect.
# savedObjects.permission.enabled: true

# Set the value to true to enable workspace feature
# workspace.enabled: false
# Set the value to false to disable permission check on workspace
# Permission check depends on OpenSearch Dashboards has authentication enabled, set it to false if no authentication is configured
# workspace.permission.enabled: true

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ describe('buildActiveMappings', () => {
expect(hashes.aaa).not.toEqual(hashes.ccc);
});

test('permissions field is added when permission control flag is enabled', () => {
const rawConfig = configMock.create();
rawConfig.get.mockReturnValue(true);
expect(buildActiveMappings({}, rawConfig)).toHaveProperty('properties.permissions');
});

test('workspaces field is added when workspace feature flag is enabled', () => {
const rawConfig = configMock.create();
rawConfig.get.mockReturnValue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ export function buildActiveMappings(

let mergedProperties = validateAndMerge(mapping.properties, typeDefinitions);
// if permission control for saved objects is enabled, the permissions field should be added to the mapping
if (opensearchDashboardsRawConfig?.get('savedObjects.permission.enabled')) {
const principals: SavedObjectsFieldMapping = {
properties: {
users: {
type: 'keyword',
},
groups: {
type: 'keyword',
},
},
};
mergedProperties = validateAndMerge(mapping.properties, {
permissions: {
properties: {
read: principals,
write: principals,
library_read: principals,
library_write: principals,
},
},
});
}

if (opensearchDashboardsRawConfig?.get('workspace.enabled')) {
mergedProperties = validateAndMerge(mapping.properties, {
workspaces: {
Expand Down Expand Up @@ -148,16 +171,6 @@ function findChangedProp(actual: any, expected: any) {
* @returns {IndexMapping}
*/
function defaultMapping(): IndexMapping {
const principals: SavedObjectsFieldMapping = {
properties: {
users: {
type: 'keyword',
},
groups: {
type: 'keyword',
},
},
};
return {
dynamic: 'strict',
properties: {
Expand Down Expand Up @@ -196,15 +209,6 @@ function defaultMapping(): IndexMapping {
},
},
},
permissions: {
properties: {
read: principals,
write: principals,
management: principals,
library_read: principals,
library_write: principals,
},
},
},
};
}
Expand Down
Loading

0 comments on commit e4ce3e0

Please sign in to comment.