Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SelinuxContext.SHARED by default #7187

Merged
merged 10 commits into from
Jun 20, 2023
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