Skip to content

Commit 9220816

Browse files
jeroen-vd-nlmonosouleddumelendez
authored
Use SelinuxContext.SHARED by default for mounting (#7187)
Co-authored-by: monosoul <[email protected]> Co-authored-by: Eddú Meléndez <[email protected]>
1 parent c82049b commit 9220816

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

core/src/main/java/org/testcontainers/containers/Container.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ExecResult {
7979
* @param mode the bind mode
8080
*/
8181
default void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode) {
82-
addFileSystemBind(hostPath, containerPath, mode, SelinuxContext.NONE);
82+
addFileSystemBind(hostPath, containerPath, mode, SelinuxContext.SHARED);
8383
}
8484

8585
/**
@@ -303,7 +303,7 @@ default SELF withClasspathResourceMapping(
303303
final String containerPath,
304304
final BindMode mode
305305
) {
306-
withClasspathResourceMapping(resourcePath, containerPath, mode, SelinuxContext.NONE);
306+
withClasspathResourceMapping(resourcePath, containerPath, mode, SelinuxContext.SHARED);
307307
return self();
308308
}
309309

core/src/main/java/org/testcontainers/containers/GenericContainer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ public SELF withClasspathResourceMapping(
12901290
final String containerPath,
12911291
final BindMode mode
12921292
) {
1293-
return withClasspathResourceMapping(resourcePath, containerPath, mode, SelinuxContext.NONE);
1293+
return withClasspathResourceMapping(resourcePath, containerPath, mode, SelinuxContext.SHARED);
12941294
}
12951295

12961296
/**
@@ -1305,10 +1305,10 @@ public SELF withClasspathResourceMapping(
13051305
) {
13061306
final MountableFile mountableFile = MountableFile.forClasspathResource(resourcePath);
13071307

1308-
if (mode == BindMode.READ_ONLY && selinuxContext == SelinuxContext.NONE) {
1309-
withCopyFileToContainer(mountableFile, containerPath);
1310-
} else {
1308+
if (mode == BindMode.READ_WRITE) {
13111309
addFileSystemBind(mountableFile.getResolvedPath(), containerPath, mode, selinuxContext);
1310+
} else {
1311+
withCopyFileToContainer(mountableFile, containerPath);
13121312
}
13131313

13141314
return self();

core/src/test/java/org/testcontainers/junit/CopyFileToContainerTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,12 @@ public void shouldUseCopyOnlyWithReadOnlyClasspathResources() {
4949
String resource = "/test_copy_to_container.txt";
5050
GenericContainer<?> container = new GenericContainer<>(TestImages.TINY_IMAGE)
5151
.withClasspathResourceMapping(resource, "/readOnly", BindMode.READ_ONLY)
52-
.withClasspathResourceMapping(resource, "/readOnlyNoSelinux", BindMode.READ_ONLY)
5352
.withClasspathResourceMapping(resource, "/readOnlyShared", BindMode.READ_ONLY, SelinuxContext.SHARED)
5453
.withClasspathResourceMapping(resource, "/readWrite", BindMode.READ_WRITE);
5554

5655
Map<MountableFile, String> copyMap = container.getCopyToFileContainerPathMap();
5756
assertThat(copyMap).as("uses copy for read-only").containsValue("/readOnly");
58-
assertThat(copyMap).as("uses copy for read-only and no Selinux").containsValue("/readOnlyNoSelinux");
59-
60-
assertThat(copyMap).as("uses mount for read-only with Selinux").doesNotContainValue("/readOnlyShared");
57+
assertThat(copyMap).as("uses copy for read-only with Selinux").containsValue("/readOnlyShared");
6158
assertThat(copyMap).as("uses mount for read-write").doesNotContainValue("/readWrite");
6259
}
6360

0 commit comments

Comments
 (0)