-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Check for npmrc in home directory for linux root users #4047
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just one question about Linux whitelist vs. Windows blacklist
src/util/user-home-dir.js
Outdated
process.platform === 'linux' && ROOT_USER ? path.resolve('/usr/local/share') : require('os').homedir(); | ||
export const home = require('os').homedir(); | ||
|
||
const userHomeDir = process.platform === 'linux' && ROOT_USER ? path.resolve('/usr/local/share') : home; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why limit to linux
instead of blacklisting Windows only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not sure I fully understand the question. Would you mind explaining a bit? Windows is already filtered out in the ROOT_USER here
Line 4 in 7a053e2
if (process.platform !== 'win32' && process.getuid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about other operating systems like BSD? I wonder if we should use this root logic for those, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems safe to add 'freebsd'
to the list, are there any other platforms we should add from here? https://nodejs.org/api/process.html#process_process_platform
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah actually @BYK I see what you're saying. Yeah I don't think the platform check is even necessary given that line of code in root-user.js
src/registries/npm-registry.js
Outdated
@@ -14,7 +14,7 @@ import {addSuffix} from '../util/misc'; | |||
import {getPosixPath, resolveWithHome} from '../util/path'; | |||
|
|||
const normalizeUrl = require('normalize-url'); | |||
const userHome = require('../util/user-home-dir').default; | |||
const {default: userHome, home} = require('../util/user-home-dir'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're here, could you please change this to an import
statement? I've been meaning to revisit one of my old pull requests where I updated all require
statements to use import
, but just haven't had time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushing back for the test describe
comment. I'll push a fix myself and merge it for expediency.
Thanks a lot for the fix!
const ini = require('ini'); | ||
import normalizeUrl from 'normalize-url'; | ||
import {default as userHome, home} from '../util/user-home-dir'; | ||
import path from 'path'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I think the convention is to list stdlib imports at the top, right?
__tests__/registries/npm-registry.js
Outdated
const mockReporter = jest.fn(); | ||
const mockLog = []; | ||
const mockReporter = { | ||
lang: (...args) => mockLog.push(...args), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can also use the BufferReporter
for tests?
__tests__/registries/npm-registry.js
Outdated
@@ -292,3 +297,16 @@ describe('getScope functional test', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
describe('getPossibleConfigLocations', () => { | |||
describe('searches recursively to home directory', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a test
or it
call not describe
.
// When home directory for global install is different from where $HOME/npmrc is stored, | ||
// E.g. /usr/local/share vs /root on linux machines, check the additional location | ||
if (home !== userHome) { | ||
possibles.push([true, path.join(home, localfile)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should change this data structure to be a normal object instead of an array sometime in the future: {isHomeDir: true, path: path.join(home, localfile)}
@BYK thanks for being awesome and making those changes! |
Any ETA for a release containing this fix? |
@felixfbecker You can use a nightly build if you like. https://nightly.yarnpkg.com/ The Yarn team are working on 1.0 at the moment. |
Tried to, but unfortunately I need to add it to an Alpine Docker image and running the install script just results in
Really don't want to change our whole image just for a hotfix. I guess the alternative is switching to npm 5 |
@felixfbecker that's unfortunate :( I'll file an issue to see why the script is not working on Alpine. Guessing some mismatch between GNU In the meantime, you can use the single-file bundle from https://nightly.yarnpkg.com/yarn-1.0.0-20170825.2124.js (just |
https://nightly.yarnpkg.com/latest.js will also give you the latest version. You could also manually grab the tarball from https://nightly.yarnpkg.com/latest.tar.gz, check the GPG signature, and extract it. That's what the install script does :) |
Summary
Fix for #3920.
In this commit,
userHome
for linux users running as root was changed to/usr/local/share
, mainly to allow for other users to run globally added bins. However this introduced a bug where npmrc wasn't being looked in the root directory after checking/user/local/share
. So this change pushes another location to check in caseuserHome
is different from native home directory returned byos.homedir()
Test plan
I've added a test to generally test the
getPossibleConfigLocations
method, but I haven't been able to properly mock out running it as a root user on linux. Suggestions welcome!