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] Add a base setup for resource access evaluation and adds a sample plugin #10

Draft
wants to merge 67 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
deb9c43
Explicitly create index before ingesting document in ComplianceAuditl…
cwperks Nov 20, 2024
49bc80f
Update Gradle to 8.11 (#4920)
reta Nov 20, 2024
9dfd5a0
Update Gradle to 8.11.1 (#4924)
reta Nov 20, 2024
831dca3
Add a base setup for resource access evaluation
DarshitChanpura Aug 30, 2024
1c65eff
Adds handler and other access management components for resource sharing
DarshitChanpura Sep 6, 2024
118cb07
Adds sample resource plugin
DarshitChanpura Sep 6, 2024
c41b67d
Removes node_modules entry from gitingore
DarshitChanpura Sep 6, 2024
45d4fa5
Handles changes related to scope
DarshitChanpura Oct 4, 2024
ae2464d
Updates sample plugin to implement a custom scope
DarshitChanpura Oct 4, 2024
aea2253
Fixes Checkstyle and spotless issues
DarshitChanpura Oct 4, 2024
1e17dc0
Fixes initialization error
DarshitChanpura Oct 4, 2024
84746e8
Renames sample resource plugin and adds a logger statement
DarshitChanpura Oct 4, 2024
83e4da0
Changes package name for sample plugin
DarshitChanpura Oct 4, 2024
4b9b9b1
Re-organizes and renames sample plugin files
DarshitChanpura Oct 4, 2024
81216f1
Updates method references to conform to core
DarshitChanpura Oct 4, 2024
1e33dad
Fixes compile errors
DarshitChanpura Oct 4, 2024
a671cc1
Fixes some names and method implementations
DarshitChanpura Oct 14, 2024
47b73da
Adds few concrete method implementations in security plugin
DarshitChanpura Oct 14, 2024
8942a80
Adds capability to introduce index listeners for all resource plugins
DarshitChanpura Oct 15, 2024
2b06603
Removes sampleplugin to be added in a separate PR
DarshitChanpura Nov 11, 2024
6f42bf1
Updates settings.gradle
DarshitChanpura Nov 11, 2024
45b002e
Fixes imports
DarshitChanpura Nov 20, 2024
6a16fdb
Bump Wandalen/wretry.action from 3.7.2 to 3.7.3 (#4931)
dependabot[bot] Nov 25, 2024
59a01dd
Bump com.google.googlejavaformat:google-java-format from 1.24.0 to 1.…
dependabot[bot] Nov 25, 2024
6deeaba
Bump com.google.errorprone:error_prone_annotations from 2.35.1 to 2.3…
dependabot[bot] Nov 25, 2024
a8447cc
Bump commons-io:commons-io from 2.17.0 to 2.18.0 (#4928)
dependabot[bot] Nov 25, 2024
c22002a
Add support for certificates hot reload (#4880)
willyborankin Nov 25, 2024
a30be57
Adds concrete implementations of remainder methods
DarshitChanpura Nov 27, 2024
58003f6
Fixes spotless errors
DarshitChanpura Nov 27, 2024
078a976
Fixes log statement
DarshitChanpura Nov 27, 2024
64f4d5b
Bump io.dropwizard.metrics:metrics-core from 4.2.28 to 4.2.29 (#4940)
dependabot[bot] Dec 2, 2024
67f378a
Bump org.springframework.kafka:spring-kafka-test from 2.9.13 to 3.3.0…
cwperks Dec 4, 2024
8e44cf3
Renames ResourceManagement repository and add keyword to search query…
DarshitChanpura Dec 4, 2024
16a0ba6
Fixes delete method
DarshitChanpura Dec 4, 2024
ac53c8f
Fixes updateByQuery painless script
DarshitChanpura Dec 5, 2024
4176478
Fix typos (#4950)
terryquigleysas Dec 5, 2024
9e6ae85
Updates revoke handler to use painless script
DarshitChanpura Dec 5, 2024
0fe9779
Convert sets to lists
DarshitChanpura Dec 5, 2024
6d7f4c0
Explicitly casts painless entries to set to avoid duplicates
DarshitChanpura Dec 6, 2024
9d4ca1e
Fixes revoke access script
DarshitChanpura Dec 6, 2024
7ae045c
Ensure no active threads in any threadpool for tests in the integrati…
cwperks Dec 6, 2024
d31b188
Add release notes for 1.3.20 release (#4953)
cwperks Dec 6, 2024
a1d4408
Change log level for log line in OBO Authenticator if OBO is disabled…
cwperks Dec 6, 2024
b4b22d6
Fixes revoke script to handle duplicates
DarshitChanpura Dec 6, 2024
e87bb80
Updates logger statement
DarshitChanpura Dec 7, 2024
5ad813b
Adds validation for resource ownership when granting and revoking access
DarshitChanpura Dec 7, 2024
0edba23
Bump org.checkerframework:checker-qual from 3.48.2 to 3.48.3 (#4958)
dependabot[bot] Dec 9, 2024
47ee2cf
Bump com.carrotsearch.randomizedtesting:randomizedtesting-runner from…
dependabot[bot] Dec 9, 2024
719c659
Bump org.eclipse.platform:org.eclipse.core.runtime from 3.31.100 to 3…
dependabot[bot] Dec 9, 2024
3c7404f
Bump org.eclipse.platform:org.eclipse.equinox.common from 3.19.100 to…
dependabot[bot] Dec 9, 2024
c08a992
Adds super-admin bypass
DarshitChanpura Dec 10, 2024
8e3d41c
Updates method names and adds missing java doc
DarshitChanpura Dec 11, 2024
cabbcd6
Updates methods to return actual resources instead of resource ids
DarshitChanpura Dec 12, 2024
dc964ac
Stash context to fetch resources from a system index
DarshitChanpura Dec 13, 2024
cc973c6
Optimize call to fetch resources
DarshitChanpura Dec 13, 2024
3ce3d92
Updates javadoc
DarshitChanpura Dec 13, 2024
428e11e
Adds input validation
DarshitChanpura Dec 13, 2024
3a6dd40
Bump org.apache.commons:commons-text from 1.12.0 to 1.13.0 (#4969)
dependabot[bot] Dec 16, 2024
79a3299
Bump com.google.googlejavaformat:google-java-format from 1.25.0 to 1.…
dependabot[bot] Dec 16, 2024
2f870c7
Refactor SafeSerializationUtils for better performance (#4973)
shikharj05 Dec 18, 2024
a55ac22
Adds auditlog capability and conform to changes in core
DarshitChanpura Dec 20, 2024
1c62d36
Conforms to type bounding change introduced in core
DarshitChanpura Dec 20, 2024
6a23f46
Merge remote-tracking branch 'upstream/main' into resource-access-con…
DarshitChanpura Dec 20, 2024
c24323c
Stashes context while fetching resource sharing record
DarshitChanpura Dec 20, 2024
f514859
Fixes accessDeclaredMembers error caused in AuditConfig class
DarshitChanpura Dec 20, 2024
193e846
Changes log levels and improves log statements
DarshitChanpura Dec 20, 2024
13fdb81
Bring user notion to security plugin
DarshitChanpura Dec 31, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
working-directory: downloaded-artifacts

- name: Upload Coverage with retry
uses: Wandalen/[email protected].2
uses: Wandalen/[email protected].3
with:
attempt_limit: 5
attempt_delay: 2000
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,3 @@ out/
build/
gradle-build/
.gradle/

# nodejs
node_modules/
package-lock.json
26 changes: 13 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,16 @@ configurations {
force "org.apache.commons:commons-lang3:${versions.commonslang}"

// for spotless transitive dependency CVE
force "org.eclipse.platform:org.eclipse.core.runtime:3.31.100"
force "org.eclipse.platform:org.eclipse.equinox.common:3.19.100"
force "org.eclipse.platform:org.eclipse.core.runtime:3.32.0"
force "org.eclipse.platform:org.eclipse.equinox.common:3.19.200"

// For integrationTest
force "org.apache.httpcomponents:httpclient:4.5.14"
force "org.apache.httpcomponents:httpcore:4.4.16"
force "com.google.errorprone:error_prone_annotations:2.35.1"
force "org.checkerframework:checker-qual:3.48.2"
force "com.google.errorprone:error_prone_annotations:2.36.0"
force "org.checkerframework:checker-qual:3.48.3"
force "ch.qos.logback:logback-classic:1.5.12"
force "commons-io:commons-io:2.17.0"
force "commons-io:commons-io:2.18.0"
}
}

Expand Down Expand Up @@ -611,7 +611,7 @@ dependencies {
runtimeOnly 'com.eclipsesource.minimal-json:minimal-json:0.9.5'
runtimeOnly 'commons-codec:commons-codec:1.17.1'
runtimeOnly 'org.cryptacular:cryptacular:1.2.7'
compileOnly 'com.google.errorprone:error_prone_annotations:2.35.1'
compileOnly 'com.google.errorprone:error_prone_annotations:2.36.0'
runtimeOnly 'com.sun.istack:istack-commons-runtime:4.2.0'
runtimeOnly 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.2'
runtimeOnly 'org.ow2.asm:asm:9.7.1'
Expand All @@ -620,7 +620,7 @@ dependencies {

//OpenSAML
implementation 'net.shibboleth.utilities:java-support:8.4.2'
runtimeOnly "io.dropwizard.metrics:metrics-core:4.2.28"
runtimeOnly "io.dropwizard.metrics:metrics-core:4.2.29"
implementation "com.onelogin:java-saml:${one_login_java_saml}"
implementation "com.onelogin:java-saml-core:${one_login_java_saml}"
implementation "org.opensaml:opensaml-core:${open_saml_version}"
Expand All @@ -641,7 +641,7 @@ dependencies {
implementation "com.nulab-inc:zxcvbn:1.9.0"

runtimeOnly 'com.google.guava:failureaccess:1.0.2'
runtimeOnly 'org.apache.commons:commons-text:1.12.0'
runtimeOnly 'org.apache.commons:commons-text:1.13.0'
runtimeOnly "org.glassfish.jaxb:jaxb-runtime:${jaxb_version}"
runtimeOnly 'com.google.j2objc:j2objc-annotations:2.8'
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
Expand All @@ -655,7 +655,7 @@ dependencies {
runtimeOnly 'org.apache.ws.xmlschema:xmlschema-core:2.3.1'
runtimeOnly 'org.apache.santuario:xmlsec:2.3.4'
runtimeOnly "com.github.luben:zstd-jni:${versions.zstd}"
runtimeOnly 'org.checkerframework:checker-qual:3.48.2'
runtimeOnly 'org.checkerframework:checker-qual:3.48.3'
runtimeOnly "org.bouncycastle:bcpkix-jdk18on:${versions.bouncycastle}"
runtimeOnly 'org.scala-lang.modules:scala-java8-compat_3:1.0.2'

Expand Down Expand Up @@ -686,7 +686,7 @@ dependencies {
testImplementation "org.apache.kafka:kafka_2.13:${kafka_version}:test"
testImplementation "org.apache.kafka:kafka-clients:${kafka_version}:test"
testImplementation 'commons-validator:commons-validator:1.9.0'
testImplementation 'org.springframework.kafka:spring-kafka-test:2.9.13'
testImplementation 'org.springframework.kafka:spring-kafka-test:3.3.0'
testImplementation "org.springframework:spring-beans:${spring_version}"
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.3'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'
Expand Down Expand Up @@ -724,13 +724,13 @@ dependencies {
compileOnly "org.opensearch:opensearch:${opensearch_version}"

//integration test framework:
integrationTestImplementation('com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.8.1') {
integrationTestImplementation('com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.8.2') {
exclude(group: 'junit', module: 'junit')
}
integrationTestImplementation 'junit:junit:4.13.2'
integrationTestImplementation "org.opensearch.plugin:reindex-client:${opensearch_version}"
integrationTestImplementation "org.opensearch.plugin:percolator-client:${opensearch_version}"
integrationTestImplementation 'commons-io:commons-io:2.17.0'
integrationTestImplementation 'commons-io:commons-io:2.18.0'
integrationTestImplementation "org.apache.logging.log4j:log4j-core:${versions.log4j}"
integrationTestImplementation "org.apache.logging.log4j:log4j-jul:${versions.log4j}"
integrationTestImplementation 'org.hamcrest:hamcrest:2.2'
Expand All @@ -749,7 +749,7 @@ dependencies {
integrationTestImplementation "org.mockito:mockito-core:5.14.2"

//spotless
implementation('com.google.googlejavaformat:google-java-format:1.24.0') {
implementation('com.google.googlejavaformat:google-java-format:1.25.2') {
exclude group: 'com.google.guava'
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
8 changes: 8 additions & 0 deletions release-notes/opensearch-security.release-notes-1.3.20.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Version 1.3.20.0

Compatible with OpenSearch 1.3.20

### Maintenance

* Update commons-io to 2.18.0 ([#4944](https://github.com/opensearch-project/security/pull/4944))
* Bump spring-framework dependency to 2.9.13 ([#4947](https://github.com/opensearch-project/security/pull/4947))
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright OpenSearch Contributors
* 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.security;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.security.http.ExampleSystemIndexPlugin;
import org.opensearch.test.framework.TestSecurityConfig.AuthcDomain;
import org.opensearch.test.framework.cluster.ClusterManager;
import org.opensearch.test.framework.cluster.LocalCluster;
import org.opensearch.test.framework.cluster.TestRestClient;
import org.opensearch.test.framework.cluster.TestRestClient.HttpResponse;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.opensearch.security.support.ConfigConstants.SECURITY_RESTAPI_ROLES_ENABLED;
import static org.opensearch.test.framework.TestSecurityConfig.Role.ALL_ACCESS;
import static org.opensearch.test.framework.TestSecurityConfig.User.USER_ADMIN;

@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class)
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
public class ThreadPoolTests {

public static final AuthcDomain AUTHC_DOMAIN = new AuthcDomain("basic", 0).httpAuthenticatorWithChallenge("basic").backend("internal");

@ClassRule
public static final LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.SINGLENODE)
.anonymousAuth(false)
.authc(AUTHC_DOMAIN)
.users(USER_ADMIN)
.plugin(ExampleSystemIndexPlugin.class)
.nodeSettings(Map.of(SECURITY_RESTAPI_ROLES_ENABLED, List.of("user_" + USER_ADMIN.getName() + "__" + ALL_ACCESS.getName())))
.build();

@Test
public void testEnsureNoThreadLeftRunningInGenericThreadPool() throws IOException, InterruptedException {
try (TestRestClient client = cluster.getRestClient(USER_ADMIN)) {
client.put("test-index");

XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("field1", "foo");
builder.endObject();

HttpResponse indexDocResponse = client.putJson("test-index/_doc/1", builder.toString());

assertThat(indexDocResponse.getStatusCode(), equalTo(RestStatus.CREATED.getStatus()));

XContentBuilder updateBuilder = XContentFactory.jsonBuilder();
updateBuilder.startObject();
updateBuilder.startObject("doc");
updateBuilder.field("field1", "bar");
updateBuilder.endObject();
updateBuilder.endObject();

HttpResponse updateDocResponse = client.postJson("test-index/_update/1", updateBuilder.toString());

assertThat(updateDocResponse.getStatusCode(), equalTo(RestStatus.OK.getStatus()));

client.delete("test-index");

Thread.sleep(2000);

HttpResponse hotThreadsResponse = client.get("_nodes/hot_threads");

assertThat(hotThreadsResponse.getBody(), not(containsString("ClusterStateMetadataDependentPrivileges")));
}
}
}
26 changes: 20 additions & 6 deletions src/main/java/org/opensearch/security/DefaultObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,26 @@ public static TypeFactory getTypeFactory() {
return objectMapper.getTypeFactory();
}

@SuppressWarnings("removal")
public static Set<String> getFields(Class<?> cls) {
return objectMapper.getSerializationConfig()
.introspect(getTypeFactory().constructType(cls))
.findProperties()
.stream()
.map(BeanPropertyDefinition::getName)
.collect(ImmutableSet.toImmutableSet());
final SecurityManager sm = System.getSecurityManager();

if (sm != null) {
sm.checkPermission(new SpecialPermission());
}

try {
return AccessController.doPrivileged(
(PrivilegedExceptionAction<Set<String>>) () -> objectMapper.getSerializationConfig()
.introspect(getTypeFactory().constructType(cls))
.findProperties()
.stream()
.map(BeanPropertyDefinition::getName)
.collect(ImmutableSet.toImmutableSet())
);
} catch (final PrivilegedActionException e) {
throw (RuntimeException) e.getCause();
}

}
}
Loading
Loading