Skip to content

Commit

Permalink
Run Docker container as current user (#1975)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kurt-von-Laven committed Jan 10, 2023
1 parent c5561aa commit 6f0f21d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l

- Fixes
- Change name of config file for powershell formatter to avoid collision with powershell linter config
- Run Docker container as current user rather than root ([#1975](https://github.com/oxsecurity/megalinter/issues/1975))

- Linter versions upgrades
- [prettier](https://prettier.io/) from 2.8.1 to **2.8.2** on 2023-01-07
Expand Down
4 changes: 4 additions & 0 deletions mega-linter-runner/lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const optionsDefinition = require("./options");
const { spawnSync } = require("child_process");
const c = require("chalk");
const path = require("path");
const { getgid, getuid } = require("process");
const which = require("which");
const fs = require("fs-extra");
const { MegaLinterUpgrader } = require("./upgrade");
Expand Down Expand Up @@ -127,6 +128,9 @@ ERROR: Docker engine has not been found on your system.
if (options["containerName"]) {
commandArgs.push(...["--name", options["containerName"]]);
}
if (getuid && getgid) {
commandArgs.push(...["--user", `${getuid()}:${getgid()}`]);
}
commandArgs.push(...["-v", "/var/run/docker.sock:/var/run/docker.sock:rw"]);
commandArgs.push(...["-v", `${lintPath}:/tmp/lint:rw`]);
if (options.fix === true) {
Expand Down

0 comments on commit 6f0f21d

Please sign in to comment.