Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ExecResult {
* @param mode the bind mode
*/
default void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode) {
addFileSystemBind(hostPath, containerPath, mode, SelinuxContext.NONE);
addFileSystemBind(hostPath, containerPath, mode, SelinuxContext.SHARED);
}

/**
Expand Down Expand Up @@ -303,7 +303,7 @@ default SELF withClasspathResourceMapping(
final String containerPath,
final BindMode mode
) {
withClasspathResourceMapping(resourcePath, containerPath, mode, SelinuxContext.NONE);
withClasspathResourceMapping(resourcePath, containerPath, mode, SelinuxContext.SHARED);
return self();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ public SELF withClasspathResourceMapping(
final String containerPath,
final BindMode mode
) {
return withClasspathResourceMapping(resourcePath, containerPath, mode, SelinuxContext.NONE);
return withClasspathResourceMapping(resourcePath, containerPath, mode, SelinuxContext.SHARED);
}

/**
Expand All @@ -1305,10 +1305,10 @@ public SELF withClasspathResourceMapping(
) {
final MountableFile mountableFile = MountableFile.forClasspathResource(resourcePath);

if (mode == BindMode.READ_ONLY && selinuxContext == SelinuxContext.NONE) {
withCopyFileToContainer(mountableFile, containerPath);
} else {
if (mode == BindMode.READ_WRITE) {
addFileSystemBind(mountableFile.getResolvedPath(), containerPath, mode, selinuxContext);
} else {
withCopyFileToContainer(mountableFile, containerPath);
}

return self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,12 @@ public void shouldUseCopyOnlyWithReadOnlyClasspathResources() {
String resource = "/test_copy_to_container.txt";
GenericContainer<?> container = new GenericContainer<>(TestImages.TINY_IMAGE)
.withClasspathResourceMapping(resource, "/readOnly", BindMode.READ_ONLY)
.withClasspathResourceMapping(resource, "/readOnlyNoSelinux", BindMode.READ_ONLY)
.withClasspathResourceMapping(resource, "/readOnlyShared", BindMode.READ_ONLY, SelinuxContext.SHARED)
.withClasspathResourceMapping(resource, "/readWrite", BindMode.READ_WRITE);

Map<MountableFile, String> copyMap = container.getCopyToFileContainerPathMap();
assertThat(copyMap).as("uses copy for read-only").containsValue("/readOnly");
assertThat(copyMap).as("uses copy for read-only and no Selinux").containsValue("/readOnlyNoSelinux");

assertThat(copyMap).as("uses mount for read-only with Selinux").doesNotContainValue("/readOnlyShared");
assertThat(copyMap).as("uses copy for read-only with Selinux").containsValue("/readOnlyShared");
assertThat(copyMap).as("uses mount for read-write").doesNotContainValue("/readWrite");
}

Expand Down