Disable SELinux label security policy when building images

When using the Gradle `bootBuildImage` task or Maven
`spring-boot:build-image` goal on a Linux distribution with SELinux
enabled, binding the Docker socket in the builder container might
fail. This commit disables the `label` security policy in the builder
container to prevent this type of failure.

Fixes gh-32000
This commit is contained in:
Scott Frederick
2022-08-18 15:41:58 -05:00
parent 238493a7d4
commit c16094e04b
14 changed files with 78 additions and 5 deletions

View File

@@ -143,4 +143,18 @@ class PhaseTests {
then(update).shouldHaveNoMoreInteractions();
}
@Test
void applyWhenWithSecurityOptionsUpdatesConfigurationWithSecurityOptions() {
Phase phase = new Phase("test", true);
phase.withSecurityOption("option1=value1");
phase.withSecurityOption("option2=value2");
Update update = mock(Update.class);
phase.apply(update);
then(update).should().withCommand("/cnb/lifecycle/test");
then(update).should().withLabel("author", "spring-boot");
then(update).should().withSecurityOption("option1=value1");
then(update).should().withSecurityOption("option2=value2");
then(update).shouldHaveNoMoreInteractions();
}
}

View File

@@ -61,12 +61,13 @@ class ContainerConfigTests extends AbstractJsonTests {
update.withEnv("name1", "value1");
update.withEnv("name2", "value2");
update.withNetworkMode("test");
update.withSecurityOption("option=value");
});
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
containerConfig.writeTo(outputStream);
String actualJson = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
String expectedJson = StreamUtils.copyToString(getContent("container-config.json"), StandardCharsets.UTF_8);
JSONAssert.assertEquals(expectedJson, actualJson, false);
JSONAssert.assertEquals(expectedJson, actualJson, true);
}
}

View File

@@ -33,6 +33,9 @@
"pack-cache-b35197ac41ea.launch:/launch-cache",
"/host/src/path:/container/dest/path:ro",
"volume-name:/container/volume/path:rw"
],
"SecurityOpt" : [
"label=disable"
]
}
}

View File

@@ -31,6 +31,9 @@
"pack-app-aaaaaaaaaa:/workspace",
"build-volume:/cache",
"launch-volume:/launch-cache"
],
"SecurityOpt" : [
"label=disable"
]
}
}

View File

@@ -32,6 +32,9 @@
"pack-app-aaaaaaaaaa:/workspace",
"pack-cache-b35197ac41ea.build:/cache",
"pack-cache-b35197ac41ea.launch:/launch-cache"
],
"SecurityOpt" : [
"label=disable"
]
}
}

View File

@@ -31,6 +31,9 @@
"pack-app-aaaaaaaaaa:/workspace",
"pack-cache-b35197ac41ea.build:/cache",
"pack-cache-b35197ac41ea.launch:/launch-cache"
],
"SecurityOpt" : [
"label=disable"
]
}
}

View File

@@ -31,6 +31,9 @@
"pack-app-aaaaaaaaaa:/workspace",
"pack-cache-b35197ac41ea.build:/cache",
"pack-cache-b35197ac41ea.launch:/launch-cache"
],
"SecurityOpt" : [
"label=disable"
]
}
}

View File

@@ -32,6 +32,9 @@
"pack-app-aaaaaaaaaa:/workspace",
"pack-cache-b35197ac41ea.build:/cache",
"pack-cache-b35197ac41ea.launch:/launch-cache"
],
"SecurityOpt" : [
"label=disable"
]
}
}

View File

@@ -7,6 +7,9 @@
"author" : "spring-boot"
},
"HostConfig" : {
"Binds" : [ "/var/run/docker.sock:/var/run/docker.sock", "pack-layers-aaaaaaaaaa:/layers", "pack-app-aaaaaaaaaa:/workspace", "pack-cache-b35197ac41ea.build:/cache", "pack-cache-b35197ac41ea.launch:/launch-cache" ]
"Binds" : [ "/var/run/docker.sock:/var/run/docker.sock", "pack-layers-aaaaaaaaaa:/layers", "pack-app-aaaaaaaaaa:/workspace", "pack-cache-b35197ac41ea.build:/cache", "pack-cache-b35197ac41ea.launch:/launch-cache" ],
"SecurityOpt" : [
"label=disable"
]
}
}

View File

@@ -31,6 +31,9 @@
"pack-app-aaaaaaaaaa:/workspace",
"pack-cache-b35197ac41ea.build:/cache",
"pack-cache-b35197ac41ea.launch:/launch-cache"
],
"SecurityOpt" : [
"label=disable"
]
}
}

View File

@@ -17,6 +17,9 @@
"Binds": [
"bind-source:bind-dest"
],
"NetworkMode": "test"
"NetworkMode": "test",
"SecurityOpt": [
"option=value"
]
}
}