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

[24.0 backport] Fixing dockerd-rootless-setuptools.sh when user name contains a backslash #46407

Merged
merged 1 commit into from Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 14 additions & 7 deletions contrib/dockerd-rootless-setuptool.sh
Expand Up @@ -37,6 +37,8 @@ BIN=""
SYSTEMD=""
CFG_DIR=""
XDG_RUNTIME_DIR_CREATED=""
USERNAME=""
USERNAME_ESCAPED=""

# run checks and also initialize global vars
init() {
Expand Down Expand Up @@ -78,6 +80,11 @@ init() {
exit 1
fi

# Set USERNAME from `id -un` and potentially protect backslash
# for windbind/samba domain users
USERNAME=$(id -un)
USERNAME_ESCAPED=$(echo $USERNAME | sed 's/\\/\\\\/g')

# set CFG_DIR
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"

Expand Down Expand Up @@ -222,21 +229,21 @@ init() {
fi

# instructions: validate subuid/subgid files for current user
if ! grep -q "^$(id -un):\|^$(id -u):" /etc/subuid 2> /dev/null; then
if ! grep -q "^$USERNAME_ESCAPED:\|^$(id -u):" /etc/subuid 2> /dev/null; then
instructions=$(
cat <<- EOI
${instructions}
# Add subuid entry for $(id -un)
echo "$(id -un):100000:65536" >> /etc/subuid
# Add subuid entry for ${USERNAME}
echo "${USERNAME}:100000:65536" >> /etc/subuid
EOI
)
fi
if ! grep -q "^$(id -un):\|^$(id -u):" /etc/subgid 2> /dev/null; then
if ! grep -q "^$USERNAME_ESCAPED:\|^$(id -u):" /etc/subgid 2> /dev/null; then
instructions=$(
cat <<- EOI
${instructions}
# Add subgid entry for $(id -un)
echo "$(id -un):100000:65536" >> /etc/subgid
# Add subgid entry for ${USERNAME}
echo "${USERNAME}:100000:65536" >> /etc/subgid
EOI
)
fi
Expand Down Expand Up @@ -340,7 +347,7 @@ install_systemd() {
)
INFO "Installed ${SYSTEMD_UNIT} successfully."
INFO "To control ${SYSTEMD_UNIT}, run: \`systemctl --user (start|stop|restart) ${SYSTEMD_UNIT}\`"
INFO "To run ${SYSTEMD_UNIT} on system startup, run: \`sudo loginctl enable-linger $(id -un)\`"
INFO "To run ${SYSTEMD_UNIT} on system startup, run: \`sudo loginctl enable-linger ${USERNAME}\`"
echo
}

Expand Down