Skip to content

Commit 02e4905

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 6048ba6 commit 02e4905

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `oxsecurity/megalinter:beta` docker image
1010

11+
- Run Docker container as current user rather than root ([#1975](https://github.com/oxsecurity/megalinter/issues/1975))
1112
- Remove default npm-groovy-lint extra arguments ([#1872](https://github.com/oxsecurity/megalinter/issues/1872))
1213

1314
- Linter versions upgrades

mega-linter-runner/lib/runner.js

+6
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 process = require("process");
78
const which = require("which");
89
const fs = require("fs-extra");
910
const { MegaLinterUpgrader } = require("./upgrade");
@@ -127,6 +128,11 @@ ERROR: Docker engine has not been found on your system.
127128
if (options["containerName"]) {
128129
commandArgs.push(...["--name", options["containerName"]]);
129130
}
131+
if (process.getuid && process.getgid) {
132+
commandArgs.push(
133+
...["--user", `${process.getuid()}:${process.getgid()}`]
134+
);
135+
}
130136
commandArgs.push(...["-v", "/var/run/docker.sock:/var/run/docker.sock:rw"]);
131137
commandArgs.push(...["-v", `${lintPath}:/tmp/lint:rw`]);
132138
if (options.fix === true) {

0 commit comments

Comments
 (0)