Skip to content

Commit 890376a

Browse files
authored
[Fix-16918][Task] Make task working directory to 775 (#16923)
1 parent 7495642 commit 890376a

File tree

12 files changed

+45
-38
lines changed

12 files changed

+45
-38
lines changed

docs/docs/en/guide/security/security.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Administrator login, default username/password: admin/dolphinscheduler123
1919
- Tenant Code: **The tenant code is the user on Linux, unique and cannot be repeated**
2020
- The administrator enters the `Security Center->Tenant Management` page, and clicks the `Create Tenant` button to create a tenant.
2121

22-
> Note: Currently, only admin users can modify tenant.
22+
> Note:
23+
> 1. Currently, only admin users can modify tenant.
24+
> 2. If you create a tenant manually in the Linux, you need to add the manually created tenant to the dolphinscheduler bootstrap user's group, so that the tenant will have enough working directory permissions.
2325
2426
![create-tenant](../../../../img/new_ui/dev/security/create-tenant.png)
2527

docs/docs/zh/guide/security/security.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
- 租户编码:**租户编码是 Linux上 的用户,唯一,不能重复**
1919
- 管理员进入安全中心->租户管理页面,点击“创建租户”按钮,创建租户。
2020

21-
> 注意:目前仅有 admin 用户可以修改租户。
21+
> 注意:
22+
> 1. 目前仅有 admin 用户可以修改租户;
23+
> 2. 如果您在 Linux 中手动创建一个租户,则需要将手动创建的租户添加到 dolphinscheduler 启动用户组,以便该租户拥有足够的工作目录权限。
2224
2325
![create-tenant](../../../../img/new_ui/dev/security/create-tenant.png)
2426

dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public class FileUtils {
6262

6363
public static final String KUBE_CONFIG_FILE = "config";
6464

65-
private static final Set<PosixFilePermission> PERMISSION_755 = PosixFilePermissions.fromString("rwxr-xr-x");
65+
public static final Set<PosixFilePermission> PERMISSION_755 = PosixFilePermissions.fromString("rwxr-xr-x");
66+
67+
public static final Set<PosixFilePermission> PERMISSION_775 = PosixFilePermissions.fromString("rwxrwxr-x");
6668

6769
/**
6870
* get download file absolute path and name
@@ -239,7 +241,7 @@ public static String getFileChecksum(String pathName) throws IOException {
239241
public static void createFileWith755(@NonNull Path path) throws IOException {
240242
final Path parent = path.getParent();
241243
if (!parent.toFile().exists()) {
242-
createDirectoryWith755(parent);
244+
createDirectoryWithPermission(parent, PERMISSION_755);
243245
}
244246
if (SystemUtils.IS_OS_WINDOWS) {
245247
Files.createFile(path);
@@ -249,29 +251,6 @@ public static void createFileWith755(@NonNull Path path) throws IOException {
249251
}
250252
}
251253

252-
public static void createDirectoryWith755(@NonNull Path path) throws IOException {
253-
if (path.toFile().exists()) {
254-
return;
255-
}
256-
if (OSUtils.isWindows()) {
257-
Files.createDirectories(path);
258-
} else {
259-
Path parent = path.getParent();
260-
if (parent != null && !parent.toFile().exists()) {
261-
createDirectoryWith755(parent);
262-
}
263-
264-
try {
265-
Files.createDirectory(path);
266-
Files.setPosixFilePermissions(path, PERMISSION_755);
267-
} catch (FileAlreadyExistsException fileAlreadyExistsException) {
268-
// Catch the FileAlreadyExistsException here to avoid create the same parent directory in parallel
269-
log.debug("The directory: {} already exists", path);
270-
}
271-
272-
}
273-
}
274-
275254
public static void setFileTo755(File file) throws IOException {
276255
if (OSUtils.isWindows()) {
277256
return;
@@ -289,6 +268,29 @@ public static void setFileTo755(File file) throws IOException {
289268
}
290269
}
291270

271+
public static void createDirectoryWithPermission(@NonNull Path path,
272+
@NonNull Set<PosixFilePermission> permissions) throws IOException {
273+
if (path.toFile().exists()) {
274+
return;
275+
}
276+
277+
if (OSUtils.isWindows()) {
278+
Files.createDirectories(path);
279+
} else {
280+
Path parent = path.getParent();
281+
if (parent != null && !parent.toFile().exists()) {
282+
createDirectoryWithPermission(parent, permissions);
283+
}
284+
285+
try {
286+
Files.createDirectory(path);
287+
Files.setPosixFilePermissions(path, permissions);
288+
} catch (FileAlreadyExistsException fileAlreadyExistsException) {
289+
log.error("The directory: {} already exists", path);
290+
}
291+
}
292+
}
293+
292294
public static String concatFilePath(String... paths) {
293295
if (paths.length == 0) {
294296
throw new IllegalArgumentException("At least one path should be provided");

dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ public void testGetProcessExecDir() {
6060
}
6161

6262
@Test
63-
public void createDirectoryWith755() throws IOException {
63+
public void testCreateDirectoryWithPermission() throws IOException {
6464
Path path = Paths.get("/tmp/createWorkDirAndUserIfAbsent");
6565
try {
66-
FileUtils.createDirectoryWith755(path);
66+
FileUtils.createDirectoryWithPermission(path, FileUtils.PERMISSION_755);
6767
File file = path.toFile();
6868
Assertions.assertTrue(file.exists());
6969
Assertions.assertTrue(file.isDirectory());
7070
Assertions.assertTrue(file.canExecute());
7171
Assertions.assertTrue(file.canRead());
7272
Assertions.assertTrue(file.canWrite());
7373

74-
FileUtils.createDirectoryWith755(Paths.get("/"));
74+
FileUtils.createDirectoryWithPermission(Paths.get("/"), FileUtils.PERMISSION_755);
7575
} catch (Exception e) {
7676
e.printStackTrace();
7777
Assertions.fail(e.getMessage());

dolphinscheduler-storage-plugin/dolphinscheduler-storage-abs/src/main/java/org/apache/dolphinscheduler/plugin/storage/abs/AbsStorageOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void download(String srcFilePath, String dstFilePath, boolean overwrite)
9999
if (dstFile.isDirectory()) {
100100
Files.delete(dstFile.toPath());
101101
} else {
102-
FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
102+
FileUtils.createDirectoryWithPermission(dstFile.getParentFile().toPath(), FileUtils.PERMISSION_755);
103103
}
104104

105105
BlobClient blobClient = blobContainerClient.getBlobClient(srcFilePath);

dolphinscheduler-storage-plugin/dolphinscheduler-storage-cos/src/main/java/org/apache/dolphinscheduler/plugin/storage/cos/CosStorageOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void download(String srcFilePath, String dstFilePath, boolean overwrite)
148148
if (dstFile.isDirectory()) {
149149
Files.delete(dstFile.toPath());
150150
} else {
151-
FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
151+
FileUtils.createDirectoryWithPermission(dstFile.getParentFile().toPath(), FileUtils.PERMISSION_755);
152152
}
153153

154154
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, cosKey);

dolphinscheduler-storage-plugin/dolphinscheduler-storage-gcs/src/main/java/org/apache/dolphinscheduler/plugin/storage/gcs/GcsStorageOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void download(String srcFilePath, String dstFilePath, boolean overwrite)
112112
if (dstFile.isDirectory()) {
113113
Files.delete(dstFile.toPath());
114114
} else {
115-
FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
115+
FileUtils.createDirectoryWithPermission(dstFile.getParentFile().toPath(), FileUtils.PERMISSION_755);
116116
}
117117

118118
Blob blob = gcsStorage.get(BlobId.of(bucketName, srcFilePath));

dolphinscheduler-storage-plugin/dolphinscheduler-storage-obs/src/main/java/org/apache/dolphinscheduler/plugin/storage/obs/ObsStorageOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void download(String srcFilePath, String dstFilePath, boolean overwrite)
111111
if (dstFile.isDirectory()) {
112112
Files.delete(dstFile.toPath());
113113
} else {
114-
FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
114+
FileUtils.createDirectoryWithPermission(dstFile.getParentFile().toPath(), FileUtils.PERMISSION_755);
115115
}
116116
ObsObject obsObject = obsClient.getObject(bucketName, srcFilePath);
117117
try (

dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss/OssStorageOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void download(String srcFilePath,
169169
if (dstFile.isDirectory()) {
170170
Files.delete(dstFile.toPath());
171171
} else {
172-
FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
172+
FileUtils.createDirectoryWithPermission(dstFile.getParentFile().toPath(), FileUtils.PERMISSION_755);
173173
}
174174
OSSObject ossObject = ossClient.getObject(bucketName, srcFilePath);
175175
try (

dolphinscheduler-storage-plugin/dolphinscheduler-storage-s3/src/main/java/org/apache/dolphinscheduler/plugin/storage/s3/S3StorageOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void download(String srcFilePath,
113113
if (dstFile.isDirectory()) {
114114
Files.delete(dstFile.toPath());
115115
} else {
116-
FileUtils.createDirectoryWith755(dstFile.getParentFile().toPath());
116+
FileUtils.createDirectoryWithPermission(dstFile.getParentFile().toPath(), FileUtils.PERMISSION_755);
117117
}
118118
S3Object o = s3Client.getObject(bucketName, srcFilePath);
119119
try (

0 commit comments

Comments
 (0)