Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not drop perms in git when not root #23

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,17 @@ function spawnGit (gitArgs, gitOpts, opts) {
})
}

module.exports._mkOpts = mkOpts
function mkOpts (_gitOpts, opts) {
const gitOpts = {
env: gitEnv()
}
if (+opts.uid && !isNaN(opts.uid)) {
const isRoot = process.getuid && process.getuid() === 0
// don't change child process uid/gid if not root
if (+opts.uid && !isNaN(opts.uid) && isRoot) {
gitOpts.uid = +opts.uid
}
if (+opts.gid && !isNaN(opts.gid)) {
if (+opts.gid && !isNaN(opts.gid) && isRoot) {
gitOpts.gid = +opts.gid
}
Object.assign(gitOpts, _gitOpts)
Expand Down
22 changes: 22 additions & 0 deletions test/git.mkopts.uid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'
const t = require('tap')
const { _mkOpts: mkOpts } = require('../lib/util/git.js')
const getuid = process.getuid

t.test('mkOpts sets perms when root', t => {
t.teardown(() => {
process.getuid = getuid
})
process.getuid = () => 0
t.match(mkOpts({}, { uid: 1234, gid: 1234 }), { uid: 1234, gid: 1234 })
t.end()
})

t.test('mkOpts does not set perms when not root', t => {
t.teardown(() => {
process.getuid = getuid
})
process.getuid = () => 4321
t.match(mkOpts({}, { uid: 1234, gid: 1234 }), { uid: undefined, gid: undefined })
t.end()
})