-
Notifications
You must be signed in to change notification settings - Fork 2k
Add non-root user support #4397
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
Changes from 37 commits
737fd53
e71bc0b
02e6241
26c26ca
fc176d8
aee134e
7773de5
670ec48
74311e6
452945b
a60cc4f
dc8141a
3fced5d
9130588
0d68933
cfff6d4
0ae0262
991f949
c0b37b0
ebb8aed
b2e63de
bc2dcd8
31aea92
8984b4f
afe6f03
20ea44f
98b3ba7
26cad58
6d493d9
1a0fa36
8d775f5
c5aae01
40d8c42
a880a6a
cc858da
452e753
c0442d4
daaa7e3
724e253
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{{ | ||
_ ARGS: | ||
pkgs: list of packages to remove | ||
pkg-mgr (optional): package manager to use | ||
pkg-mgr-opts (optional): additional options to pass to the package manager | ||
noninteractive (optional): whether to use noninteractive mode | ||
no-clean (optional): skip package manager cleanup after install ^ | ||
|
||
set isAlpine to find(OS_VERSION, "alpine") >= 0 ^ | ||
set isMariner to find(OS_VERSION, "cbl-mariner") >= 0 ^ | ||
set isDnf to ARGS["pkg-mgr"] = "dnf" ^ | ||
set isTdnf to ARGS["pkg-mgr"] = "tdnf" || (!isDnf && isMariner) ^ | ||
set isApk to ARGS["pkg-mgr"] = "apk" || isAlpine | ||
}}{{ | ||
if isDnf:dnf remove -y{{ARGS["pkg-mgr-opts"]}} \^ | ||
elif isApk:apk del{{ARGS["pkg-mgr-opts"]}} \^ | ||
elif isTdnf:tdnf remove -y{{ARGS["pkg-mgr-opts"]}} \^ | ||
else:apt-get remove \ | ||
&&{{if ARGS["noninteractive"]: DEBIAN_FRONTEND=noninteractive}} apt-get remove -y {{ARGS["pkg-mgr-opts"]}} \}}{{ | ||
for index, pkg in ARGS["pkgs"]: | ||
{{pkg}} \}}{{if !no-clean:{{ | ||
if isTdnf: | ||
&& tdnf clean all{{ARGS["pkg-mgr-opts"]}}^ | ||
elif isDnf: | ||
&& dnf autoremove{{ARGS["pkg-mgr-opts"]}} \ | ||
&& dnf clean all{{ARGS["pkg-mgr-opts"]}}^ | ||
elif !isApk: | ||
&& apt-get autoremove \ | ||
&& rm -rf /var/lib/apt/lists/*}}}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,9 @@ | |
_ .NET major version matches the major version of dotnet-monitor ^ | ||
set dotnetMajor to split(PRODUCT_VERSION, ".")[0] | ||
}}ENV \ | ||
# Unset ASPNETCORE_URLS from aspnet base image | ||
ASPNETCORE_URLS= \ | ||
{{if dotnetMajor != "6" && dotnetMajor != "7":# Unset ASPNETCORE_HTTP_PORTS from aspnet base image | ||
ASPNETCORE_HTTP_PORTS= \^else:# Unset ASPNETCORE_URLS from aspnet base image | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jander-msft - I know you requested this. Can you explain the need for this? Also, should the monitor Dockerfile be configured to run as non-root by default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
.NET Monitor already runs its HTTP server at ports 52323 and 52325 by default. Either setting ASPNETCORE_HTTP_PORTS would override that behavior (which we don't want by default) or it is not observed (which would be bad to insinuate that it has some effect when it does not); I think the former would be the case if the environment variable is specified. I will very later today that this is the case.
That would be great if that could be added too. Although, if this change is only scoped to .NET 8+, then this work shouldn't be necessary because .NET Monitor is only offering distroless and chiseled images for .NET 8+, which should already be using the non-root user. |
||
ASPNETCORE_URLS= \}} | ||
# Disable debugger and profiler diagnostics to avoid diagnosing self. | ||
COMPlus_EnableDiagnostics=0 \ | ||
# Default Filter | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{ | ||
_ Configures a non-root user | ||
_ ARGS: | ||
name: Name of the user/group to create | ||
uid: ID of the user to be created | ||
gid: ID of the group to be created | ||
no-create-home (optional): Indicates whether a home directory should be created for the user ^ | ||
set dotnetVersion to join(slice(split(PRODUCT_VERSION, "."), 0, 2), ".") ^ | ||
set isAlpine to find(OS_VERSION, "alpine") >= 0 ^ | ||
set isDebian to find(OS_ARCH_HYPHENATED, "Debian") >= 0 ^ | ||
set isMariner to find(OS_VERSION, "cbl-mariner") >= 0 ^ | ||
set isDistrolessMariner to defined(match(OS_VERSION, "^cbl-mariner\d+\.\d+-distroless$")) ^ | ||
set utilPkgs to when(isMariner && !isDistrolessMariner && dotnetVersion != "6.0" && dotnetVersion != "7.0", ["shadow-utils"], []) | ||
}}{{if len(utilPkgs) > 0:{{InsertTemplate("../Dockerfile.linux.install-pkgs", [ | ||
"pkgs": utilPkgs, | ||
"no-clean": "true" | ||
])}} | ||
&& }}{{if isAlpine:addgroup^else:groupadd}} \ | ||
--system \ | ||
--gid={{ARGS["gid"]}} \ | ||
{{ARGS["name"]}} \ | ||
&& {{if isDebian:useradd^else:adduser}} \ | ||
--uid {{ARGS["uid"]}} \ | ||
{{if isAlpine:--ingroup={{ARGS["name"]}}^else:--gid {{ARGS["gid"]}}}} \ | ||
--shell /bin/false \{{if ARGS["no-create-home"]: | ||
--no-create-home \^elif dotnetVersion != "6.0" && dotnetVersion != "7.0" && (isMariner || isDebian): | ||
--create-home \}} | ||
--system \ | ||
{{ARGS["name"]}}{{if len(utilPkgs) > 0: \ | ||
&& {{InsertTemplate("../Dockerfile.linux.remove-pkgs", [ | ||
"pkgs": utilPkgs | ||
], " ")}}}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
{{ | ||
_ ARGS | ||
append-cmd: Indicates whether to append the command to an existing command | ||
|
||
}}# Trigger first run experience by running arbitrary cmd | ||
{{if ARGS["append-cmd"]:&&^else:RUN}} dotnet help |
Uh oh!
There was an error while loading. Please reload this page.