Skip to content

Commit 63984b2

Browse files
authored
Feature/184 introduce security tests (#474)
* 184: Code copied from Ravi's branch Signed-off-by: Stevan Buzejic <buzejic.stevan@gmail.com> * 184: Added security tests. Extended gradle file. Resolved 500 issue once opensearch status exception is raised Signed-off-by: Stevan Buzejic <buzejic.stevan@gmail.com> * 184: Refactored ISM rest test cases to consider forwarded client. Extended test cases and created reusable methods Signed-off-by: Stevan Buzejic <buzejic.stevan@gmail.com> * 184: Removed unused privileges Signed-off-by: Stevan Buzejic <buzejic.stevan@gmail.com> Signed-off-by: Stevan Buzejic <buzejic.stevan@gmail.com>
1 parent 9fb1c26 commit 63984b2

File tree

11 files changed

+1690
-13
lines changed

11 files changed

+1690
-13
lines changed

build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ integTest {
407407
excludeTestsMatching "org.opensearch.indexmanagement.bwc.*IT"
408408
}
409409
}
410+
// Exclude security test
411+
if (System.getProperty("https") == null || System.getProperty("https") == "false") {
412+
filter {
413+
excludeTestsMatching "org.opensearch.*Security*IT"
414+
}
415+
}
410416

411417
// TODO: Fix running notification test against remote cluster with security plugin installed
412418
if (System.getProperty("https") != null) {
@@ -446,6 +452,11 @@ task integTestRemote(type: RestIntegTestTask) {
446452
excludeTestsMatching "org.opensearch.indexmanagement.indexstatemanagement.action.NotificationActionIT"
447453
}
448454
}
455+
456+
if (System.getProperty("test.debug") != null) {
457+
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=8000'
458+
}
459+
449460
// Snapshot action integration tests rely on node level setting path.repo which we can't set remotely
450461
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionIT.class'
451462
}

src/main/kotlin/org/opensearch/indexmanagement/util/IndexManagementException.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.indexmanagement.util
77

88
import org.opensearch.OpenSearchException
9+
import org.opensearch.OpenSearchStatusException
910
import org.opensearch.common.Strings
1011
import org.opensearch.common.ValidationException
1112
import org.opensearch.index.IndexNotFoundException
@@ -37,6 +38,10 @@ class IndexManagementException(message: String, val status: RestStatus, ex: Exce
3738
status = RestStatus.BAD_REQUEST
3839
friendlyMsg = ex.message as String
3940
}
41+
is OpenSearchStatusException -> {
42+
status = ex.status()
43+
friendlyMsg = ex.message as String
44+
}
4045
else -> {
4146
if (!Strings.isNullOrEmpty(ex.message)) {
4247
friendlyMsg = ex.message as String
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.indexmanagement
7+
8+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.addpolicy.AddPolicyAction
9+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.deletepolicy.DeletePolicyAction
10+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.explain.ExplainAction
11+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.getpolicy.GetPoliciesAction
12+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.getpolicy.GetPolicyAction
13+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.indexpolicy.IndexPolicyAction
14+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.managedIndex.ManagedIndexAction
15+
import org.opensearch.indexmanagement.rollup.action.delete.DeleteRollupAction
16+
import org.opensearch.indexmanagement.rollup.action.explain.ExplainRollupAction
17+
import org.opensearch.indexmanagement.rollup.action.get.GetRollupAction
18+
import org.opensearch.indexmanagement.rollup.action.index.IndexRollupAction
19+
import org.opensearch.indexmanagement.rollup.action.mapping.UpdateRollupMappingAction
20+
import org.opensearch.indexmanagement.transform.action.delete.DeleteTransformsAction
21+
import org.opensearch.indexmanagement.transform.action.explain.ExplainTransformAction
22+
import org.opensearch.indexmanagement.transform.action.get.GetTransformAction
23+
import org.opensearch.indexmanagement.transform.action.get.GetTransformsAction
24+
import org.opensearch.indexmanagement.transform.action.index.IndexTransformAction
25+
import org.opensearch.indexmanagement.transform.action.start.StartTransformAction
26+
import org.opensearch.indexmanagement.transform.action.stop.StopTransformAction
27+
28+
// ISM
29+
const val WRITE_POLICY = IndexPolicyAction.NAME
30+
const val ADD_POLICY = AddPolicyAction.NAME
31+
const val GET_POLICIES = GetPoliciesAction.NAME
32+
const val GET_POLICY = GetPolicyAction.NAME
33+
const val EXPLAIN_INDEX = ExplainAction.NAME
34+
const val MANAGED_INDEX = ManagedIndexAction.NAME
35+
const val DELETE_POLICY = DeletePolicyAction.NAME
36+
// Rollup
37+
const val ROLLUP_ALL = "cluster:admin/opendistro/rollup/*"
38+
const val INDEX_ROLLUP = IndexRollupAction.NAME
39+
const val GET_ROLLUP = GetRollupAction.NAME
40+
const val EXPLAIN_ROLLUP = ExplainRollupAction.NAME
41+
const val UPDATE_ROLLUP = UpdateRollupMappingAction.NAME
42+
const val DELETE_ROLLUP = DeleteRollupAction.NAME
43+
// Transform
44+
const val TRANSFORM_ACTION = IndexTransformAction.NAME
45+
const val GET_TRANSFORM = GetTransformAction.NAME
46+
const val EXPLAIN_TRANSFORM = ExplainTransformAction.NAME
47+
const val START_TRANSFORM = StartTransformAction.NAME
48+
const val DELETE_TRANSFORM = DeleteTransformsAction.NAME
49+
const val GET_TRANSFORMS = GetTransformsAction.NAME
50+
const val STOP_TRANSFORM = StopTransformAction.NAME
51+
// In order to execute transform, user need to have health privilege
52+
const val HEALTH = "cluster:monitor/health"
53+
// Index
54+
const val GET_INDEX_MAPPING = "indices:admin/mappings/get"
55+
const val PUT_INDEX_MAPPING = "indices:admin/mapping/put"
56+
const val SEARCH_INDEX = "indices:data/read/search"
57+
const val CREATE_INDEX = "indices:admin/create"
58+
const val WRITE_INDEX = "indices:data/write/index"
59+
const val BULK_WRITE_INDEX = "indices:data/write/bulk*"

0 commit comments

Comments
 (0)