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 31 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 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
b4f876f
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura Oct 10, 2024
9baac32
Updates toXContent implementations
DarshitChanpura Oct 10, 2024
0eb47ac
Fix toString implementation
DarshitChanpura Oct 10, 2024
e313071
Allows the ability to list resource permissions
DarshitChanpura Oct 15, 2024
bd91162
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura Nov 5, 2024
2327258
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura Nov 20, 2024
774a4a1
Merge remote-tracking branch 'upstream/main' into resource-permissions
DarshitChanpura Nov 25, 2024
37cacf0
Adds NamedWriteable implementations
DarshitChanpura Nov 27, 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 @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Support prefix list for remote repository attributes([#16271](https://github.com/opensearch-project/OpenSearch/pull/16271))
- Add new configuration setting `synonym_analyzer`, to the `synonym` and `synonym_graph` filters, enabling the specification of a custom analyzer for reading the synonym file ([#16488](https://github.com/opensearch-project/OpenSearch/pull/16488)).
- Add stats for remote publication failure and move download failure stats to remote methods([#16682](https://github.com/opensearch-project/OpenSearch/pull/16682/))
- Add resource-level access control and sharing ([#16030](https://github.com/opensearch-project/OpenSearch/pull/16030))

### Dependencies
- Bump `com.google.cloud:google-cloud-core-http` from 2.23.0 to 2.47.0 ([#16504](https://github.com/opensearch-project/OpenSearch/pull/16504))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;

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, NamedWriteable {

private String user;

public CreatedBy(String user) {
this.user = user;
}

Check warning on line 32 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#L30-L32

Added lines #L30 - L32 were not covered by tests

public CreatedBy(StreamInput in) throws IOException {
this(in.readString());
}

Check warning on line 36 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#L35-L36

Added lines #L35 - L36 were not covered by tests

public String getUser() {
return user;

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#L39

Added line #L39 was not covered by tests
}

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

Check warning on line 44 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#L43-L44

Added lines #L43 - L44 were not covered by tests

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

Check warning on line 48 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#L48

Added line #L48 was not covered by tests
}

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

Check warning on line 53 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#L53

Added line #L53 was not covered by tests
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(user);
}

Check warning on line 59 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#L58-L59

Added lines #L58 - L59 were not covered by tests

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

Check warning on line 63 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#L63

Added line #L63 was not covered by tests
}

public static CreatedBy fromXContent(XContentParser parser) throws IOException {
String user = null;
String currentFieldName = null;

Check warning on line 68 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#L67-L68

Added lines #L67 - L68 were not covered by tests
XContentParser.Token token;

while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();

Check warning on line 73 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#L73

Added line #L73 was not covered by tests
} else if (token == XContentParser.Token.VALUE_STRING) {
if ("user".equals(currentFieldName)) {
user = parser.text();

Check warning on line 76 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#L76

Added line #L76 was not covered by tests
}
}
}

if (user == null) {
throw new IllegalArgumentException("user field is required");

Check warning on line 82 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#L82

Added line #L82 was not covered by tests
}

return new CreatedBy(user);

Check warning on line 85 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#L85

Added line #L85 was not covered by tests
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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("users"),
ROLES("roles"),
BACKEND_ROLES("backend_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#L18-L20

Added lines #L18 - L20 were not covered by tests

private final String value;

EntityType(String value) {
this.value = value;
}

Check warning on line 26 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#L24-L26

Added lines #L24 - L26 were not covered by tests

@Override
public String toString() {
return value;

Check warning on line 30 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#L30

Added line #L30 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
*/
public 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
}
}
Loading
Loading