Skip to content

Commit 115212c

Browse files
authored
[RORDEV-1442] ES 9.0.0-rc1 support (#1093)
1 parent 5d9e818 commit 115212c

File tree

15 files changed

+237
-8
lines changed

15 files changed

+237
-8
lines changed

ci/supported-es-versions/es9x.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
9.0.0-rc1
12
9.0.0-beta1

es90x/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latestSupportedEsVersion=9.0.0-beta1
1+
latestSupportedEsVersion=9.0.0-rc1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ALL-UNNAMED:
2+
- files:
3+
- relative_path: ../
4+
relative_to: config
5+
mode: read
6+
- manage_threads
7+
- inbound_network
8+
- outbound_network
9+
- create_class_loader

ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/Es80xPatch.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import scala.language.postfixOps
2828
private[patches] class Es80xPatch(rorPluginDirectory: RorPluginDirectory, esVersion: SemVer)
2929
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
3030
new ElasticsearchJarPatchCreator(
31-
ModifyPolicyUtilClass,
31+
ModifyBootstrapPolicyUtilClass,
3232
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
3333
),
3434
new RorSecurityPolicyPatchCreator(

ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/Es813xPatch.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private[patches] class Es813xPatch(rorPluginDirectory: RorPluginDirectory, esVer
2929
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
3030
new ElasticsearchJarPatchCreator(
3131
OpenModule,
32-
ModifyPolicyUtilClass,
32+
ModifyBootstrapPolicyUtilClass,
3333
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
3434
),
3535
new RorSecurityPolicyPatchCreator(

ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/Es814xPatch.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private[patches] class Es814xPatch(rorPluginDirectory: RorPluginDirectory, esVer
2929
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
3030
new ElasticsearchJarPatchCreator(
3131
OpenModule,
32-
ModifyPolicyUtilClass,
32+
ModifyBootstrapPolicyUtilClass,
3333
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
3434
),
3535
new RorSecurityPolicyPatchCreator(

ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/Es815xPatch.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private[patches] class Es815xPatch(rorPluginDirectory: RorPluginDirectory, esVer
2929
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
3030
new ElasticsearchJarPatchCreator(
3131
OpenModule,
32-
ModifyPolicyUtilClass,
32+
ModifyBootstrapPolicyUtilClass,
3333
new SecurityManagerShouldAllowReadingEsConfigFile(esVersion),
3434
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
3535
),

ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/Es83xPatch.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private[patches] class Es83xPatch(rorPluginDirectory: RorPluginDirectory, esVers
2929
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
3030
new ElasticsearchJarPatchCreator(
3131
OpenModule,
32-
ModifyPolicyUtilClass,
32+
ModifyBootstrapPolicyUtilClass,
3333
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
3434
),
3535
new RorSecurityPolicyPatchCreator(

ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/Es89xPatch.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private[patches] class Es89xPatch(rorPluginDirectory: RorPluginDirectory, esVers
2929
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
3030
new ElasticsearchJarPatchCreator(
3131
OpenModule,
32-
ModifyPolicyUtilClass,
32+
ModifyBootstrapPolicyUtilClass,
3333
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
3434
),
3535
new RorSecurityPolicyPatchCreator(
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* This file is part of ReadonlyREST.
3+
*
4+
* ReadonlyREST is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* ReadonlyREST is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/
16+
*/
17+
package tech.beshu.ror.tools.core.patches
18+
19+
import just.semver.SemVer
20+
import tech.beshu.ror.tools.core.patches.base.TransportNetty4AwareEsPatch
21+
import tech.beshu.ror.tools.core.patches.internal.RorPluginDirectory
22+
import tech.beshu.ror.tools.core.patches.internal.filePatchers.*
23+
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.*
24+
25+
import scala.language.postfixOps
26+
27+
private[patches] class Es90xPatch(rorPluginDirectory: RorPluginDirectory, esVersion: SemVer)
28+
extends TransportNetty4AwareEsPatch(rorPluginDirectory, esVersion,
29+
new ElasticsearchJarPatchCreator(
30+
OpenModule,
31+
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
32+
),
33+
new EntitlementJarPatchCreator(
34+
ModifyEntitlementRuntimePolicyUtilsClass,
35+
),
36+
new XPackCoreJarPatchCreator(
37+
OpenModule,
38+
DisabledAsyncSearchSecurity
39+
),
40+
new XPackSecurityJarPatchCreator(
41+
OpenModule,
42+
DeactivateSecurityActionFilter,
43+
DeactivateAuthenticationServiceInHttpTransport,
44+
DummyAuthorizeInAuthorizationService
45+
),
46+
new XPackIlmJarPatchCreator(
47+
OpenModule
48+
)
49+
)

ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/patches/base/EsPatch.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ object EsPatch {
8989
val rorPluginDirectory = new RorPluginDirectory(esDirectory)
9090
new EsPatchLoggingDecorator(
9191
readEsVersion(esDirectory) match {
92+
case esVersion if esVersion >= es900rc1 => new Es90xPatch(rorPluginDirectory, esVersion)
9293
case esVersion if esVersion >= es8150 => new Es815xPatch(rorPluginDirectory, esVersion)
9394
case esVersion if esVersion >= es8140 => new Es814xPatch(rorPluginDirectory, esVersion)
9495
case esVersion if esVersion >= es8130 => new Es813xPatch(rorPluginDirectory, esVersion)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of ReadonlyREST.
3+
*
4+
* ReadonlyREST is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* ReadonlyREST is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/
16+
*/
17+
package tech.beshu.ror.tools.core.patches.internal.filePatchers
18+
19+
import just.semver.SemVer
20+
import tech.beshu.ror.tools.core.patches.internal.modifiers.FileModifier
21+
import tech.beshu.ror.tools.core.patches.internal.{FileModifiersBasedPatch, RorPluginDirectory}
22+
23+
private[patches] class EntitlementJarPatchCreator(patchingSteps: FileModifier*)
24+
extends FilePatchCreator[EntitlementJarPatch] {
25+
26+
override def create(rorPluginDirectory: RorPluginDirectory,
27+
esVersion: SemVer): EntitlementJarPatch =
28+
new EntitlementJarPatch(rorPluginDirectory, esVersion, patchingSteps)
29+
}
30+
31+
private[patches] class EntitlementJarPatch(rorPluginDirectory: RorPluginDirectory,
32+
esVersion: SemVer,
33+
patchingSteps: Iterable[FileModifier])
34+
extends FileModifiersBasedPatch(
35+
rorPluginDirectory = rorPluginDirectory,
36+
fileToPatchPath = rorPluginDirectory.esDirectory.libPath / s"elasticsearch-entitlement-${esVersion.render}.jar",
37+
patchingSteps = patchingSteps
38+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import tech.beshu.ror.tools.core.patches.internal.modifiers.BytecodeJarModifier
2121

2222
import java.io.{File, InputStream}
2323

24-
private [patches] object ModifyPolicyUtilClass extends BytecodeJarModifier {
24+
private [patches] object ModifyBootstrapPolicyUtilClass extends BytecodeJarModifier {
2525

2626
override def apply(jar: File): Unit = {
2727
modifyFileInJar(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* This file is part of ReadonlyREST.
3+
*
4+
* ReadonlyREST is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* ReadonlyREST is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/
16+
*/
17+
package tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars
18+
19+
import org.objectweb.asm.*
20+
import tech.beshu.ror.tools.core.patches.internal.modifiers.BytecodeJarModifier
21+
22+
import java.io.{File, InputStream}
23+
24+
private [patches] object ModifyEntitlementRuntimePolicyUtilsClass extends BytecodeJarModifier {
25+
26+
override def apply(jar: File): Unit = {
27+
modifyFileInJar(
28+
jar = jar,
29+
filePathString = "org/elasticsearch/entitlement/runtime/policy/PolicyUtils.class",
30+
processFileContent = doTreatRorPluginAsInternalPlugin
31+
)
32+
}
33+
34+
private def doTreatRorPluginAsInternalPlugin(moduleInputStream: InputStream) = {
35+
val reader = new ClassReader(moduleInputStream)
36+
val writer = new ClassWriter(reader, 0)
37+
reader.accept(new EsClassVisitor(writer), 0)
38+
writer.toByteArray
39+
}
40+
41+
private class EsClassVisitor(writer: ClassWriter)
42+
extends ClassVisitor(Opcodes.ASM9, writer) {
43+
44+
override def visitMethod(access: Int,
45+
name: String,
46+
descriptor: String,
47+
signature: String,
48+
exceptions: Array[String]): MethodVisitor = {
49+
name match {
50+
case "parsePolicyIfExists" =>
51+
new TreatRorPluginAsInternalPlugin(
52+
super.visitMethod(access, name, descriptor, signature, exceptions)
53+
)
54+
case _ =>
55+
super.visitMethod(access, name, descriptor, signature, exceptions)
56+
}
57+
}
58+
}
59+
60+
61+
private class TreatRorPluginAsInternalPlugin(underlying: MethodVisitor)
62+
extends MethodVisitor(Opcodes.ASM9) {
63+
64+
override def visitCode(): Unit = {
65+
underlying.visitCode()
66+
val label0 = new Label()
67+
underlying.visitLabel(label0)
68+
underlying.visitLineNumber(142, label0)
69+
underlying.visitVarInsn(Opcodes.ALOAD, 1)
70+
underlying.visitInsn(Opcodes.ICONST_0)
71+
underlying.visitTypeInsn(Opcodes.ANEWARRAY, "java/nio/file/LinkOption")
72+
underlying.visitMethodInsn(Opcodes.INVOKESTATIC, "java/nio/file/Files", "exists", "(Ljava/nio/file/Path;[Ljava/nio/file/LinkOption;)Z", false)
73+
val label1 = new Label()
74+
underlying.visitJumpInsn(Opcodes.IFEQ, label1)
75+
val label2 = new Label()
76+
underlying.visitLabel(label2)
77+
underlying.visitLineNumber(143, label2)
78+
underlying.visitLdcInsn("readonlyrest")
79+
underlying.visitVarInsn(Opcodes.ALOAD, 0)
80+
underlying.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false)
81+
val label3 = new Label()
82+
underlying.visitJumpInsn(Opcodes.IFEQ, label3)
83+
underlying.visitInsn(Opcodes.ICONST_0)
84+
val label4 = new Label()
85+
underlying.visitJumpInsn(Opcodes.GOTO, label4)
86+
underlying.visitLabel(label3)
87+
underlying.visitFrame(Opcodes.F_SAME, 0, null, 0, null)
88+
underlying.visitVarInsn(Opcodes.ILOAD, 2)
89+
underlying.visitLabel(label4)
90+
underlying.visitFrame(Opcodes.F_SAME1, 0, null, 1, Array(Opcodes.INTEGER))
91+
underlying.visitVarInsn(Opcodes.ISTORE, 3)
92+
val label5 = new Label()
93+
underlying.visitLabel(label5)
94+
underlying.visitLineNumber(144, label5)
95+
underlying.visitTypeInsn(Opcodes.NEW, "org/elasticsearch/entitlement/runtime/policy/PolicyParser")
96+
underlying.visitInsn(Opcodes.DUP)
97+
underlying.visitVarInsn(Opcodes.ALOAD, 1)
98+
underlying.visitInsn(Opcodes.ICONST_1)
99+
underlying.visitTypeInsn(Opcodes.ANEWARRAY, "java/nio/file/OpenOption")
100+
underlying.visitInsn(Opcodes.DUP)
101+
underlying.visitInsn(Opcodes.ICONST_0)
102+
underlying.visitFieldInsn(Opcodes.GETSTATIC, "java/nio/file/StandardOpenOption", "READ", "Ljava/nio/file/StandardOpenOption;")
103+
underlying.visitInsn(Opcodes.AASTORE)
104+
underlying.visitMethodInsn(Opcodes.INVOKESTATIC, "java/nio/file/Files", "newInputStream", "(Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;", false)
105+
underlying.visitVarInsn(Opcodes.ALOAD, 0)
106+
underlying.visitVarInsn(Opcodes.ILOAD, 3)
107+
underlying.visitMethodInsn(Opcodes.INVOKESPECIAL, "org/elasticsearch/entitlement/runtime/policy/PolicyParser", "<init>", "(Ljava/io/InputStream;Ljava/lang/String;Z)V", false)
108+
underlying.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/elasticsearch/entitlement/runtime/policy/PolicyParser", "parsePolicy", "()Lorg/elasticsearch/entitlement/runtime/policy/Policy;", false)
109+
underlying.visitInsn(Opcodes.ARETURN)
110+
underlying.visitLabel(label1)
111+
underlying.visitLineNumber(146, label1)
112+
underlying.visitFrame(Opcodes.F_SAME, 0, null, 0, null)
113+
underlying.visitTypeInsn(Opcodes.NEW, "org/elasticsearch/entitlement/runtime/policy/Policy")
114+
underlying.visitInsn(Opcodes.DUP)
115+
underlying.visitVarInsn(Opcodes.ALOAD, 0)
116+
underlying.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/List", "of", "()Ljava/util/List;", true)
117+
underlying.visitMethodInsn(Opcodes.INVOKESPECIAL, "org/elasticsearch/entitlement/runtime/policy/Policy", "<init>", "(Ljava/lang/String;Ljava/util/List;)V", false)
118+
underlying.visitInsn(Opcodes.ARETURN)
119+
val label6 = new Label()
120+
underlying.visitLabel(label6)
121+
underlying.visitLocalVariable("modIsExternalPlugin", "Z", null, label5, label1, 3)
122+
underlying.visitLocalVariable("pluginName", "Ljava/lang/String;", null, label0, label6, 0)
123+
underlying.visitLocalVariable("policyFile", "Ljava/nio/file/Path;", null, label0, label6, 1)
124+
underlying.visitLocalVariable("isExternalPlugin", "Z", null, label0, label6, 2)
125+
underlying.visitMaxs(7, 4)
126+
underlying.visitEnd()
127+
}
128+
}
129+
130+
}

ror-tools-core/src/main/scala/tech/beshu/ror/tools/core/utils/EsUtil.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ object EsUtil {
2424
private val elasticsearchJar = """^elasticsearch-(\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?)\.jar$""".r
2525
private val transportNetty4JarNameRegex = """^transport-netty4-(\d+\.\d+\.\d+(-[a-zA-Z0-9]+)?)\.jar$""".r
2626

27+
val es900rc1: SemVer = SemVer.unsafeParse("9.0.0-rc1")
2728
val es8150: SemVer = SemVer.unsafeParse("8.15.0")
2829
val es8140: SemVer = SemVer.unsafeParse("8.14.0")
2930
val es8130: SemVer = SemVer.unsafeParse("8.13.0")

0 commit comments

Comments
 (0)