Skip to content

Commit

Permalink
Use SelinuxContext.SHARED by default for mounting (#7187)
Browse files Browse the repository at this point in the history
Co-authored-by: monosoul <Kloz.Klaud@gmail.com>
Co-authored-by: Eddú Meléndez <eddu.melendez@gmail.com>
  • Loading branch information
3 people committed Jun 20, 2023
1 parent c82049b commit 9220816
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
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

0 comments on commit 9220816

Please sign in to comment.