Skip to content
Open
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
6 changes: 6 additions & 0 deletions docs/en/engines/zeta/checkpoint-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ seatunnel:

Notice: namespace must end with "/".

In the official binary package, SeaTunnel copies Zeta checkpoint and IMAP storage dependencies to
`starter/zeta/`. During initialization, SeaTunnel always loads jars from `starter/zeta/common` and
then loads the directory matching `plugin-config.storage.type` when it exists, such as `s3` or
`oss`. If `storage.type` is empty, SeaTunnel falls back to scanning the whole `starter/zeta`
directory. COS jars are still not bundled and must be added to `lib/` manually.

#### OSS

Aliyun OSS based hdfs-file you can refer [Hadoop OSS Docs](https://hadoop.apache.org/docs/stable/hadoop-aliyun/tools/hadoop-aliyun/index.html) to config oss.
Expand Down
10 changes: 8 additions & 2 deletions docs/en/engines/zeta/hybrid-cluster-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ map:
fs.oss.endpoint: OSS endpoint
```

Notice: When using OSS, make sure that the following jars are in the lib directory.
Notice: In the official binary package, the jars required by OSS IMAP storage are copied to
`starter/zeta/common` and `starter/zeta/oss`. You do not need to add them to `lib/` again when
using the packaged distribution. If you build a custom distribution, make sure the following
jars are available in those directories.

The `seatunnel-shade-hadoop3-uber` JAR comes from the [Apache SeaTunnel Shade](https://github.com/apache/seatunnel-shade) project, which provides a shaded (package-relocated) version of the Hadoop client. All third-party classes are relocated under `org.apache.seatunnel.shade.*` to avoid classpath conflicts with SeaTunnel's own dependencies. The version follows the `${library.version}-${seatunnel.shade.version}` format (e.g., `3.1.4-3.0.0`). Refer to the actual JAR file name in your SeaTunnel distribution package for the exact version.

Expand Down Expand Up @@ -394,7 +397,10 @@ map:
fs.s3a.aws.credentials.provider: org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider
```

Notice: When using S3, make sure that the following jars are in the lib directory.
Notice: In the official binary package, the jars required by S3 IMAP storage are copied to
`starter/zeta/common` and `starter/zeta/s3`. You do not need to add them to `lib/` again when
using the packaged distribution. If you build a custom distribution, make sure the following
jars are available in those directories.

Both JARs come from the [Apache SeaTunnel Shade](https://github.com/apache/seatunnel-shade) project:
- `seatunnel-shade-hadoop3-uber` — shaded Hadoop client with relocated packages
Expand Down
10 changes: 8 additions & 2 deletions docs/en/engines/zeta/separated-cluster-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ map:
fs.oss.endpoint: OSS endpoint
```

Notice: When using OSS, make sure that the following jars are in the lib directory.
Notice: In the official binary package, the jars required by OSS IMAP storage are copied to
`starter/zeta/common` and `starter/zeta/oss`. You do not need to add them to `lib/` again when
using the packaged distribution. If you build a custom distribution, make sure the following
jars are available in those directories.

The `seatunnel-shade-hadoop3-uber` JAR comes from the [Apache SeaTunnel Shade](https://github.com/apache/seatunnel-shade) project, which provides a shaded (package-relocated) version of the Hadoop client. All third-party classes are relocated under `org.apache.seatunnel.shade.*` to avoid classpath conflicts with SeaTunnel's own dependencies. The version follows the `${library.version}-${seatunnel.shade.version}` format (e.g., `3.1.4-3.0.0`). Refer to the actual JAR file name in your SeaTunnel distribution package for the exact version.

Expand Down Expand Up @@ -356,7 +359,10 @@ map:
fs.s3a.aws.credentials.provider: org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider
```

Notice: When using S3, make sure that the following jars are in the lib directory.
Notice: In the official binary package, the jars required by S3 IMAP storage are copied to
`starter/zeta/common` and `starter/zeta/s3`. You do not need to add them to `lib/` again when
using the packaged distribution. If you build a custom distribution, make sure the following
jars are available in those directories.

Both JARs come from the [Apache SeaTunnel Shade](https://github.com/apache/seatunnel-shade) project:
- `seatunnel-shade-hadoop3-uber` — shaded Hadoop client with relocated packages
Expand Down
6 changes: 6 additions & 0 deletions docs/zh/engines/zeta/checkpoint-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ seatunnel:

注意: namespace必须以"/"结尾。

在官方二进制发行包中,SeaTunnel 会把 Zeta 的 checkpoint 和 IMAP 存储依赖复制到
`starter/zeta/` 目录。初始化时,SeaTunnel 会始终加载 `starter/zeta/common`,然后按
`plugin-config.storage.type` 加载对应的子目录,比如 `s3` 或 `oss`。如果没有配置
`storage.type`,SeaTunnel 会回退为扫描整个 `starter/zeta` 目录。COS 相关 jar 仍然不会内置,
需要手动放到 `lib/` 目录下。

#### OSS

阿里云OSS是基于hdfs-file,所以你可以参考[Hadoop OSS文档](https://hadoop.apache.org/docs/stable/hadoop-aliyun/tools/hadoop-aliyun/index.html)来配置oss.
Expand Down
4 changes: 3 additions & 1 deletion docs/zh/engines/zeta/hybrid-cluster-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ map:
fs.oss.endpoint: OSS endpoint
```

注意:使用OSS 时,确保 lib目录下有这几个jar。
注意:在官方二进制发行包中,OSS IMAP 存储所需 jar 会被复制到
`starter/zeta/common` 和 `starter/zeta/oss`。使用官方发行包时,不需要再手动放到 `lib/`
目录。如果是自定义打包,请确保以下 jar 位于这两个目录中。

其中 `seatunnel-shade-hadoop3-uber` 来自 [Apache SeaTunnel Shade](https://github.com/apache/seatunnel-shade) 项目,它是对 Hadoop 客户端的 shaded(包重定位)版本,所有第三方类被重定位到 `org.apache.seatunnel.shade.*` 下,避免与 SeaTunnel 自身的依赖产生类路径冲突。版本号格式为 `${library.version}-${seatunnel.shade.version}`(例如 `3.1.4-3.0.0`),具体版本请参考 SeaTunnel 发行包中实际包含的 JAR 文件名。

Expand Down
4 changes: 3 additions & 1 deletion docs/zh/engines/zeta/separated-cluster-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ map:
fs.oss.endpoint: OSS endpoint
```

注意:使用OSS 时,确保 lib目录下有这几个jar。
注意:在官方二进制发行包中,OSS IMAP 存储所需 jar 会被复制到
`starter/zeta/common` 和 `starter/zeta/oss`。使用官方发行包时,不需要再手动放到 `lib/`
目录。如果是自定义打包,请确保以下 jar 位于这两个目录中。

其中 `seatunnel-shade-hadoop3-uber` 来自 [Apache SeaTunnel Shade](https://github.com/apache/seatunnel-shade) 项目,它是对 Hadoop 客户端的 shaded(包重定位)版本,所有第三方类被重定位到 `org.apache.seatunnel.shade.*` 下,避免与 SeaTunnel 自身的依赖产生类路径冲突。版本号格式为 `${library.version}-${seatunnel.shade.version}`(例如 `3.1.4-3.0.0`),具体版本请参考 SeaTunnel 发行包中实际包含的 JAR 文件名。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -60,10 +62,15 @@ public class FileUtils {
public static final long MAX_TAIL_BYTES = Integer.MAX_VALUE - 8;

public static List<URL> searchJarFiles(@NonNull Path directory) throws IOException {
return searchJarFiles(directory, Integer.MAX_VALUE);
}

private static List<URL> searchJarFiles(@NonNull Path directory, int maxDepth)
throws IOException {
if (!directory.toFile().exists()) {
return new ArrayList<>();
}
try (Stream<Path> paths = Files.walk(directory, FileVisitOption.FOLLOW_LINKS)) {
try (Stream<Path> paths = Files.walk(directory, maxDepth, FileVisitOption.FOLLOW_LINKS)) {
return paths.filter(path -> path.toString().endsWith(".jar"))
.map(
path -> {
Expand All @@ -80,6 +87,109 @@ public static List<URL> searchJarFiles(@NonNull Path directory) throws IOExcepti
}
}

/**
* Valid split-layout storage directory names. storage.type is user-supplied configuration;
* restricting it to a bare lowercase identifier is what keeps {@link #searchJarFilesForStorage}
* from resolving outside the starter/zeta root.
*/
private static final Pattern STORAGE_TYPE_PATTERN = Pattern.compile("[a-z0-9_-]+");

/**
* Returns true only when {@code directory} exists and its real path (symlinks resolved) is
* still inside {@code rootRealPath}. A subdirectory that is a symlink pointing outside the
* starter/zeta root must not be scanned: the JAR walk follows links, so an escaping link would
* load engine plugins from unrelated filesystem locations.
*/
private static boolean isContainedDirectory(Path directory, Path rootRealPath)
throws IOException {
if (!Files.isDirectory(directory)) {
return false;
}
Path realPath = directory.toRealPath();
if (!realPath.startsWith(rootRealPath)) {
log.warn(
"Ignoring storage jar directory {} because it resolves to {} outside {}",
directory,
realPath,
rootRealPath);
return false;
}
return true;
}

/**
* Search Zeta storage JAR files from a split starter layout.
*
* <p>When {@code storageType} is configured, SeaTunnel loads jars from {@code common/} and the
* matching storage-specific subdirectory (for example, {@code s3/} or {@code oss/}). If the
* split layout is not available, this method falls back to scanning the whole Zeta directory to
* preserve compatibility with the legacy layout.
*
* @param zetaDirectory The starter/zeta directory
* @param storageType The storage type configured in plugin-config, such as {@code hdfs}, {@code
* s3}, or {@code oss}
* @return List of URLs pointing to JAR files
* @throws IOException if there is an error reading JAR files
*/
public static List<URL> searchJarFilesForStorage(
@NonNull Path zetaDirectory, String storageType) throws IOException {
if (!Files.isDirectory(zetaDirectory)) {
log.debug("Zeta directory does not exist: {}", zetaDirectory);
return new ArrayList<>();
}

if (storageType == null || storageType.trim().isEmpty()) {
return searchJarFiles(zetaDirectory);
}

String normalizedStorageType = storageType.trim().toLowerCase(Locale.ROOT);
// storage.type comes from user configuration, so it must stay a plain directory name.
// Anything path-shaped (separators, "..", drive/scheme prefixes, absolute paths) could
// make resolve() escape the starter/zeta root and load arbitrary JARs into the engine.
// Fail closed to the legacy whole-directory scan, which never leaves zetaDirectory.
if (!STORAGE_TYPE_PATTERN.matcher(normalizedStorageType).matches()) {
log.warn(
"Ignoring illegal storage type '{}' for split storage-jar loading: only "
+ "[a-z0-9_-] names are allowed. Falling back to scanning {}",
storageType,
zetaDirectory);
return searchJarFiles(zetaDirectory);
}

List<URL> jars = new ArrayList<>();
boolean splitLayoutDetected = false;
Path zetaRealPath = zetaDirectory.toRealPath();

Path commonDir = zetaDirectory.resolve("common");
if (isContainedDirectory(commonDir, zetaRealPath)) {
splitLayoutDetected = true;
jars.addAll(searchJarFiles(commonDir));
}

Path storageDir = zetaDirectory.resolve(normalizedStorageType);
if (isContainedDirectory(storageDir, zetaRealPath)) {
splitLayoutDetected = true;
jars.addAll(searchJarFiles(storageDir));
}

if (splitLayoutDetected) {
// Keep root-level jars visible for installations transitioning from the legacy layout.
jars.addAll(searchJarFiles(zetaDirectory, 1));
log.info(
"Loaded {} storage JAR(s) for storage type '{}' from {}",
jars.size(),
normalizedStorageType,
zetaDirectory);
return jars;
}

log.info(
"No split Zeta storage directory found for storage type '{}', scan all JAR(s) under {} instead",
normalizedStorageType,
zetaDirectory);
return searchJarFiles(zetaDirectory);
}

public static String readFileToStr(Path path) {
try {
byte[] bytes = Files.readAllBytes(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

import lombok.NonNull;
Expand All @@ -29,11 +31,17 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class FileUtilsTest {

Expand Down Expand Up @@ -153,6 +161,126 @@ public void createNewFile() throws IOException {
FileUtils.readFileToStr(Paths.get("/tmp/newfolder/newfolder2/newfolde3/test.txt")));
}

@Test
public void testSearchJarFilesForStorageLoadsCommonAndStorageDirectories() throws Exception {
Path zetaDir = Files.createTempDirectory("seatunnel-zeta");
Files.createDirectories(zetaDir.resolve("common"));
Files.createDirectories(zetaDir.resolve("s3"));
Files.createDirectories(zetaDir.resolve("oss"));
Path commonJar = Files.createFile(zetaDir.resolve("common").resolve("common.jar"));
Path storageJar = Files.createFile(zetaDir.resolve("s3").resolve("s3.jar"));
Files.createFile(zetaDir.resolve("oss").resolve("oss.jar"));

Set<String> jarNames =
extractJarNames(FileUtils.searchJarFilesForStorage(zetaDir, " S3 "));

Assertions.assertEquals(
new HashSet<>(
Arrays.asList(
commonJar.getFileName().toString(),
storageJar.getFileName().toString())),
jarNames);
}

@Test
public void testSearchJarFilesForStorageFallsBackToLegacyLayout() throws Exception {
Path zetaDir = Files.createTempDirectory("seatunnel-zeta-legacy");
Path legacyJar = Files.createFile(zetaDir.resolve("legacy.jar"));

Set<String> jarNames = extractJarNames(FileUtils.searchJarFilesForStorage(zetaDir, "hdfs"));

Assertions.assertEquals(
new HashSet<>(Arrays.asList(legacyJar.getFileName().toString())), jarNames);
}

@Test
public void testSearchJarFilesForStorageKeepsLegacyRootJarsInMixedLayout() throws Exception {
Path zetaDir = Files.createTempDirectory("seatunnel-zeta-mixed");
Files.createDirectories(zetaDir.resolve("common"));
Path commonJar = Files.createFile(zetaDir.resolve("common/common.jar"));
Path legacyJar = Files.createFile(zetaDir.resolve("legacy-storage.jar"));

Set<String> jarNames = extractJarNames(FileUtils.searchJarFilesForStorage(zetaDir, "s3"));

Assertions.assertEquals(
new HashSet<>(
Arrays.asList(
commonJar.getFileName().toString(),
legacyJar.getFileName().toString())),
jarNames);
}

/**
* storage.type is user configuration: a path-shaped value must never widen the JAR scan beyond
* the starter/zeta root. A traversal value has to fall back to the legacy scan of the root
* itself and must not pick up JARs from a sibling directory.
*/
@Test
public void testSearchJarFilesForStorageRejectsTraversalStorageType() throws Exception {
Path parent = Files.createTempDirectory("seatunnel-zeta-traversal");
Path zetaDir = Files.createDirectories(parent.resolve("starter"));
Path outsideDir = Files.createDirectories(parent.resolve("outside"));
Files.createFile(outsideDir.resolve("escaped.jar"));
Path legacyJar = Files.createFile(zetaDir.resolve("legacy.jar"));

Set<String> jarNames =
extractJarNames(FileUtils.searchJarFilesForStorage(zetaDir, "../outside"));

Assertions.assertEquals(
new HashSet<>(Arrays.asList(legacyJar.getFileName().toString())), jarNames);
}

/** An absolute storage.type is just as illegal as a relative traversal and must not scan. */
@Test
public void testSearchJarFilesForStorageRejectsAbsoluteStorageType() throws Exception {
Path zetaDir = Files.createTempDirectory("seatunnel-zeta-absolute");
Path legacyJar = Files.createFile(zetaDir.resolve("legacy.jar"));
Path outsideDir = Files.createTempDirectory("seatunnel-zeta-absolute-outside");
Files.createFile(outsideDir.resolve("escaped.jar"));

Set<String> jarNames =
extractJarNames(FileUtils.searchJarFilesForStorage(zetaDir, outsideDir.toString()));

Assertions.assertEquals(
new HashSet<>(Arrays.asList(legacyJar.getFileName().toString())), jarNames);
}

/**
* Even a clean identifier must not be scanned when the matching subdirectory is a symlink
* escaping the starter/zeta root: the JAR walk follows links, so an escaping link would load
* plugins from unrelated filesystem locations. Disabled on Windows because creating symlinks
* there requires elevated privileges on the CI runners.
*/
@Test
@DisabledOnOs(OS.WINDOWS)
public void testSearchJarFilesForStorageIgnoresSymlinkEscapingRoot() throws Exception {
Path parent = Files.createTempDirectory("seatunnel-zeta-symlink");
Path zetaDir = Files.createDirectories(parent.resolve("starter"));
Path outsideDir = Files.createDirectories(parent.resolve("outside"));
Files.createFile(outsideDir.resolve("escaped.jar"));
Files.createSymbolicLink(zetaDir.resolve("s3"), outsideDir);
Files.createDirectories(zetaDir.resolve("common"));
Path commonJar = Files.createFile(zetaDir.resolve("common").resolve("common.jar"));

Set<String> jarNames = extractJarNames(FileUtils.searchJarFilesForStorage(zetaDir, "s3"));

Assertions.assertFalse(jarNames.contains("escaped.jar"));
Assertions.assertTrue(jarNames.contains(commonJar.getFileName().toString()));
}

private Set<String> extractJarNames(List<URL> jarUrls) {
return jarUrls.stream()
.map(
url -> {
try {
return Paths.get(url.toURI()).getFileName().toString();
} catch (Exception e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.toSet());
}

@Test
void readFileTailToStrReturnsWholeFileWhenItFitsTheLimit(@TempDir Path tempDir)
throws IOException {
Expand Down
Loading
Loading