Skip to content

Commit 344f323

Browse files
Run Docker container as current user (#1975)
Previously, mega-linter-runner ran the MegaLinter Docker image as root. Users whose files became owned by root as a consequence of this behavior will need to chown them to be owned by the appropriate user. This change only affects POSIX platforms, because process.getuid and process.getgid are only available there.
1 parent 0bc37a1 commit 344f323

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
2727
- Added **cli_lint_fix_arg_name** parameter to **powershell formatter** descriptor as without it, autofix does not work, by @bdovaz in [#2294](https://github.com/oxsecurity/megalinter/pull/2294)
2828
- Created **ProtolintLinter** class to fix the problem that returns exit code 1 when it encounters a problem to correct even though it corrects it correctly, by @bdovaz in [#2294](https://github.com/oxsecurity/megalinter/pull/2294)
2929
- Concatenate **--output** parameter correctly to **xmllint** linter, by @bdovaz in [#2294](https://github.com/oxsecurity/megalinter/pull/2294)
30+
- Run Docker container as current user rather than root by @Kurt-von-Laven in
31+
[#1975](https://github.com/oxsecurity/megalinter/issues/1975).
3032

3133
- Documentation
3234
- Change **swiftlint** example that did not correctly reflect the **--fix** parameter, by @bdovaz in [#2294](https://github.com/oxsecurity/megalinter/pull/2294)

mega-linter-runner/lib/runner.js

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const optionsDefinition = require("./options");
44
const { spawnSync } = require("child_process");
55
const c = require("chalk");
66
const path = require("path");
7+
const { getgid, getuid } = require("process");
78
const which = require("which");
89
const fs = require("fs-extra");
910
const { MegaLinterUpgrader } = require("./upgrade");
@@ -127,6 +128,9 @@ ERROR: Docker engine has not been found on your system.
127128
if (options["containerName"]) {
128129
commandArgs.push(...["--name", options["containerName"]]);
129130
}
131+
if (getuid && getgid) {
132+
commandArgs.push(...["--user", `${getuid()}:${getgid()}`]);
133+
}
130134
commandArgs.push(...["-v", "/var/run/docker.sock:/var/run/docker.sock:rw"]);
131135
commandArgs.push(...["-v", `${lintPath}:/tmp/lint:rw`]);
132136
if (options.fix === true) {

0 commit comments

Comments
 (0)