Skip to content

Commit 080d06b

Browse files
Run Docker container as user 1000 (#1975)
Previously, mega-linter-runner ran the MegaLinter Docker image as root. In the Docker image, chown the /megalinter, /megalinter-descriptors, and /action/lib/.automation directories to be owned by user and group 1000. Users whose files became owned by root as a consequence of having run a previous version of MegaLinter will need to chown them to be owned by user 1000 when upgrading MegaLinter.
1 parent b6bee18 commit 080d06b

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
1515
- Linter enhancements & fixes
1616

1717
- Core
18+
- Make Docker image rootless, and run it as user 1000 rather than root by
19+
@Kurt-von-Laven in [#1975](https://github.com/oxsecurity/megalinter/issues/1975).
1820

1921
- Documentation
2022

Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ ENV KICS_QUERIES_PATH=/opt/kics/assets/queries KICS_LIBRARIES_PATH=/opt/kics/ass
666666
################################
667667
# Installs python dependencies #
668668
################################
669-
COPY megalinter /megalinter
669+
COPY --chown=1000:1000 megalinter /megalinter
670670
RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
671671
&& PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py clean --all \
672672
&& rm -rf /var/cache/apk/* \
@@ -675,8 +675,8 @@ RUN PYTHONDONTWRITEBYTECODE=1 python /megalinter/setup.py install \
675675
#######################################
676676
# Copy scripts and rules to container #
677677
#######################################
678-
COPY megalinter/descriptors /megalinter-descriptors
679-
COPY TEMPLATES /action/lib/.automation
678+
COPY --chown=1000:1000 megalinter/descriptors /megalinter-descriptors
679+
COPY --chown=1000:1000 TEMPLATES /action/lib/.automation
680680

681681
###########################
682682
# Get the build arguments #

mega-linter-runner/lib/runner.js

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ ERROR: Docker engine has not been found on your system.
132132
if (options["containerName"]) {
133133
commandArgs.push(...["--name", options["containerName"]]);
134134
}
135+
commandArgs.push(...["--user", `1000:1000`]);
135136
commandArgs.push(...["-v", "/var/run/docker.sock:/var/run/docker.sock:rw"]);
136137
commandArgs.push(...["-v", `${lintPath}:/tmp/lint:rw`]);
137138
if (options.fix === true) {

0 commit comments

Comments
 (0)