Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
compile "org.jetbrains:annotations:13.0"
compile "com.amazon.opendistroforelasticsearch:notification:${opendistroVersion}.0"
compile "com.amazon.opendistroforelasticsearch:notification:1.13.1.0"
compile "com.amazon.opendistroforelasticsearch:common-utils:${opendistroVersion}.0"
compile "com.github.seancfoley:ipaddress:5.3.3"

testCompile "org.elasticsearch.test:framework:${es_version}"
testCompile "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
Expand Down Expand Up @@ -175,6 +176,7 @@ afterEvaluate {
def firstPlugin = plugins.get(0)
plugins.remove(0)
plugins.add(firstPlugin)

if (securityEnabled) {
node.extraConfigFile("kirk.pem", file("src/test/resources/security/kirk.pem"))
node.extraConfigFile("kirk-key.pem", file("src/test/resources/security/kirk-key.pem"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ object ManagedIndexRunner : ScheduledJobRunner,
private val errorNotificationRetryPolicy = BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(250), 3)
private var jobInterval: Int = DEFAULT_JOB_INTERVAL
private var allowList: List<String> = ALLOW_LIST_NONE
private var hostDenyList: List<String> = emptyList()

fun registerClusterService(clusterService: ClusterService): ManagedIndexRunner {
this.clusterService = clusterService
Expand Down Expand Up @@ -165,6 +166,8 @@ object ManagedIndexRunner : ScheduledJobRunner,
clusterService.clusterSettings.addSettingsUpdateConsumer(ALLOW_LIST) {
allowList = it
}

hostDenyList = settings.getAsList(ManagedIndexSettings.HOST_DENY_LIST)
return this
}

Expand Down Expand Up @@ -225,7 +228,7 @@ object ManagedIndexRunner : ScheduledJobRunner,
}

val state = policy.getStateToExecute(managedIndexMetaData)
val action: Action? = state?.getActionToExecute(clusterService, scriptService, client, managedIndexMetaData)
val action: Action? = state?.getActionToExecute(clusterService, scriptService, client, settings, managedIndexMetaData)
val step: Step? = action?.getStepToExecute()
val currentActionMetaData = action?.getUpdatedActionMetaData(managedIndexMetaData, state)

Expand Down Expand Up @@ -651,7 +654,7 @@ object ManagedIndexRunner : ScheduledJobRunner,
policy.errorNotification?.run {
errorNotificationRetryPolicy.retry(logger) {
withContext(Dispatchers.IO) {
destination.publish(null, compileTemplate(messageTemplate, managedIndexMetaData))
destination.publish(null, compileTemplate(messageTemplate, managedIndexMetaData), hostDenyList)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.step.notification.AttemptNotificationStep
import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.script.ScriptService

class NotificationAction(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData,
config: NotificationActionConfig
) : Action(ActionConfig.ActionType.NOTIFICATION, config, managedIndexMetaData) {

private val attemptNotificationStep = AttemptNotificationStep(clusterService, scriptService, client, config, managedIndexMetaData)
private val attemptNotificationStep = AttemptNotificationStep(clusterService, scriptService, client, settings, config, managedIndexMetaData)
private val steps = listOf(attemptNotificationStep)

override fun getSteps(): List<Step> = steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.io.stream.Writeable
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentFragment
import org.elasticsearch.common.xcontent.XContentBuilder
Expand Down Expand Up @@ -51,6 +52,7 @@ abstract class ActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand Down Expand Up @@ -49,6 +50,7 @@ data class AllocationActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = AllocationAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData
import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand All @@ -46,6 +47,7 @@ data class CloseActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = CloseAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData
import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand All @@ -46,6 +47,7 @@ data class DeleteActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = DeleteAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand Down Expand Up @@ -55,6 +56,7 @@ data class ForceMergeActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = ForceMergeAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand Down Expand Up @@ -53,6 +54,7 @@ data class IndexPriorityActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = IndexPriorityAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand Down Expand Up @@ -59,8 +60,9 @@ data class NotificationActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = NotificationAction(clusterService, scriptService, client, managedIndexMetaData, this)
): Action = NotificationAction(clusterService, scriptService, client, settings, managedIndexMetaData, this)

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData
import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand All @@ -46,6 +47,7 @@ data class OpenActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = OpenAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData
import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand All @@ -46,6 +47,7 @@ data class ReadOnlyActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = ReadOnlyAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData
import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand Down Expand Up @@ -47,6 +48,7 @@ data class ReadWriteActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = ReadWriteAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand Down Expand Up @@ -53,6 +54,7 @@ data class ReplicaCountActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = ReplicaCountAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.unit.ByteSizeValue
import org.elasticsearch.common.unit.TimeValue
import org.elasticsearch.common.xcontent.ToXContent
Expand Down Expand Up @@ -62,6 +63,7 @@ data class RolloverActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = RolloverAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand Down Expand Up @@ -50,6 +51,7 @@ class RollupActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = RollupAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.xcontent.ToXContent
import org.elasticsearch.common.xcontent.ToXContentObject
import org.elasticsearch.common.xcontent.XContentBuilder
Expand Down Expand Up @@ -52,6 +53,7 @@ data class SnapshotActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = SnapshotAction(clusterService, client, managedIndexMetaData, this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagemen
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.model.Transition
import org.elasticsearch.client.Client
import org.elasticsearch.cluster.service.ClusterService
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.script.ScriptService

data class TransitionsActionConfig(
Expand All @@ -31,6 +32,7 @@ data class TransitionsActionConfig(
clusterService: ClusterService,
scriptService: ScriptService,
client: Client,
settings: Settings,
managedIndexMetaData: ManagedIndexMetaData
): Action = TransitionsAction(clusterService, client, managedIndexMetaData, this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.amazon.opendistroforelasticsearch.alerting.destination.message.Custom
import com.amazon.opendistroforelasticsearch.alerting.destination.message.SlackMessage
import com.amazon.opendistroforelasticsearch.alerting.destination.response.DestinationResponse
import com.amazon.opendistroforelasticsearch.indexmanagement.elasticapi.convertToMap
import com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.util.isHostInDenylist
import org.apache.logging.log4j.LogManager
import org.elasticsearch.common.io.stream.StreamInput
import org.elasticsearch.common.io.stream.StreamOutput
Expand Down Expand Up @@ -115,7 +116,7 @@ data class Destination(
}

@Throws(IOException::class)
fun publish(compiledSubject: String?, compiledMessage: String): DestinationResponse {
fun publish(compiledSubject: String?, compiledMessage: String, denyHostRanges: List<String>): DestinationResponse {
val destinationMessage: BaseMessage
when (type) {
DestinationType.CHIME -> {
Expand Down Expand Up @@ -144,6 +145,7 @@ data class Destination(
.withMessage(compiledMessage).build()
}
}
validateDestinationUri(destinationMessage, denyHostRanges)
val response = Notification.publish(destinationMessage) as DestinationResponse
logger.info("Message published for action type: $type, messageid: ${response.responseContent}, statuscode: ${response.statusCode}")
return response
Expand All @@ -161,4 +163,10 @@ data class Destination(
}
return content
}

private fun validateDestinationUri(destinationMessage: BaseMessage, denyHostRanges: List<String>) {
if (destinationMessage.isHostInDenylist(denyHostRanges)) {
throw IllegalArgumentException("The destination address is invalid.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ManagedIndexSettings {
private val ALLOW_LIST_ALL = ActionConfig.ActionType.values().toList().map { it.type }
val ALLOW_LIST_NONE = emptyList<String>()
val SNAPSHOT_DENY_LIST_NONE = emptyList<String>()
const val HOST_DENY_LIST = "opendistro.destination.host.deny_list"

val INDEX_STATE_MANAGEMENT_ENABLED: Setting<Boolean> = Setting.boolSetting(
"opendistro.index_state_management.enabled",
Expand Down
Loading