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

[DRAFT] [Feature]Introduces ability to control access to and share resources #16030

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
909a85b
Adds a new plugin type named ResourcePlugin and relevant base classes
DarshitChanpura Aug 27, 2024
66a849c
Adds a No-op implementation of ResourcePlugin
DarshitChanpura Aug 27, 2024
08cdcb3
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura Aug 30, 2024
d7169e4
Adds a way to configure security plugin for resource access-control
DarshitChanpura Aug 30, 2024
58ae851
Fixes compilation errors and changes debug log-level to info for Reso…
DarshitChanpura Aug 30, 2024
fd00243
Replace plugin count check with isEmpty
DarshitChanpura Aug 30, 2024
ef8a0b7
Adds package-info
DarshitChanpura Aug 30, 2024
e98cb61
Renames a bunch of files
DarshitChanpura Aug 30, 2024
96f09b0
Changes method signatures to be inline with their usage
DarshitChanpura Aug 30, 2024
c86dfc9
Adds new method for deleting by entity
DarshitChanpura Aug 30, 2024
7c6ec2a
Adds abstract method definitions for ResourcePlugin interface
DarshitChanpura Sep 3, 2024
c04762e
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura Sep 3, 2024
f95a67f
Adds toXContent implementations
DarshitChanpura Sep 6, 2024
8b8fffd
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura Sep 6, 2024
7e7cd0a
Modifies some method names and comments
DarshitChanpura Sep 10, 2024
e1a1b62
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura Oct 2, 2024
23fcfba
Fixes license
DarshitChanpura Oct 2, 2024
fba48ab
Adds changelog entry
DarshitChanpura Oct 2, 2024
9cb8d0e
Adds a notion of scope
DarshitChanpura Oct 2, 2024
848234e
Modifies sharedwith to accomodate scope
DarshitChanpura Oct 4, 2024
eaf0c6e
Adds missing JavaDoc
DarshitChanpura Oct 4, 2024
6a6e6f7
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura Oct 4, 2024
566913a
Adds NamedWriteable capability and removes un-needed method
DarshitChanpura Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [S3 Repository] Change default retry mechanism of s3 clients to Standard Mode ([#15978](https://github.com/opensearch-project/OpenSearch/pull/15978))
- Add changes to block calls in cat shards, indices and segments based on dynamic limit settings ([#15986](https://github.com/opensearch-project/OpenSearch/pull/15986))
- New `phone` & `phone-search` analyzer + tokenizer ([#15915](https://github.com/opensearch-project/OpenSearch/pull/15915))
- Add resource-level access control and sharing ([#16030](https://github.com/opensearch-project/OpenSearch/pull/16030))

### Dependencies
- Bump `com.azure:azure-identity` from 1.13.0 to 1.13.2 ([#15578](https://github.com/opensearch-project/OpenSearch/pull/15578))
Expand Down
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;
}

Check warning on line 31 in server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java#L28-L31

Added lines #L28 - L31 were not covered by tests

public String getBackendRole() {
return backendRole;

Check warning on line 34 in server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java#L34

Added line #L34 was not covered by tests
}

public void setBackendRole(String backendRole) {
this.backendRole = backendRole;
}

Check warning on line 39 in server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java#L38-L39

Added lines #L38 - L39 were not covered by tests

public String getUser() {
return user;

Check warning on line 42 in server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java#L42

Added line #L42 was not covered by tests
}

public void setUser(String user) {
this.user = user;
}

Check warning on line 47 in server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java#L46-L47

Added lines #L46 - L47 were not covered by tests

@Override
public String toString() {
return "CreatedBy {" + "user='" + user + '\'' + ", backendRole='" + backendRole + '\'' + '}';

Check warning on line 51 in server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java#L51

Added line #L51 was not covered by tests
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject().field("user", user).field("backend_role", backendRole).endObject();

Check warning on line 56 in server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/CreatedBy.java#L56

Added line #L56 was not covered by tests
}
}
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 {

Check warning on line 16 in server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java#L16

Added line #L16 was not covered by tests

USERS,

Check warning on line 18 in server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java#L18

Added line #L18 was not covered by tests

ROLES,

Check warning on line 20 in server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java#L20

Added line #L20 was not covered by tests

BACKEND_ROLES,

Check warning on line 22 in server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java#L22

Added line #L22 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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 interface defines the two basic access scopes for resource-access.
* Each plugin must implement their own scopes and manage them
* These access scopes will then be used to verify the type of access being requested.
*
* @opensearch.experimental
*/
public interface ResourceAccessScope {
String READ_ONLY = "read_only";
String READ_WRITE = "read_write";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.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);

Check warning on line 40 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java#L39-L40

Added lines #L39 - L40 were not covered by tests
} else {
throw new OpenSearchException(

Check warning on line 42 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java#L42

Added line #L42 was not covered by tests
"Multiple resource access control plugins are not supported, found: "
+ resourceACPlugins.stream().map(Object::getClass).map(Class::getName).collect(Collectors.joining(","))

Check warning on line 44 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java#L44

Added line #L44 was not covered by tests
);
}
}

/**
* Gets the current ResourcePlugin to perform authorization
*/
public ResourceAccessControlPlugin getResourceAccessControlPlugin() {
return resourceACPlugin;

Check warning on line 53 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java#L53

Added line #L53 was not covered by tests
}

/**
* List active plugins that define resources
*/
List<ResourcePlugin> listResourcePlugins() {
return resourcePlugins;

Check warning on line 60 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceService.java#L60

Added line #L60 was not covered by tests
}
}
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;
}

Check warning on line 40 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L35-L40

Added lines #L35 - L40 were not covered by tests

public String getSourceIdx() {
return sourceIdx;

Check warning on line 43 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L43

Added line #L43 was not covered by tests
}

public void setSourceIdx(String sourceIdx) {
this.sourceIdx = sourceIdx;
}

Check warning on line 48 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L47-L48

Added lines #L47 - L48 were not covered by tests

public String getResourceId() {
return resourceId;

Check warning on line 51 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L51

Added line #L51 was not covered by tests
}

public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}

Check warning on line 56 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L55-L56

Added lines #L55 - L56 were not covered by tests

public CreatedBy getCreatedBy() {
return createdBy;

Check warning on line 59 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L59

Added line #L59 was not covered by tests
}

public void setCreatedBy(CreatedBy createdBy) {
this.createdBy = createdBy;
}

Check warning on line 64 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L63-L64

Added lines #L63 - L64 were not covered by tests

public ShareWith getShareWith() {
return shareWith;

Check warning on line 67 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L67

Added line #L67 was not covered by tests
}

public void setShareWith(ShareWith shareWith) {
this.shareWith = shareWith;
}

Check warning on line 72 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L71-L72

Added lines #L71 - L72 were not covered by tests

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResourceSharing resourceSharing = (ResourceSharing) o;

Check warning on line 78 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L78

Added line #L78 was not covered by tests
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());

Check warning on line 87 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L87

Added line #L87 was not covered by tests
}

@Override
public String toString() {
return "Resource {"

Check warning on line 92 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L92

Added line #L92 was not covered by tests
+ "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();

Check warning on line 113 in server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ResourceSharing.java#L108-L113

Added lines #L108 - L113 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.common.io.stream.NamedWriteable;
import org.opensearch.core.common.io.stream.StreamOutput;
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 and at what scope.
* Here is a sample of what this would look like:
* "share_with": {
* "read_only": {
* "users": [],
* "roles": [],
* "backend_roles": []
* },
* "read_write": {
* "users": [],
* "roles": [],
* "backend_roles": []
* }
* }
*
* @opensearch.experimental
*/
public class ShareWith implements ToXContentFragment, NamedWriteable {

private final List<SharedWithScope> sharedWithScopes;

public ShareWith(List<SharedWithScope> sharedWithScopes) {
this.sharedWithScopes = sharedWithScopes;
}

Check warning on line 43 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L41-L43

Added lines #L41 - L43 were not covered by tests

public List<SharedWithScope> getSharedWithScopes() {
return sharedWithScopes;

Check warning on line 46 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L46

Added line #L46 was not covered by tests
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject("share_with").value(sharedWithScopes).endObject();

Check warning on line 51 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L51

Added line #L51 was not covered by tests
}

@Override
public String getWriteableName() {
return "share_with";

Check warning on line 56 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L56

Added line #L56 was not covered by tests
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeList(sharedWithScopes);
}

Check warning on line 62 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L61-L62

Added lines #L61 - L62 were not covered by tests
}
Loading
Loading