Skip to content

Commit

Permalink
[RORDEV-1215] ES 7.21.22 support (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
coutoPL authored Jun 15, 2024
1 parent c7c1103 commit 3d58e1e
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions ci/supported-es-versions/es7x.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
7.17.22
7.17.21
7.17.20
7.17.19
Expand Down
2 changes: 1 addition & 1 deletion es717x/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
latestSupportedEsVersion=7.17.21
latestSupportedEsVersion=7.17.22
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import scala.language.postfixOps
private[patches] class Es717xPatch(rorPluginDirectory: RorPluginDirectory, esVersion: SemVer)
extends SimpleEsPatch(rorPluginDirectory, esVersion,
new ElasticsearchJarPatchCreator(
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion)
new RepositoriesServiceAvailableForClusterServiceForAnyTypeOfNode(esVersion),
new SecurityManagerShouldAllowReadingEsConfigFile(esVersion)
),
new XPackCoreJarPatchCreator(
AlwaysGrantApplicationPermission
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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 just.semver.SemVer
import org.objectweb.asm._
import tech.beshu.ror.tools.core.patches.internal.modifiers.BytecodeJarModifier
import tech.beshu.ror.tools.core.utils.EsUtil.{es71722, es800}

import java.io.{File, InputStream}

private[patches] class SecurityManagerShouldAllowReadingEsConfigFile(esVersion: SemVer)
extends BytecodeJarModifier {

override def apply(jar: File): Unit = {
modifyFileInJar(
jar = jar,
filePathString = "org/elasticsearch/bootstrap/Security.class",
processFileContent = removeForbiddingReadPermissionForElasticsearchYmlFile
)
}

private def removeForbiddingReadPermissionForElasticsearchYmlFile(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 = {
def noChanges = super.visitMethod(access, name, descriptor, signature, exceptions)

name match {
case _ if esVersion >= es800 =>
noChanges
case "createForbiddenFilePermissions" if esVersion >= es71722 =>
new ElasticsearchYmlFileShouldBeReadable(super.visitMethod(access, name, descriptor, signature, exceptions))
case _ =>
noChanges
}
}
}

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

private var modifyThePermissionList: Boolean = false

override def visitLdcInsn(value: Any): Unit = {
value match {
case "elasticsearch.yml" =>
modifyThePermissionList = true
super.visitLdcInsn(value)
case "read,readlink,write,delete,execute" if modifyThePermissionList =>
modifyThePermissionList = false
super.visitLdcInsn("write,delete,execute")
case _ =>
super.visitLdcInsn(value)
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object EsUtil {
val es820: SemVer = SemVer.unsafeParse("8.2.0")
val es810: SemVer = SemVer.unsafeParse("8.1.0")
val es800: SemVer = SemVer.unsafeParse("8.0.0")
val es71722: SemVer = SemVer.unsafeParse("7.17.22")
val es71713: SemVer = SemVer.unsafeParse("7.17.13")
val es7110: SemVer = SemVer.unsafeParse("7.11.0")
val es790: SemVer = SemVer.unsafeParse("7.9.0")
Expand Down

0 comments on commit 3d58e1e

Please sign in to comment.