From 5afaf63d99184801fe5688c05c5aba6a6bb2041d Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Wed, 28 May 2025 12:01:25 +0200 Subject: [PATCH] oobe: exit early for cloud-init WSL supports `cloud-init` for provisioning. In some cases (RHEL) this is enabled. If `wsl-setup` is used on RHEL then there's a TOCTOU between the check for "no user exists" and the "create user" part as `cloud-init` creates the user during the prompt. Let's exit early and assume everything is handled by `cloud-init` *if* it is enabled. Signed-off-by: Simon de Vlieger --- wsl-oobe.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wsl-oobe.sh b/wsl-oobe.sh index ace2e51..240dde6 100644 --- a/wsl-oobe.sh +++ b/wsl-oobe.sh @@ -2,7 +2,8 @@ # The Fedora WSL out of box experience script. # -# This command runs the first time the user opens an interactive shell. +# This command runs the first time the user opens an interactive shell if +# `cloud-init` is not enabled. # # A non-zero exit code indicates to WSL that setup failed. @@ -10,6 +11,10 @@ set -ueo pipefail DEFAULT_USER_ID=1000 +if systemctl is-enabled cloud-init.service > /dev/null ; then + exit 0 +fi + echo 'Please create a default user account. The username does not need to match your Windows username.' echo 'For more information visit: https://aka.ms/wslusers'