From 9dc9a07a5109de7810fa5e622b005ed4d2e60a5a Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Fri, 30 Aug 2024 07:59:57 +0000 Subject: [PATCH 1/4] [dotnet] - remove ubuntu:noble's ubuntu user capturing 1000 uid & gid --- src/dotnet/.devcontainer/Dockerfile | 19 +++++++++++++++++++ src/dotnet/.devcontainer/devcontainer.json | 2 ++ src/dotnet/test-project/test.sh | 13 +++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/dotnet/.devcontainer/Dockerfile b/src/dotnet/.devcontainer/Dockerfile index 1f8a6f182..00bafa555 100644 --- a/src/dotnet/.devcontainer/Dockerfile +++ b/src/dotnet/.devcontainer/Dockerfile @@ -2,6 +2,25 @@ ARG VARIANT=8.0-bookworm-slim FROM mcr.microsoft.com/dotnet/sdk:${VARIANT} ENV PATH $PATH:/home/vscode/.dotnet:/home/vscode/.dotnet/tools +ARG VARIANT +ENV VARIANT=${VARIANT} + +RUN if [ "${VARIANT#*noble}" != "$VARIANT" ]; then \ + echo "Variant contains noble"; \ + # Check if ubuntu user exists and delete it if it does + if id "ubuntu" &>/dev/null; then \ + echo "Deleting user ubuntu" && userdel -f -r ubuntu || echo "Failed to delete ubuntu user"; \ + echo "Deleting group associated with ubuntu" && groupdel ubuntu || echo "Failed to delete group associated with ubuntu user"; \ + #check if group 1000 and user 1000 is deleted + echo "Checking user at 1000 uid" && getent passwd 1000 || echo "Failed to find user at uid 1000;" \ + echo "Checking group at 1000 gid" && getent group 1000 || echo "Failed to find group at gid 1000"; \ + else \ + echo "User ubuntu does not exist"; \ + fi; \ + else \ + echo "Variant does not contain noble"; \ + fi + # clear this environment variable so xml docs from NuGet packages are unpackaged. The default dotnet/sdk image sets it to 'skip'. # see https://github.com/dotnet/dotnet-docker/issues/2790 ENV NUGET_XMLDOC_MODE= \ No newline at end of file diff --git a/src/dotnet/.devcontainer/devcontainer.json b/src/dotnet/.devcontainer/devcontainer.json index 141b6263e..4653ec348 100644 --- a/src/dotnet/.devcontainer/devcontainer.json +++ b/src/dotnet/.devcontainer/devcontainer.json @@ -7,6 +7,8 @@ "ghcr.io/devcontainers/features/common-utils:2": { "installZsh": "true", "username": "vscode", + "userUid": "1000", + "userGid": "1000", "upgradePackages": "true" }, "ghcr.io/devcontainers/features/node:1": { diff --git a/src/dotnet/test-project/test.sh b/src/dotnet/test-project/test.sh index d1d9b89da..e577eb748 100755 --- a/src/dotnet/test-project/test.sh +++ b/src/dotnet/test-project/test.sh @@ -29,5 +29,18 @@ check "usr-local-etc-config-does-not-exist" test ! -f "/usr/local/etc/gitconfig" checkPackageVersion "pwsh" "7.4.4" "PowerShell" +os_release=$(cat /etc/os-release) +# Check if the output contains "NAME=Ubuntu" and "VERSION=24.04" +if echo "$os_release" | grep -q "NAME=\"Ubuntu\"" && echo "$os_release" | grep -q "VERSION=\"24.04"; then + check "Find ubuntu User" bash -c "grep 'ubuntu' /etc/passwd || echo 'ubuntu user not found.'" + check "Find ubuntu Group" bash -c "grep 'ubuntu' /etc/group || echo 'ubuntu group not found.'" + check "Find vscode User" bash -c "grep 'vscode' /etc/passwd || echo 'vscode user not found.'" + check "Find vscode Group" bash -c "grep 'vscode' /etc/group || echo 'vscode group not found.'" + + check "log file contents" bash -c "cat /tmp/logfile.txt" + check "all users" bash -c "cat /etc/passwd" + check "uid" bash -c "id -u vscode | grep 1000" +fi + # Report result reportResults From 958ec3d1dc9ac2f7d0c643942884ea5e2ecc013b Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Tue, 24 Sep 2024 01:40:02 +0000 Subject: [PATCH 2/4] changes as required --- src/dotnet/.devcontainer/Dockerfile | 16 +++------------- src/dotnet/test-project/test.sh | 27 ++++++++++++++++----------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/dotnet/.devcontainer/Dockerfile b/src/dotnet/.devcontainer/Dockerfile index 4d6284584..acd613d4c 100644 --- a/src/dotnet/.devcontainer/Dockerfile +++ b/src/dotnet/.devcontainer/Dockerfile @@ -3,22 +3,12 @@ FROM mcr.microsoft.com/dotnet/sdk:${VARIANT} ENV PATH $PATH:/home/vscode/.dotnet:/home/vscode/.dotnet/tools ARG VARIANT -ENV VARIANT=${VARIANT} - -RUN if [ "${VARIANT#*noble}" != "$VARIANT" ]; then \ - echo "Variant contains noble"; \ - # Check if ubuntu user exists and delete it if it does +RUN if [ "${VARIANT#*noble}" != "$VARIANT" ]; then \ if id "ubuntu" &>/dev/null; then \ - echo "Deleting user ubuntu" && userdel -f -r ubuntu || echo "Failed to delete ubuntu user"; \ - echo "Deleting group associated with ubuntu" && groupdel ubuntu || echo "Failed to delete group associated with ubuntu user"; \ - #check if group 1000 and user 1000 is deleted - echo "Checking user at 1000 uid" && getent passwd 1000 || echo "Failed to find user at uid 1000;" \ - echo "Checking group at 1000 gid" && getent group 1000 || echo "Failed to find group at gid 1000"; \ + echo "Deleting user 'ubuntu' for $VARIANT" && userdel -f -r ubuntu || echo "Failed to delete ubuntu user for $VARIANT"; \ else \ - echo "User ubuntu does not exist"; \ + echo "User 'ubuntu' does not exist for $VARIANT"; \ fi; \ - else \ - echo "Variant does not contain noble"; \ fi # clear this environment variable so xml docs from NuGet packages are unpackaged. The default dotnet/sdk image sets it to 'skip'. diff --git a/src/dotnet/test-project/test.sh b/src/dotnet/test-project/test.sh index e577eb748..6d0072ed4 100755 --- a/src/dotnet/test-project/test.sh +++ b/src/dotnet/test-project/test.sh @@ -29,17 +29,22 @@ check "usr-local-etc-config-does-not-exist" test ! -f "/usr/local/etc/gitconfig" checkPackageVersion "pwsh" "7.4.4" "PowerShell" -os_release=$(cat /etc/os-release) -# Check if the output contains "NAME=Ubuntu" and "VERSION=24.04" -if echo "$os_release" | grep -q "NAME=\"Ubuntu\"" && echo "$os_release" | grep -q "VERSION=\"24.04"; then - check "Find ubuntu User" bash -c "grep 'ubuntu' /etc/passwd || echo 'ubuntu user not found.'" - check "Find ubuntu Group" bash -c "grep 'ubuntu' /etc/group || echo 'ubuntu group not found.'" - check "Find vscode User" bash -c "grep 'vscode' /etc/passwd || echo 'vscode user not found.'" - check "Find vscode Group" bash -c "grep 'vscode' /etc/group || echo 'vscode group not found.'" - - check "log file contents" bash -c "cat /tmp/logfile.txt" - check "all users" bash -c "cat /etc/passwd" - check "uid" bash -c "id -u vscode | grep 1000" +check_ubuntu_user() { + if ! id -u ubuntu > /dev/null 2>&1; then + echo -e "✔️ User ubuntu does not exist." + else + echo -e "❌ User ubuntu exists." + exit 1; + fi + echo -e "\n\nList of all users:"; + cat /etc/passwd; +} + +if grep -q 'VERSION_CODENAME=noble' /etc/os-release; then + echo -e "\nThe base image is ubuntu:noble. Checking user Ubuntu.." + check "uid" "check_ubuntu_user" +else + echo -e "\nCannot check user Ubuntu. The base image is not ubuntu:noble." fi # Report result From 59afb973f6ad3855eb959208deefc63885a5369d Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Thu, 26 Sep 2024 07:16:11 +0000 Subject: [PATCH 3/4] pinning to 1000 for vscode user --- src/dotnet/.devcontainer/devcontainer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dotnet/.devcontainer/devcontainer.json b/src/dotnet/.devcontainer/devcontainer.json index 141b6263e..e6e6a919b 100644 --- a/src/dotnet/.devcontainer/devcontainer.json +++ b/src/dotnet/.devcontainer/devcontainer.json @@ -7,7 +7,9 @@ "ghcr.io/devcontainers/features/common-utils:2": { "installZsh": "true", "username": "vscode", - "upgradePackages": "true" + "upgradePackages": "true", + "userUid": "1000", + "userGid": "1000" }, "ghcr.io/devcontainers/features/node:1": { "version": "none" From 8f1a66e71f09d0f44962b4ff95adf65968ff1ce9 Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Thu, 26 Sep 2024 07:18:11 +0000 Subject: [PATCH 4/4] as required --- src/dotnet/test-project/test.sh | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/dotnet/test-project/test.sh b/src/dotnet/test-project/test.sh index 6d0072ed4..d1d9b89da 100755 --- a/src/dotnet/test-project/test.sh +++ b/src/dotnet/test-project/test.sh @@ -29,23 +29,5 @@ check "usr-local-etc-config-does-not-exist" test ! -f "/usr/local/etc/gitconfig" checkPackageVersion "pwsh" "7.4.4" "PowerShell" -check_ubuntu_user() { - if ! id -u ubuntu > /dev/null 2>&1; then - echo -e "✔️ User ubuntu does not exist." - else - echo -e "❌ User ubuntu exists." - exit 1; - fi - echo -e "\n\nList of all users:"; - cat /etc/passwd; -} - -if grep -q 'VERSION_CODENAME=noble' /etc/os-release; then - echo -e "\nThe base image is ubuntu:noble. Checking user Ubuntu.." - check "uid" "check_ubuntu_user" -else - echo -e "\nCannot check user Ubuntu. The base image is not ubuntu:noble." -fi - # Report result reportResults