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

Updates for build qualifiers #1742

Closed
Closed
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ jobs:
- run: ./gradlew clean assemble -Dbuild.snapshot=false
- run: test -s ./build/opensearch-security-${{ steps.security-plugin-version.outputs.value }}.jar

- run: ./gradlew clean assemble -Dbuild.snapshot=false -Dbuild.version_qualifier=alpha1
- run: test -s ./build/opensearch-security-${{ steps.security-plugin-version.outputs.value }}-alpha1.jar
- run: ./gradlew clean assemble -Dbuild.snapshot=false -Dbuild.version_qualifier=alpha2
- run: test -s ./build/opensearch-security-${{ steps.security-plugin-version.outputs.value }}-alpha2.jar

- run: ./gradlew clean assemble -Dbuild.version_qualifier=alpha1
- run: test -s ./build/opensearch-security-${{ steps.security-plugin-version.outputs.value }}-alpha1-SNAPSHOT.jar
- run: ./gradlew clean assemble -Dbuild.version_qualifier=alpha2
- run: test -s ./build/opensearch-security-${{ steps.security-plugin-version.outputs.value }}-alpha2-SNAPSHOT.jar

- run: ./gradlew clean assemble -Dopensearch.version=2.0.0-alpha1-SNAPSHOT -Dbuild.snapshot=false -Dbuild.version_qualifier=alpha2
- run: test -s ./build/opensearch-security-${{ steps.security-plugin-version.outputs.value }}-alpha2.jar

- name: List files in the build directory if there was an error
run: ls -al ./build/
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/plugin_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ jobs:
- name: Build
run: ./gradlew clean assemble -Dbuild.snapshot=false

- name: Find OpenSearch version
id: opensearch-version-finder
run: echo "::set-output name=number_only::$(echo "${{ steps.opensearch-version.outputs.value }}" | sed "s/.*\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/g")"

- name: Download OpenSearch Core
run: |
wget https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${{ steps.opensearch-version.outputs.value }}/latest/linux/x64/builds/opensearch/dist/opensearch-min-${{ steps.opensearch-version.outputs.value }}-linux-x64.tar.gz
wget https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${{ steps.opensearch-version-finder.outputs.number_only }}/latest/linux/x64/builds/opensearch/dist/opensearch-min-${{ steps.opensearch-version-finder.outputs.number_only }}-linux-x64.tar.gz
tar -xzf opensearch-*.tar.gz
rm -f opensearch-*.tar.gz

Expand Down
25 changes: 9 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ repositories {
}

ext {
default_opensearch_version = property("opensearch-core.version") + "-SNAPSHOT"
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
default_opensearch_version = property("opensearch-core.version")
opensearch_version = System.getProperty("opensearch.version", default_opensearch_version)
buildVersionQualifier = System.getProperty("build.version_qualifier")
buildVersionQualifier = System.getProperty("build.version_qualifier", "")
}

configurations.all {
Expand Down Expand Up @@ -124,22 +125,17 @@ dependencies {
compileOnly "org.opensearch:opensearch:${opensearch_version}"
}

ext {
securityPluginVersion = property('security-plugin.version')
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
}

group = 'org.opensearch'
version = securityPluginVersion
description = 'OpenSearch Security'

version = property('security-plugin.version')
if (buildVersionQualifier) {
version += "-${buildVersionQualifier}"
}
if (isSnapshot) {
version += "-SNAPSHOT"
}

description = 'OpenSearch Security'


java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11
Expand Down Expand Up @@ -326,22 +322,19 @@ task bundleSecurityAdminStandaloneTarGz(dependsOn: jar, type: Tar) {
}

task createPluginDescriptor() {
if (opensearch_version.contains("-SNAPSHOT")) {
opensearch_version=opensearch_version.substring(0, opensearch_version.length() - 9)
}
List<String> descriptorProperties = [
"description=Provide access control related features for OpenSearch",
"version=${version}",
"version=${version.tokenize('-')[0]}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would this change achieve?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously our version string would only be the numeric version 2.0.0 now it can include 2.0.0-alpha and this is not accepted in the descriptor file. String.tokenize(delim)[0] is a quick way in groovy to substring before the given token.

"name=opensearch-security",
"classname=org.opensearch.security.OpenSearchSecurityPlugin",
"java.version=${java.targetCompatibility}",
"opensearch.version=${opensearch_version}",
"opensearch.version=${opensearch_version.tokenize('-')[0]}",
]

new File("plugin-descriptor.properties").text = descriptorProperties.join ("\n")
}
bundle.doLast() {
new File("plugin-descriptor.properties").delete()
new File("plugin-descriptor.properties").delete()
}

tasks.assemble.dependsOn(bundle)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sets the version of the Security plugin
security-plugin.version=2.0.0.0
# Sets the version of OpenSearch this plugin should be built with
opensearch-core.version=2.0.0
opensearch-core.version=2.0.0-alpha1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ public void postIndex(ShardId shardId, Index index, IndexResult result) {
if(previousContent == null) {
//no previous content
if(!result.isCreated()) {
log.warn("No previous content and not created (its an update but do not find orig source) for {}/{}/{}/{}", index.startTime(), shardId, index.type(), index.id());
log.warn("No previous content and not created (its an update but do not find orig source) for {}/{}/{}", index.startTime(), shardId, index.id());
}
assert result.isCreated():"No previous content and not created";
} else {
if(result.isCreated()) {
log.warn("Previous content and created for {}/{}/{}/{}", index.startTime(), shardId, index.type(), index.id());
log.warn("Previous content and created for {}/{}/{}", index.startTime(), shardId, index.id());
}
assert !result.isCreated():"Previous content and created";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public void binaryFieldRead(final FieldInfo fieldInfo, byte[] fieldValue) {
}
}

public void stringFieldRead(final FieldInfo fieldInfo, final byte[] fieldValue) {
public void stringFieldRead(final FieldInfo fieldInfo, final String fieldValue) {
try {
if(!recordField(fieldInfo.name, true)) {
return;
}
fieldRead0(fieldInfo.name, new String(fieldValue, StandardCharsets.UTF_8));
fieldRead0(fieldInfo.name, fieldValue);
} catch (Exception e) {
log.error("Unexpected error reading string field '{}' in index '{}'", fieldInfo.name, index.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,6 @@ public void checkIntegrity() throws IOException {
public void close() throws IOException {
in.close();
}

@Override
public long ramBytesUsed() {
return in.ramBytesUsed();
}
}

@Override
Expand Down Expand Up @@ -521,7 +516,7 @@ public int hashCode() {
}

@Override
public void stringField(final FieldInfo fieldInfo, final byte[] value) throws IOException {
public void stringField(final FieldInfo fieldInfo, final String value) throws IOException {
fieldReadCallback.stringFieldRead(fieldInfo, value);
delegate.stringField(fieldInfo, value);
}
Expand Down Expand Up @@ -610,7 +605,7 @@ public int hashCode() {
}

@Override
public void stringField(final FieldInfo fieldInfo, final byte[] value) throws IOException {
public void stringField(final FieldInfo fieldInfo, final String value) throws IOException {
delegate.stringField(fieldInfo, value);
}

Expand Down Expand Up @@ -681,7 +676,7 @@ public int hashCode() {
}

@Override
public void stringField(final FieldInfo fieldInfo, final byte[] value) throws IOException {
public void stringField(final FieldInfo fieldInfo, final String value) throws IOException {
final Optional<MaskedField> mf = maskedFieldsMap.getMaskedField(fieldInfo.name);

if(mf.isPresent()) {
Expand Down Expand Up @@ -868,11 +863,6 @@ private SortedDocValues wrapSortedDocValues(final String field, final SortedDocV
if (mf != null) {
return new SortedDocValues() {

@Override
public BytesRef binaryValue() throws IOException {
return mf.mask(sortedDocValues.binaryValue());
}

@Override
public int lookupTerm(BytesRef key) throws IOException {
return sortedDocValues.lookupTerm(key);
Expand Down
12 changes: 4 additions & 8 deletions src/test/java/org/opensearch/security/TracingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,10 @@ public void testAdvancedMapping() throws Exception {
setup(Settings.EMPTY, new DynamicSecurityConfig(), Settings.EMPTY, true, ClusterConfiguration.DEFAULT);

try (Client tc = getClient()) {
tc.admin().indices().create(new CreateIndexRequest("myindex1")
.mapping("mytype1", FileHelper.loadFile("mapping1.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")
.mapping("mytype2", FileHelper.loadFile("mapping2.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex3")
.mapping("mytype3", FileHelper.loadFile("mapping3.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex4")
.mapping("mytype4", FileHelper.loadFile("mapping4.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex1")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex3")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex4")).actionGet();
}

RestHelper rh = nonSslRestHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,10 @@ public void testAdvancedMapping() throws Exception {
rh.executePutRequest("_opendistro/_security/api/audit/config", AuditTestUtils.createAuditPayload(settings), encodeBasicHeader("admin", "admin"));

try (Client tc = getClient()) {
tc.admin().indices().create(new CreateIndexRequest("myindex1")
.mapping("mytype1", FileHelper.loadFile("mapping1.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")
.mapping("mytype2", FileHelper.loadFile("mapping2.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex3")
.mapping("mytype3", FileHelper.loadFile("mapping3.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex4")
.mapping("mytype4", FileHelper.loadFile("mapping4.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex1")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex3")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex4")).actionGet();
}

System.out.println("############ write into mapping 1");
Expand Down Expand Up @@ -391,10 +387,8 @@ public void testImmutableIndex() throws Exception {
rh.executePutRequest("_opendistro/_security/api/audit/config", AuditTestUtils.createAuditPayload(Settings.EMPTY), encodeBasicHeader("admin", "admin"));

try (Client tc = getClient()) {
tc.admin().indices().create(new CreateIndexRequest("myindex1")
.mapping("mytype1", FileHelper.loadFile("mapping1.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")
.mapping("mytype2", FileHelper.loadFile("mapping1.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex1")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")).actionGet();
}

System.out.println("############ immutable 1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class CustomFieldMaskedComplexMappingTest extends AbstractDlsFlsTest{
protected void populateData(Client tc) {

try {
tc.admin().indices().create(new CreateIndexRequest("logs").mapping("_doc", FileHelper.loadFile("dlsfls/masked_field_mapping.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("logs")).actionGet();


byte[] data = FileHelper.loadFile("dlsfls/logs_bulk_data.json").getBytes(StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,25 @@ public class DlsNestedTest extends AbstractDlsFlsTest{
protected void populateData(Client tc) {

String mapping = "{" +
" \"mytype\" : {" +
" \"properties\" : {" +
" \"amount\" : {\"type\": \"integer\"}," +
" \"owner\" : {\"type\": \"text\"}," +
" \"my_nested_object\" : {\"type\" : \"nested\"}" +
" }" +
" }" +
" }" +
"";

tc.admin().indices().create(new CreateIndexRequest("deals")
.settings(Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build())
.mapping("mytype", mapping, XContentType.JSON)).actionGet();
.mapping(mapping, XContentType.JSON)).actionGet();

//tc.index(new IndexRequest("deals").id("3").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
// .source("{\"amount\": 7,\"owner\": \"a\", \"my_nested_object\" : {\"name\": \"spock\"}}", XContentType.JSON)).actionGet();
//tc.index(new IndexRequest("deals").id("4").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
// .source("{\"amount\": 8, \"my_nested_object\" : {\"name\": \"spock\"}}", XContentType.JSON)).actionGet();
//tc.index(new IndexRequest("deals").id("5").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
// .source("{\"amount\": 1400,\"owner\": \"a\", \"my_nested_object\" : {\"name\": \"spock\"}}", XContentType.JSON)).actionGet();
tc.index(new IndexRequest("deals").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
tc.index(new IndexRequest("deals").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.source("{\"amount\": 1500,\"owner\": \"b\", \"my_nested_object\" : {\"name\": \"spock\"}}", XContentType.JSON)).actionGet();
}

Expand Down
Loading