Skip to content

Commit 4e20005

Browse files
authored
[RORDEV-1902][RORDEV-1904][RORDEV-1906] ES 9.2.3, 9.1.9, 8.19.9 support (#1196)
1 parent 93284f4 commit 4e20005

File tree

12 files changed

+349
-55
lines changed

12 files changed

+349
-55
lines changed

ci/supported-es-versions/es8x.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
8.19.9
12
8.19.8
23
8.19.7
34
8.19.6

ci/supported-es-versions/es9x.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
9.2.3
12
9.2.2
23
9.2.1
34
9.2.0
5+
9.1.9
46
9.1.8
57
9.1.7
68
9.1.6

ci/upload_es_artifacts.sh

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,4 @@ set -xe
44

55
echo ">>> ($0) UPLOADING ES ARTIFACTS ..."
66

7-
./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=9.2.2
8-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=9.2.1
9-
./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=9.1.8
10-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=9.1.7
11-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.9.2
12-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.9.1
13-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.9.0
14-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.8.2
15-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.8.1
16-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.8.0
17-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.7.1
18-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.7.0
19-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.6.2
20-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.6.1
21-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.6.0
22-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.5.3
23-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.5.2
24-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.5.1
25-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.5.0
26-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.4.3
27-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.4.2
28-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.4.1
29-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.4.0
30-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.3.3
31-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.3.2
32-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.3.1
33-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.3.0
34-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.2.3
35-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.2.2
36-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.2.1
37-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.2.0
38-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.1.3
39-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.1.2
40-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.1.1
41-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.1.0
42-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.0.1
43-
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=8.0.0
7+
#./gradlew --stacktrace --info clean ror-tools:uploadArtifactsFromEsBinaries -PesVersion=9.2.2

es818x/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latestSupportedEsVersion=8.19.8
1+
latestSupportedEsVersion=8.19.9

es91x/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latestSupportedEsVersion=9.1.8
1+
latestSupportedEsVersion=9.1.9

es92x/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latestSupportedEsVersion=9.2.2
1+
latestSupportedEsVersion=9.2.3

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import tech.beshu.ror.tools.core.patches.internal.filePatchers.*
2323
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.*
2424
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.authentication.DummyAuthenticationInAuthenticationChain
2525
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.authorization.DummyAuthorizeInAuthorizationService
26-
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.entitlements.{ModifyEntitlementInitializationClass, ModifyEntitlementRuntimePolicyParserClass, ModifyFilesEntitlementsValidationClass}
27-
import tech.beshu.ror.tools.core.utils.EsUtil.es8182
26+
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.entitlements.*
27+
import tech.beshu.ror.tools.core.utils.EsUtil.{es8182, es8190}
2828

2929
import scala.language.postfixOps
3030

@@ -40,6 +40,10 @@ private[patches] class Es818xPatch(rorPluginDirectory: RorPluginDirectory, esVer
4040
case _ => new ModifyEntitlementInitializationClass(esVersion)
4141
},
4242
ModifyEntitlementRuntimePolicyParserClass,
43+
esVersion match {
44+
case v if v >= es8190 => new ModifyPolicyCheckerImplClass(esVersion)
45+
case _ => new ModifyPolicyManagerClass(esVersion)
46+
},
4347
),
4448
new XPackCoreJarPatchCreator(
4549
OpenModule,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import tech.beshu.ror.tools.core.patches.internal.filePatchers.*
2323
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.*
2424
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.authentication.DummyAuthenticationInAuthenticationChain
2525
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.authorization.DummyAuthorizeInAuthorizationService
26-
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.entitlements.{ModifyEntitlementInitializationClass, ModifyEntitlementRuntimePolicyParserClass, ModifyFilesEntitlementsValidationClass}
27-
import tech.beshu.ror.tools.core.utils.EsUtil.es902
26+
import tech.beshu.ror.tools.core.patches.internal.modifiers.bytecodeJars.entitlements.*
27+
import tech.beshu.ror.tools.core.utils.EsUtil.{es902, es903}
2828

2929
import scala.language.postfixOps
3030

@@ -40,6 +40,10 @@ private[patches] class Es90xPatch(rorPluginDirectory: RorPluginDirectory, esVers
4040
case _ => new ModifyEntitlementInitializationClass(esVersion)
4141
},
4242
ModifyEntitlementRuntimePolicyParserClass,
43+
esVersion match {
44+
case v if v >= es903 => new ModifyPolicyCheckerImplClass(esVersion)
45+
case _ => new ModifyPolicyManagerClass(esVersion)
46+
},
4347
),
4448
new XPackCoreJarPatchCreator(
4549
OpenModule,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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.entitlements
18+
19+
import just.semver.SemVer
20+
import org.objectweb.asm.*
21+
import org.objectweb.asm.tree.*
22+
import tech.beshu.ror.tools.core.patches.internal.modifiers.BytecodeJarModifier
23+
import tech.beshu.ror.tools.core.utils.EsUtil.{es8190, es900, es903}
24+
25+
import java.io.{File, InputStream}
26+
27+
private[patches] class ModifyPolicyCheckerImplClass(esVersion: SemVer)
28+
extends BytecodeJarModifier {
29+
30+
override def apply(jar: File): Unit = {
31+
modifyFileInJar(
32+
jar = jar,
33+
filePathString = "org/elasticsearch/entitlement/runtime/policy/PolicyCheckerImpl.class",
34+
processFileContent = dontValidateFileAccessInCaseOfRorPlugin
35+
)
36+
}
37+
38+
private def dontValidateFileAccessInCaseOfRorPlugin(moduleInputStream: InputStream) = {
39+
val reader = new ClassReader(moduleInputStream)
40+
val writer = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES)
41+
reader.accept(new EsClassVisitor(writer), 0)
42+
writer.toByteArray
43+
}
44+
45+
private class EsClassVisitor(writer: ClassWriter)
46+
extends ClassVisitor(Opcodes.ASM9, writer) {
47+
48+
override def visitMethod(access: Int,
49+
name: String,
50+
descriptor: String,
51+
signature: String,
52+
exceptions: Array[String]): MethodVisitor = {
53+
name match {
54+
case "checkFileRead" =>
55+
esVersion match {
56+
case v if v >= es903 =>
57+
val mv = super.visitMethod(access, name, descriptor, signature, exceptions)
58+
new CheckFileReadMethodShouldNotValidateFileAccessInCaseOfRorPlugin(access, name, descriptor, signature, exceptions, mv)
59+
case v if v >= es900 =>
60+
super.visitMethod(access, name, descriptor, signature, exceptions)
61+
case v if v >= es8190 =>
62+
val mv = super.visitMethod(access, name, descriptor, signature, exceptions)
63+
new CheckFileReadMethodShouldNotValidateFileAccessInCaseOfRorPlugin(access, name, descriptor, signature, exceptions, mv)
64+
case v =>
65+
super.visitMethod(access, name, descriptor, signature, exceptions)
66+
}
67+
case _ =>
68+
super.visitMethod(access, name, descriptor, signature, exceptions)
69+
}
70+
}
71+
}
72+
73+
private class CheckFileReadMethodShouldNotValidateFileAccessInCaseOfRorPlugin(access: Int,
74+
name: String,
75+
desc: String,
76+
signature: String,
77+
exceptions: Array[String],
78+
underlying: MethodVisitor)
79+
extends MethodNode(Opcodes.ASM9, access, name, desc, signature, exceptions) {
80+
81+
override def visitEnd(): Unit = {
82+
patchAllCanReadCalls()
83+
accept(underlying)
84+
}
85+
86+
private def patchAllCanReadCalls(): Unit = {
87+
val insns = instructions
88+
var insn = insns.getFirst
89+
90+
while (insn != null) {
91+
val nextInsn = insn.getNext
92+
93+
insn match {
94+
case m: MethodInsnNode
95+
if m.name == "canRead" && m.desc == "(Ljava/nio/file/Path;)Z" =>
96+
97+
val loadPath = m.getPrevious
98+
val fileAccessCall = if (loadPath != null) loadPath.getPrevious else null
99+
val loadEnt = if (fileAccessCall != null) fileAccessCall.getPrevious else null
100+
101+
(loadEnt, fileAccessCall, loadPath) match {
102+
case (ve: VarInsnNode, fa: MethodInsnNode, vp: VarInsnNode)
103+
if ve.getOpcode == Opcodes.ALOAD &&
104+
vp.getOpcode == Opcodes.ALOAD &&
105+
fa.name == "fileAccess" =>
106+
107+
val entIdx = ve.`var`
108+
val pathIdx = vp.`var`
109+
110+
val lElse = new LabelNode()
111+
val lEnd = new LabelNode()
112+
113+
val replacement = new InsnList()
114+
115+
// "readonlyrest".equals(entitlements.componentName())
116+
replacement.add(new LdcInsnNode("readonlyrest"))
117+
replacement.add(new VarInsnNode(Opcodes.ALOAD, entIdx))
118+
replacement.add(new MethodInsnNode(
119+
Opcodes.INVOKEVIRTUAL,
120+
fa.owner,
121+
"componentName",
122+
"()Ljava/lang/String;",
123+
false
124+
))
125+
replacement.add(new MethodInsnNode(
126+
Opcodes.INVOKEVIRTUAL,
127+
"java/lang/String",
128+
"equals",
129+
"(Ljava/lang/Object;)Z",
130+
false
131+
))
132+
133+
// if false -> else branch
134+
replacement.add(new JumpInsnNode(Opcodes.IFEQ, lElse))
135+
136+
// true branch => push true
137+
replacement.add(new InsnNode(Opcodes.ICONST_1))
138+
replacement.add(new JumpInsnNode(Opcodes.GOTO, lEnd))
139+
140+
// else branch => original entitlements.fileAccess().canRead(path)
141+
replacement.add(lElse)
142+
replacement.add(new VarInsnNode(Opcodes.ALOAD, entIdx))
143+
replacement.add(new MethodInsnNode(fa.getOpcode, fa.owner, fa.name, fa.desc, fa.itf))
144+
replacement.add(new VarInsnNode(Opcodes.ALOAD, pathIdx))
145+
replacement.add(new MethodInsnNode(m.getOpcode, m.owner, m.name, m.desc, m.itf))
146+
147+
replacement.add(lEnd)
148+
149+
// Insert replacement before the start of the old sequence, then remove old nodes
150+
insns.insertBefore(ve, replacement)
151+
insns.remove(ve)
152+
insns.remove(fa)
153+
insns.remove(vp)
154+
insns.remove(m)
155+
case _ => // pattern didn't match; do nothing
156+
}
157+
case _ => // ignore
158+
}
159+
insn = nextInsn
160+
}
161+
}
162+
}
163+
}

0 commit comments

Comments
 (0)