From 7c16668bf31a5d7fccfa111a3c4b942007a54638 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 12 Jan 2022 10:43:06 -0800 Subject: [PATCH 1/2] Log Docker output to aid debugging Add an SLF4J logger so that we can see real time output of the Docker container. See gh-29370 --- .../launchscript/AbstractLaunchScriptIntegrationTests.java | 3 +++ src/checkstyle/checkstyle-suppressions.xml | 1 + 2 files changed, 4 insertions(+) diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/AbstractLaunchScriptIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/AbstractLaunchScriptIntegrationTests.java index 64fce246ad4..cb0e83dcf00 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/AbstractLaunchScriptIntegrationTests.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/AbstractLaunchScriptIntegrationTests.java @@ -23,7 +23,9 @@ import java.util.List; import java.util.function.Predicate; import org.assertj.core.api.Condition; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.output.ToStringConsumer; import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy; import org.testcontainers.images.builder.ImageFromDockerfile; @@ -85,6 +87,7 @@ abstract class AbstractLaunchScriptIntegrationTests { try (LaunchScriptTestContainer container = new LaunchScriptTestContainer(os, version, this.scriptsDir, script)) { container.withLogConsumer(consumer); + container.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("docker"))); container.start(); while (container.isRunning()) { Thread.sleep(100); diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index ca24ebe3e59..59071e2cb40 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -52,4 +52,5 @@ + From 9cf55808fb17daa9277424ecb5305c2b1516c07e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 12 Jan 2022 10:42:45 -0800 Subject: [PATCH 2/2] Ensure run user actually exists Update `launch.script` so that the `run_user` variable is only set when the user actually exists. Prior to this commit, if the jar file was owned by a non-existing user the startup script could fail. Fixes gh-29370 --- .../org/springframework/boot/loader/tools/launch.script | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script index c409a4fd889..ce3115c4371 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script @@ -128,6 +128,9 @@ log_file="$LOG_FOLDER/$LOG_FILENAME" # shellcheck disable=SC2012 [[ $(id -u) == "0" ]] && run_user=$(ls -ld "$jarfile" | awk '{print $3}') +# Ensure the user actually exists +id -u "$run_user" &> /dev/null || unset run_user + # Run as user specified in RUN_AS_USER if [[ -n "$RUN_AS_USER" ]]; then if ! [[ "$action" =~ ^(status|run)$ ]]; then