forked from dotnet/dotnet-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add non-root user support (dotnet#4397)
(cherry picked from commit 4fced56)
- Loading branch information
Showing
59 changed files
with
690 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/*}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
eng/dockerfile-templates/runtime-deps/Dockerfile.linux.non-root-user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
], " ")}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.