Skip to content

[RORDEV-1442] ES 9.0.0-rc1 support #1093

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

Merged
merged 3 commits into from
Apr 14, 2025
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
1 change: 1 addition & 0 deletions ci/supported-es-versions/es9x.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
9.0.0-rc1
9.0.0-beta1
2 changes: 1 addition & 1 deletion es90x/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
latestSupportedEsVersion=9.0.0-beta1
latestSupportedEsVersion=9.0.0-rc1
9 changes: 9 additions & 0 deletions es90x/plugin-metadata/entitlement-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALL-UNNAMED:
- files:
- relative_path: ../
relative_to: config
mode: read
- manage_threads
- inbound_network
- outbound_network
- create_class_loader
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import scala.language.postfixOps
private[patches] class Es80xPatch(rorPluginDirectory: RorPluginDirectory, esVersion: SemVer)
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
new ElasticsearchJarPatchCreator(
ModifyPolicyUtilClass,
ModifyBootstrapPolicyUtilClass,
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
),
new RorSecurityPolicyPatchCreator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private[patches] class Es813xPatch(rorPluginDirectory: RorPluginDirectory, esVer
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
new ElasticsearchJarPatchCreator(
OpenModule,
ModifyPolicyUtilClass,
ModifyBootstrapPolicyUtilClass,
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
),
new RorSecurityPolicyPatchCreator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private[patches] class Es814xPatch(rorPluginDirectory: RorPluginDirectory, esVer
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
new ElasticsearchJarPatchCreator(
OpenModule,
ModifyPolicyUtilClass,
ModifyBootstrapPolicyUtilClass,
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
),
new RorSecurityPolicyPatchCreator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private[patches] class Es815xPatch(rorPluginDirectory: RorPluginDirectory, esVer
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
new ElasticsearchJarPatchCreator(
OpenModule,
ModifyPolicyUtilClass,
ModifyBootstrapPolicyUtilClass,
new SecurityManagerShouldAllowReadingEsConfigFile(esVersion),
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private[patches] class Es83xPatch(rorPluginDirectory: RorPluginDirectory, esVers
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
new ElasticsearchJarPatchCreator(
OpenModule,
ModifyPolicyUtilClass,
ModifyBootstrapPolicyUtilClass,
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
),
new RorSecurityPolicyPatchCreator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private[patches] class Es89xPatch(rorPluginDirectory: RorPluginDirectory, esVers
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
new ElasticsearchJarPatchCreator(
OpenModule,
ModifyPolicyUtilClass,
ModifyBootstrapPolicyUtilClass,
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
),
new RorSecurityPolicyPatchCreator(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of ReadonlyREST.
*
* ReadonlyREST is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ReadonlyREST is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/
*/
package tech.beshu.ror.tools.core.patches

import just.semver.SemVer
import tech.beshu.ror.tools.core.patches.base.TransportNetty4AwareEsPatch
import tech.beshu.ror.tools.core.patches.internal.RorPluginDirectory
import tech.beshu.ror.tools.core.patches.internal.filePatchers.*
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.*

import scala.language.postfixOps

private[patches] class Es90xPatch(rorPluginDirectory: RorPluginDirectory, esVersion: SemVer)
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
new ElasticsearchJarPatchCreator(
OpenModule,
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
),
new EntitlementJarPatchCreator(
ModifyEntitlementRuntimePolicyUtilsClass,
),
new XPackCoreJarPatchCreator(
OpenModule,
DisabledAsyncSearchSecurity
),
new XPackSecurityJarPatchCreator(
OpenModule,
DeactivateSecurityActionFilter,
DeactivateAuthenticationServiceInHttpTransport,
DummyAuthorizeInAuthorizationService
),
new XPackIlmJarPatchCreator(
OpenModule
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ object EsPatch {
val rorPluginDirectory = new RorPluginDirectory(esDirectory)
new EsPatchLoggingDecorator(
readEsVersion(esDirectory) match {
case esVersion if esVersion >= es900rc1 => new Es90xPatch(rorPluginDirectory, esVersion)
case esVersion if esVersion >= es8150 => new Es815xPatch(rorPluginDirectory, esVersion)
case esVersion if esVersion >= es8140 => new Es814xPatch(rorPluginDirectory, esVersion)
case esVersion if esVersion >= es8130 => new Es813xPatch(rorPluginDirectory, esVersion)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of ReadonlyREST.
*
* ReadonlyREST is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ReadonlyREST is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/
*/
package tech.beshu.ror.tools.core.patches.internal.filePatchers

import just.semver.SemVer
import tech.beshu.ror.tools.core.patches.internal.modifiers.FileModifier
import tech.beshu.ror.tools.core.patches.internal.{FileModifiersBasedPatch, RorPluginDirectory}

private[patches] class EntitlementJarPatchCreator(patchingSteps: FileModifier*)
extends FilePatchCreator[EntitlementJarPatch] {

override def create(rorPluginDirectory: RorPluginDirectory,
esVersion: SemVer): EntitlementJarPatch =
new EntitlementJarPatch(rorPluginDirectory, esVersion, patchingSteps)
}

private[patches] class EntitlementJarPatch(rorPluginDirectory: RorPluginDirectory,
esVersion: SemVer,
patchingSteps: Iterable[FileModifier])
extends FileModifiersBasedPatch(
rorPluginDirectory = rorPluginDirectory,
fileToPatchPath = rorPluginDirectory.esDirectory.libPath / s"elasticsearch-entitlement-${esVersion.render}.jar",
patchingSteps = patchingSteps
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import tech.beshu.ror.tools.core.patches.internal.modifiers.BytecodeJarModifier

import java.io.{File, InputStream}

private [patches] object ModifyPolicyUtilClass extends BytecodeJarModifier {
private [patches] object ModifyBootstrapPolicyUtilClass extends BytecodeJarModifier {

override def apply(jar: File): Unit = {
modifyFileInJar(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* This file is part of ReadonlyREST.
*
* ReadonlyREST is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ReadonlyREST is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/
*/
package tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars

import org.objectweb.asm.*
import tech.beshu.ror.tools.core.patches.internal.modifiers.BytecodeJarModifier

import java.io.{File, InputStream}

private [patches] object ModifyEntitlementRuntimePolicyUtilsClass extends BytecodeJarModifier {

override def apply(jar: File): Unit = {
modifyFileInJar(
jar = jar,
filePathString = "org/elasticsearch/entitlement/runtime/policy/PolicyUtils.class",
processFileContent = doTreatRorPluginAsInternalPlugin
)
}

private def doTreatRorPluginAsInternalPlugin(moduleInputStream: InputStream) = {
val reader = new ClassReader(moduleInputStream)
val writer = new ClassWriter(reader, 0)
reader.accept(new EsClassVisitor(writer), 0)
writer.toByteArray
}

private class EsClassVisitor(writer: ClassWriter)
extends ClassVisitor(Opcodes.ASM9, writer) {

override def visitMethod(access: Int,
name: String,
descriptor: String,
signature: String,
exceptions: Array[String]): MethodVisitor = {
name match {
case "parsePolicyIfExists" =>
new TreatRorPluginAsInternalPlugin(
super.visitMethod(access, name, descriptor, signature, exceptions)
)
case _ =>
super.visitMethod(access, name, descriptor, signature, exceptions)
}
}
}


private class TreatRorPluginAsInternalPlugin(underlying: MethodVisitor)
extends MethodVisitor(Opcodes.ASM9) {

override def visitCode(): Unit = {
underlying.visitCode()
val label0 = new Label()
underlying.visitLabel(label0)
underlying.visitLineNumber(142, label0)
underlying.visitVarInsn(Opcodes.ALOAD, 1)
underlying.visitInsn(Opcodes.ICONST_0)
underlying.visitTypeInsn(Opcodes.ANEWARRAY, "java/nio/file/LinkOption")
underlying.visitMethodInsn(Opcodes.INVOKESTATIC, "java/nio/file/Files", "exists", "(Ljava/nio/file/Path;[Ljava/nio/file/LinkOption;)Z", false)
val label1 = new Label()
underlying.visitJumpInsn(Opcodes.IFEQ, label1)
val label2 = new Label()
underlying.visitLabel(label2)
underlying.visitLineNumber(143, label2)
underlying.visitLdcInsn("readonlyrest")
underlying.visitVarInsn(Opcodes.ALOAD, 0)
underlying.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false)
val label3 = new Label()
underlying.visitJumpInsn(Opcodes.IFEQ, label3)
underlying.visitInsn(Opcodes.ICONST_0)
val label4 = new Label()
underlying.visitJumpInsn(Opcodes.GOTO, label4)
underlying.visitLabel(label3)
underlying.visitFrame(Opcodes.F_SAME, 0, null, 0, null)
underlying.visitVarInsn(Opcodes.ILOAD, 2)
underlying.visitLabel(label4)
underlying.visitFrame(Opcodes.F_SAME1, 0, null, 1, Array(Opcodes.INTEGER))
underlying.visitVarInsn(Opcodes.ISTORE, 3)
val label5 = new Label()
underlying.visitLabel(label5)
underlying.visitLineNumber(144, label5)
underlying.visitTypeInsn(Opcodes.NEW, "org/elasticsearch/entitlement/runtime/policy/PolicyParser")
underlying.visitInsn(Opcodes.DUP)
underlying.visitVarInsn(Opcodes.ALOAD, 1)
underlying.visitInsn(Opcodes.ICONST_1)
underlying.visitTypeInsn(Opcodes.ANEWARRAY, "java/nio/file/OpenOption")
underlying.visitInsn(Opcodes.DUP)
underlying.visitInsn(Opcodes.ICONST_0)
underlying.visitFieldInsn(Opcodes.GETSTATIC, "java/nio/file/StandardOpenOption", "READ", "Ljava/nio/file/StandardOpenOption;")
underlying.visitInsn(Opcodes.AASTORE)
underlying.visitMethodInsn(Opcodes.INVOKESTATIC, "java/nio/file/Files", "newInputStream", "(Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;", false)
underlying.visitVarInsn(Opcodes.ALOAD, 0)
underlying.visitVarInsn(Opcodes.ILOAD, 3)
underlying.visitMethodInsn(Opcodes.INVOKESPECIAL, "org/elasticsearch/entitlement/runtime/policy/PolicyParser", "<init>", "(Ljava/io/InputStream;Ljava/lang/String;Z)V", false)
underlying.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/elasticsearch/entitlement/runtime/policy/PolicyParser", "parsePolicy", "()Lorg/elasticsearch/entitlement/runtime/policy/Policy;", false)
underlying.visitInsn(Opcodes.ARETURN)
underlying.visitLabel(label1)
underlying.visitLineNumber(146, label1)
underlying.visitFrame(Opcodes.F_SAME, 0, null, 0, null)
underlying.visitTypeInsn(Opcodes.NEW, "org/elasticsearch/entitlement/runtime/policy/Policy")
underlying.visitInsn(Opcodes.DUP)
underlying.visitVarInsn(Opcodes.ALOAD, 0)
underlying.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/List", "of", "()Ljava/util/List;", true)
underlying.visitMethodInsn(Opcodes.INVOKESPECIAL, "org/elasticsearch/entitlement/runtime/policy/Policy", "<init>", "(Ljava/lang/String;Ljava/util/List;)V", false)
underlying.visitInsn(Opcodes.ARETURN)
val label6 = new Label()
underlying.visitLabel(label6)
underlying.visitLocalVariable("modIsExternalPlugin", "Z", null, label5, label1, 3)
underlying.visitLocalVariable("pluginName", "Ljava/lang/String;", null, label0, label6, 0)
underlying.visitLocalVariable("policyFile", "Ljava/nio/file/Path;", null, label0, label6, 1)
underlying.visitLocalVariable("isExternalPlugin", "Z", null, label0, label6, 2)
underlying.visitMaxs(7, 4)
underlying.visitEnd()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object EsUtil {
private val elasticsearchJar = """^elasticsearch-(\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?)\.jar$""".r
private val transportNetty4JarNameRegex = """^transport-netty4-(\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?)\.jar$""".r

val es900rc1: SemVer = SemVer.unsafeParse("9.0.0-rc1")
val es8150: SemVer = SemVer.unsafeParse("8.15.0")
val es8140: SemVer = SemVer.unsafeParse("8.14.0")
val es8130: SemVer = SemVer.unsafeParse("8.13.0")
Expand Down
Loading