diff --git a/CHANGELOG.md b/CHANGELOG.md index 17fc7353176..dffd62acdfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l by @Kurt-von-Laven in [#2275](https://github.com/oxsecurity/megalinter/pull/2275). - Only run npm-package-json-lint when package.json is present by @Kurt-von-Laven in [#2280](https://github.com/oxsecurity/megalinter/pull/2280). + - Run Docker container as current user rather than root by @Kurt-von-Laven in + [#1975](https://github.com/oxsecurity/megalinter/issues/1975). - Documentation - Configure jsonschema documentation formatting (see [Descriptor schema](https://megalinter.io/latest/json-schemas/descriptor.html), [Configuration schema](https://megalinter.io/latest/json-schemas/configuration.html)), by @echoix in [#2270](https://github.com/oxsecurity/megalinter/pull/2270) diff --git a/mega-linter-runner/lib/runner.js b/mega-linter-runner/lib/runner.js index 79a8da5c369..b24baeda03f 100644 --- a/mega-linter-runner/lib/runner.js +++ b/mega-linter-runner/lib/runner.js @@ -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"); @@ -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) {