-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Feature]Introduces Resource Sharing and Access Control #16030
Open
DarshitChanpura
wants to merge
68
commits into
opensearch-project:main
Choose a base branch
from
DarshitChanpura:resource-permissions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
909a85b
Adds a new plugin type named ResourcePlugin and relevant base classes
DarshitChanpura 66a849c
Adds a No-op implementation of ResourcePlugin
DarshitChanpura 08cdcb3
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura d7169e4
Adds a way to configure security plugin for resource access-control
DarshitChanpura 58ae851
Fixes compilation errors and changes debug log-level to info for Reso…
DarshitChanpura fd00243
Replace plugin count check with isEmpty
DarshitChanpura ef8a0b7
Adds package-info
DarshitChanpura e98cb61
Renames a bunch of files
DarshitChanpura 96f09b0
Changes method signatures to be inline with their usage
DarshitChanpura c86dfc9
Adds new method for deleting by entity
DarshitChanpura 7c6ec2a
Adds abstract method definitions for ResourcePlugin interface
DarshitChanpura c04762e
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura f95a67f
Adds toXContent implementations
DarshitChanpura 8b8fffd
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 7e7cd0a
Modifies some method names and comments
DarshitChanpura e1a1b62
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 23fcfba
Fixes license
DarshitChanpura fba48ab
Adds changelog entry
DarshitChanpura 9cb8d0e
Adds a notion of scope
DarshitChanpura 848234e
Modifies sharedwith to accomodate scope
DarshitChanpura eaf0c6e
Adds missing JavaDoc
DarshitChanpura 6a6e6f7
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 566913a
Adds NamedWriteable capability and removes un-needed method
DarshitChanpura b4f876f
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 9baac32
Updates toXContent implementations
DarshitChanpura 0eb47ac
Fix toString implementation
DarshitChanpura e313071
Allows the ability to list resource permissions
DarshitChanpura bd91162
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 2327258
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 774a4a1
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 37cacf0
Adds NamedWriteable implementations
DarshitChanpura 4107407
Adds TODO for Noop Implementation
DarshitChanpura 274c64f
Adds fromValue method to EntityType
DarshitChanpura 014be82
Refactors variables from List to Set
DarshitChanpura 3143796
Updates revokeAccess signature to accept scopes to revoke access from
DarshitChanpura 04a02cb
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura e468f91
Convert sets to lists
DarshitChanpura 3a0b4b1
Upper-case the default scope
DarshitChanpura 0056807
Adds concrete implementation of getResources in Noop RAC plugin
DarshitChanpura 0548fc2
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 193112b
Updates the ResourceAccessControlPlugin to have noop actions, renames…
DarshitChanpura cbbefa6
Adds ReflectPermissions for DefaultResourceAccessControlPlugin
DarshitChanpura d7d1f25
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura a44b06a
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura b58308e
Adds missing package-info
DarshitChanpura b25a9a7
Adds unit and integration tests
DarshitChanpura eb43578
Adds missing experimental annotations
DarshitChanpura bcd0f2b
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 686f037
Uses jackson object-mapper to read resource class and updates the int…
DarshitChanpura 0bf9fd1
Completes the integrations tests
DarshitChanpura 4a073f1
Updates SHAs
DarshitChanpura 34f160c
Comment and code cleanup
DarshitChanpura 1df8e11
Fixes tests
DarshitChanpura eee5ce1
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 77c56be
Adds integration tests for non-default RAC plugin
DarshitChanpura bb584bb
Removes unused dependency licenses
DarshitChanpura 448307b
Adds missing license headers
DarshitChanpura d9f5262
Adds type bounding to Resource
DarshitChanpura 1aff350
Updates Resource to be a serializable
DarshitChanpura f90b165
Adds getResourceName as API contract for Resource
DarshitChanpura 5e6b8ff
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura ce9d5ec
Removes notion of users, roles and backend_roles
DarshitChanpura 7a868cb
Fixes gradle check failures
DarshitChanpura f1d3011
Fixes created by tests
DarshitChanpura 00ba7a7
Adds test for recipient registry
DarshitChanpura 6fb5055
Fixes a bug in toXContent
DarshitChanpura 3dfc16e
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura 532d13a
Moves jackson dependency addition to server build.gradle
DarshitChanpura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.accesscontrol.resources; | ||
|
||
import org.opensearch.core.xcontent.ToXContentFragment; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* This class contains information on the creator of a resource. | ||
* Creator can either be a user or a backend_role. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class CreatedBy implements ToXContentFragment { | ||
|
||
private String user; | ||
|
||
private String backendRole; | ||
|
||
public CreatedBy(String user, String backendRole) { | ||
this.user = user; | ||
this.backendRole = backendRole; | ||
} | ||
|
||
public String getBackendRole() { | ||
return backendRole; | ||
} | ||
|
||
public void setBackendRole(String backendRole) { | ||
this.backendRole = backendRole; | ||
} | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(String user) { | ||
this.user = user; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CreatedBy {" + "user='" + user + '\'' + ", backendRole='" + backendRole + '\'' + '}'; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return builder.startObject().field("user", user).field("backend_role", backendRole).endObject(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.accesscontrol.resources; | ||
|
||
/** | ||
* This enum contains the type of entities a resource can be shared with. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public enum EntityType { | ||
|
||
USERS, | ||
|
||
ROLES, | ||
|
||
BACKEND_ROLES, | ||
} |
59 changes: 59 additions & 0 deletions
59
server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.accesscontrol.resources; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.OpenSearchException; | ||
import org.opensearch.plugins.NoOpResourceAccessControlPlugin; | ||
import org.opensearch.plugins.ResourceAccessControlPlugin; | ||
import org.opensearch.plugins.ResourcePlugin; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Resource access control for OpenSearch | ||
* | ||
* @opensearch.experimental | ||
* */ | ||
public class ResourceService { | ||
private static final Logger log = LogManager.getLogger(ResourceService.class); | ||
|
||
private final ResourceAccessControlPlugin resourceACPlugin; | ||
private final List<ResourcePlugin> resourcePlugins; | ||
|
||
public ResourceService(final List<ResourceAccessControlPlugin> resourceACPlugins, List<ResourcePlugin> resourcePlugins) { | ||
this.resourcePlugins = resourcePlugins; | ||
|
||
if (resourceACPlugins.isEmpty()) { | ||
log.info("Security plugin disabled: Using NoOpResourceAccessControlPlugin"); | ||
resourceACPlugin = new NoOpResourceAccessControlPlugin(); | ||
} else if (resourceACPlugins.size() == 1) { | ||
log.info("Security plugin enabled: Using OpenSearchSecurityPlugin"); | ||
resourceACPlugin = resourceACPlugins.get(0); | ||
} else { | ||
throw new OpenSearchException( | ||
"Multiple resource access control plugins are not supported, found: " | ||
+ resourceACPlugins.stream().map(Object::getClass).map(Class::getName).collect(Collectors.joining(",")) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the current ResourcePlugin to perform authorization | ||
*/ | ||
public ResourceAccessControlPlugin getResourceAccessControlPlugin() { | ||
return resourceACPlugin; | ||
} | ||
|
||
/** | ||
* List active plugins that define resources | ||
*/ | ||
public List<ResourcePlugin> listResourcePlugins() { | ||
return resourcePlugins; | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.accesscontrol.resources; | ||
|
||
import org.opensearch.core.xcontent.ToXContentFragment; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A document in .resource_sharing index. | ||
* Holds information about the resource (obtained from defining plugin's meta-data), | ||
* the index which defines the resources, the creator of the resource, | ||
* and the information on whom this resource is shared with. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class ResourceSharing implements ToXContentFragment { | ||
|
||
private String sourceIdx; | ||
|
||
private String resourceId; | ||
|
||
private CreatedBy createdBy; | ||
|
||
private ShareWith shareWith; | ||
|
||
public ResourceSharing(String sourceIdx, String resourceId, CreatedBy createdBy, ShareWith shareWith) { | ||
this.sourceIdx = sourceIdx; | ||
this.resourceId = resourceId; | ||
this.createdBy = createdBy; | ||
this.shareWith = shareWith; | ||
} | ||
|
||
public String getSourceIdx() { | ||
return sourceIdx; | ||
} | ||
|
||
public void setSourceIdx(String sourceIdx) { | ||
this.sourceIdx = sourceIdx; | ||
} | ||
|
||
public String getResourceId() { | ||
return resourceId; | ||
} | ||
|
||
public void setResourceId(String resourceId) { | ||
this.resourceId = resourceId; | ||
} | ||
|
||
public CreatedBy getCreatedBy() { | ||
return createdBy; | ||
} | ||
|
||
public void setCreatedBy(CreatedBy createdBy) { | ||
this.createdBy = createdBy; | ||
} | ||
|
||
public ShareWith getShareWith() { | ||
return shareWith; | ||
} | ||
|
||
public void setShareWith(ShareWith shareWith) { | ||
this.shareWith = shareWith; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ResourceSharing resourceSharing = (ResourceSharing) o; | ||
return Objects.equals(getSourceIdx(), resourceSharing.getSourceIdx()) | ||
&& Objects.equals(getResourceId(), resourceSharing.getResourceId()) | ||
&& Objects.equals(getCreatedBy(), resourceSharing.getCreatedBy()) | ||
&& Objects.equals(getShareWith(), resourceSharing.getShareWith()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getSourceIdx(), getResourceId(), getCreatedBy(), getShareWith()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Resource {" | ||
+ "sourceIdx='" | ||
+ sourceIdx | ||
+ '\'' | ||
+ ", resourceId='" | ||
+ resourceId | ||
+ '\'' | ||
+ ", createdBy=" | ||
+ createdBy | ||
+ ", sharedWith=" | ||
+ shareWith | ||
+ '}'; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return builder.startObject() | ||
.field("source_idx", sourceIdx) | ||
.field("resource_id", resourceId) | ||
.field("created_by", createdBy) | ||
.field("share_with", shareWith) | ||
.endObject(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.accesscontrol.resources; | ||
|
||
import org.opensearch.core.xcontent.ToXContentFragment; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* This class contains information about whom a resource is shared with. | ||
* It could be a user-name, a role or a backend_role. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class ShareWith implements ToXContentFragment { | ||
|
||
private List<String> users; | ||
DarshitChanpura marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private List<String> roles; | ||
|
||
private List<String> backendRoles; | ||
|
||
public ShareWith(List<String> users, List<String> roles, List<String> backendRoles) { | ||
this.users = users; | ||
this.roles = roles; | ||
this.backendRoles = backendRoles; | ||
} | ||
|
||
public List<String> getUsers() { | ||
return users; | ||
} | ||
|
||
public void setUsers(List<String> users) { | ||
this.users = users; | ||
} | ||
|
||
public List<String> getRoles() { | ||
return roles; | ||
} | ||
|
||
public void setRoles(List<String> roles) { | ||
this.roles = roles; | ||
} | ||
|
||
public List<String> getBackendRoles() { | ||
return backendRoles; | ||
} | ||
|
||
public void setBackendRoles(List<String> backendRoles) { | ||
this.backendRoles = backendRoles; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ShareWith {" + "users=" + users + ", roles=" + roles + ", backendRoles=" + backendRoles + '}'; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return builder.startObject().field("users", users).field("roles", roles).field("backend_roles", backendRoles).endObject(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
server/src/main/java/org/opensearch/accesscontrol/resources/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/* | ||
DarshitChanpura marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/** | ||
* Actions that OpenSearch can take either on the data stored on disk or on other nodes. | ||
*/ | ||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
/** | ||
* This package defines all classes required for Resource Sharing and Access Control | ||
*/ | ||
package org.opensearch.accesscontrol.resources; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really necessary to support all three criteria (user name, roles, backend roles)? Especially back end roles can vary between auth backend (e.g. users authenticated via LDAP might have different backend roles than users authenticated via OIDC).
Such disparities can lead to confusion.
Who is supposed to specify these criteria when?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, backend roles is already in place amongst plugins that implement custom resource authz.
Its already in place in:
I think there may be others as well (possibly Reporting?).
Backend roles would need to be supported in order for those plugins to adopt the mechanism provided by security.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so this has the goal of a seamless transition from the older methods used in these different plugins?
Still, from a UX point of view, having too many options for a single thing is not optimal. It requires users to make a choice which is the optimal option. Proper information on how to make the right choice might be hard to find or might even not exist.
This is actually demonstrated by the broad range of artifacts which require backend roles in their configuration.
Thus, maybe the backend role option should be marked as deprecated? Or, maybe the docs should be clearer on how to use the roles?