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

Update non-root UID to avoid warning in Debian #4715

Merged
merged 3 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/dockerfile-templates/runtime-deps/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
set rpmFilename to "dotnet-runtime-deps.rpm" ^
set utilPkgs to when(isMariner && nonRootUserSupported, ["shadow-utils"], []) ^
set username to "app" ^
set uid to 64198 ^
set uid to 1654 ^
set gid to uid ^
set nonRootUserComment to "# Create a non-root user and group"
}}FROM {{baseImageRepo}}:{{baseImageTag}}{{if isMultiStage: AS {{firstStageName}}}}{{if isRpmInstall && isInternal:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set osVersionBase to match(OS_VERSION, ".+(?=.*-)")[0] ^
set osVersionNumber to split(OS_ARCH_HYPHENATED, "-")[1] ^
set username to "app" ^
set uid to 64198 ^
set uid to 1654 ^
set gid to uid
}}FROM {{ARCH_VERSIONED}}/golang:1.20 as chisel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
when(find(OS_VERSION, "1.0") >= 0,
1000,
101),
64198) ^
1654) ^
set gid to uid ^
set createUserHome to dotnetVersion != "6.0"
}}# Installer image
Expand Down
10 changes: 5 additions & 5 deletions src/runtime-deps/6.0/jammy-chiseled/amd64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ RUN go generate internal/deb/version.go \
&& cp /opt/rocks-toolbox/chisel-wrapper /usr/bin/

RUN groupadd \
--gid=64198 \
--gid=1654 \
app \
&& useradd -l \
--uid=64198 \
--gid=64198 \
--uid=1654 \
--gid=1654 \
--shell /bin/false \
app \
&& install -d -m 0755 -o 64198 -g 64198 "/rootfs/home/app" \
&& install -d -m 0755 -o 1654 -g 1654 "/rootfs/home/app" \
&& mkdir -p "/rootfs/etc" \
&& rootOrAppRegex='^\(root\|app\):' \
&& cat /etc/passwd | grep $rootOrAppRegex > "/rootfs/etc/passwd" \
Expand All @@ -48,7 +48,7 @@ COPY --from=chisel /rootfs /

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_URLS=http://+:8080 \
# Enable detection of running in a container
Expand Down
10 changes: 5 additions & 5 deletions src/runtime-deps/6.0/jammy-chiseled/arm32v7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ RUN go generate internal/deb/version.go \
&& cp /opt/rocks-toolbox/chisel-wrapper /usr/bin/

RUN groupadd \
--gid=64198 \
--gid=1654 \
app \
&& useradd -l \
--uid=64198 \
--gid=64198 \
--uid=1654 \
--gid=1654 \
--shell /bin/false \
app \
&& install -d -m 0755 -o 64198 -g 64198 "/rootfs/home/app" \
&& install -d -m 0755 -o 1654 -g 1654 "/rootfs/home/app" \
&& mkdir -p "/rootfs/etc" \
&& rootOrAppRegex='^\(root\|app\):' \
&& cat /etc/passwd | grep $rootOrAppRegex > "/rootfs/etc/passwd" \
Expand All @@ -48,7 +48,7 @@ COPY --from=chisel /rootfs /

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_URLS=http://+:8080 \
# Enable detection of running in a container
Expand Down
10 changes: 5 additions & 5 deletions src/runtime-deps/6.0/jammy-chiseled/arm64v8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ RUN go generate internal/deb/version.go \
&& cp /opt/rocks-toolbox/chisel-wrapper /usr/bin/

RUN groupadd \
--gid=64198 \
--gid=1654 \
app \
&& useradd -l \
--uid=64198 \
--gid=64198 \
--uid=1654 \
--gid=1654 \
--shell /bin/false \
app \
&& install -d -m 0755 -o 64198 -g 64198 "/rootfs/home/app" \
&& install -d -m 0755 -o 1654 -g 1654 "/rootfs/home/app" \
&& mkdir -p "/rootfs/etc" \
&& rootOrAppRegex='^\(root\|app\):' \
&& cat /etc/passwd | grep $rootOrAppRegex > "/rootfs/etc/passwd" \
Expand All @@ -48,7 +48,7 @@ COPY --from=chisel /rootfs /

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_URLS=http://+:8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/alpine3.18/amd64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM amd64/alpine:3.18

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/alpine3.18/arm32v7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM arm32v7/alpine:3.18

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/alpine3.18/arm64v8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM arm64v8/alpine:3.18

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/bookworm-slim/amd64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM amd64/debian:bookworm-slim

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/bookworm-slim/arm32v7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM arm32v7/debian:bookworm-slim

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/bookworm-slim/arm64v8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM arm64v8/debian:bookworm-slim

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ RUN tmpManifestPath="/tmp/rpmmanifest" \

# Create a non-root user and group
RUN groupadd \
--gid=64198 \
--gid=1654 \
app \
&& useradd -l \
--uid=64198 \
--gid=64198 \
--uid=1654 \
--gid=1654 \
--shell /bin/false \
--create-home \
app \
&& install -d -m 0755 -o 64198 -g 64198 "/staging/home/app" \
&& install -d -m 0755 -o 1654 -g 1654 "/staging/home/app" \
&& rootOrAppRegex='^\(root\|app\):' \
&& cat /etc/passwd | grep $rootOrAppRegex > "/staging/etc/passwd" \
&& cat /etc/group | grep $rootOrAppRegex > "/staging/etc/group"
Expand All @@ -59,7 +59,7 @@ FROM mcr.microsoft.com/cbl-mariner/distroless/minimal:2.0

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand All @@ -70,6 +70,6 @@ ENV \
COPY --from=installer /staging/ /

# Workaround for https://github.com/moby/moby/issues/38710
COPY --from=installer --chown=64198:64198 /staging/home/app /home/app
COPY --from=installer --chown=1654:1654 /staging/home/app /home/app

USER app
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ RUN tmpManifestPath="/tmp/rpmmanifest" \

# Create a non-root user and group
RUN groupadd \
--gid=64198 \
--gid=1654 \
app \
&& useradd -l \
--uid=64198 \
--gid=64198 \
--uid=1654 \
--gid=1654 \
--shell /bin/false \
--create-home \
app \
&& install -d -m 0755 -o 64198 -g 64198 "/staging/home/app" \
&& install -d -m 0755 -o 1654 -g 1654 "/staging/home/app" \
&& rootOrAppRegex='^\(root\|app\):' \
&& cat /etc/passwd | grep $rootOrAppRegex > "/staging/etc/passwd" \
&& cat /etc/group | grep $rootOrAppRegex > "/staging/etc/group"
Expand All @@ -59,7 +59,7 @@ FROM mcr.microsoft.com/cbl-mariner/distroless/minimal:2.0

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand All @@ -70,6 +70,6 @@ ENV \
COPY --from=installer /staging/ /

# Workaround for https://github.com/moby/moby/issues/38710
COPY --from=installer --chown=64198:64198 /staging/home/app /home/app
COPY --from=installer --chown=1654:1654 /staging/home/app /home/app

USER app
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/cbl-mariner2.0/amd64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/cbl-mariner/base/core:2.0 AS base

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/cbl-mariner2.0/arm64v8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/cbl-mariner/base/core:2.0 AS base

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
10 changes: 5 additions & 5 deletions src/runtime-deps/8.0/jammy-chiseled/amd64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ RUN go generate internal/deb/version.go \
&& cp /opt/rocks-toolbox/chisel-wrapper /usr/bin/

RUN groupadd \
--gid=64198 \
--gid=1654 \
app \
&& useradd -l \
--uid=64198 \
--gid=64198 \
--uid=1654 \
--gid=1654 \
--shell /bin/false \
app \
&& install -d -m 0755 -o 64198 -g 64198 "/rootfs/home/app" \
&& install -d -m 0755 -o 1654 -g 1654 "/rootfs/home/app" \
&& mkdir -p "/rootfs/etc" \
&& rootOrAppRegex='^\(root\|app\):' \
&& cat /etc/passwd | grep $rootOrAppRegex > "/rootfs/etc/passwd" \
Expand All @@ -48,7 +48,7 @@ COPY --from=chisel /rootfs /

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
10 changes: 5 additions & 5 deletions src/runtime-deps/8.0/jammy-chiseled/arm32v7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ RUN go generate internal/deb/version.go \
&& cp /opt/rocks-toolbox/chisel-wrapper /usr/bin/

RUN groupadd \
--gid=64198 \
--gid=1654 \
app \
&& useradd -l \
--uid=64198 \
--gid=64198 \
--uid=1654 \
--gid=1654 \
--shell /bin/false \
app \
&& install -d -m 0755 -o 64198 -g 64198 "/rootfs/home/app" \
&& install -d -m 0755 -o 1654 -g 1654 "/rootfs/home/app" \
&& mkdir -p "/rootfs/etc" \
&& rootOrAppRegex='^\(root\|app\):' \
&& cat /etc/passwd | grep $rootOrAppRegex > "/rootfs/etc/passwd" \
Expand All @@ -48,7 +48,7 @@ COPY --from=chisel /rootfs /

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
10 changes: 5 additions & 5 deletions src/runtime-deps/8.0/jammy-chiseled/arm64v8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ RUN go generate internal/deb/version.go \
&& cp /opt/rocks-toolbox/chisel-wrapper /usr/bin/

RUN groupadd \
--gid=64198 \
--gid=1654 \
app \
&& useradd -l \
--uid=64198 \
--gid=64198 \
--uid=1654 \
--gid=1654 \
--shell /bin/false \
app \
&& install -d -m 0755 -o 64198 -g 64198 "/rootfs/home/app" \
&& install -d -m 0755 -o 1654 -g 1654 "/rootfs/home/app" \
&& mkdir -p "/rootfs/etc" \
&& rootOrAppRegex='^\(root\|app\):' \
&& cat /etc/passwd | grep $rootOrAppRegex > "/rootfs/etc/passwd" \
Expand All @@ -48,7 +48,7 @@ COPY --from=chisel /rootfs /

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/jammy/amd64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM ubuntu.azurecr.io/ubuntu:jammy

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/jammy/arm32v7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM ubuntu.azurecr.io/ubuntu:jammy

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion src/runtime-deps/8.0/jammy/arm64v8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM ubuntu.azurecr.io/ubuntu:jammy

ENV \
# UID of the non-root user 'app'
APP_UID=64198 \
APP_UID=1654 \
# Configure web servers to bind to port 8080 when present
ASPNETCORE_HTTP_PORTS=8080 \
# Enable detection of running in a container
Expand Down
2 changes: 1 addition & 1 deletion tests/Microsoft.DotNet.Docker.Tests/ImageData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class ImageData
public string OS { get; set; }
public bool IsDistroless => OS.Contains("distroless") || OS.Contains("chiseled");
public virtual int DefaultPort => IsDistroless ? 8080 : 80;
public virtual int? NonRootUID => IsWindows ? null : 64198;
public virtual int? NonRootUID => IsWindows ? null : 1654;

private static readonly Lazy<JObject> s_imageInfoData;

Expand Down
5 changes: 4 additions & 1 deletion tests/Microsoft.DotNet.Docker.Tests/ProductImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ protected void VerifyNonRootUID(ProductImageData imageData)

int uid = int.Parse(uidString);

Assert.True(uid > 10000);
// UIDs below 1000 are reserved for system accounts
Assert.True(uid >= 1000);
// Debian has a UID_MAX of 60000
Assert.True(uid <= 60000);
}

private IEnumerable<string> GetInstalledRpmPackages(ProductImageData imageData)
Expand Down