-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Support npmrc for private registries and auth #839
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
Conversation
I haven't had the chance to check this thoroughly but as one of the people who spotted the bearer token leak in npm I thought I'd chime in early to make sure something similar doesn't creep in here. From my super-quick testing on this PR it looks like if For example, if my
... and I install an arbitrary tarball from somewhere other than This is just based on my quick 2 mins of testing so feel free to tell me I'm talking rubbish if I've missed something. |
Wow this is awesome. Nice work @devongovett and good to see you again. I haven't heard from you since the old MooTools/jQuery days! |
|
||
return this.config.requestManager.request({ | ||
url: ref, | ||
return registry.request(ref, { |
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.
Possible NPE?
On reflection, I've just realised this may actually be the intended behaviour of |
this fixes #521 when you set awesome! |
Great work! However, still having some issues with this, where the Also, one major problem I still see is that the saved e.g:
|
Awesome PR. Does this pick up |
@jbt yes, that is the desired behavior of @zetoke yes, looks like it should fix #521. @mrtnbroder does it work if you add a trailing slash to the registry url in your config? If so, I guess we could add the slash if it's not there... @donaldpipowitch no. |
Fixed an issue caused by a later PR #712, which changed from @zetoke Also added a check to ensure that we only add authorization if the request is going to the registry (not random tarballs). |
This finally works with my
🎉 |
In our case this allows yarn to resolve the packages in our private registry but when it actually goes to fetch them we get errors like: |
@sohara can you provide your |
Sure
|
I'm getting the same error with our
|
I did some debugging and I think I know how to fix it on my end, but there may be an issue when reading The issue is that I have
So the final value for |
@devongovett As a follow-up, I think the issue I'm seeing (can't speak for @sohara) is not related to this PR and should be fixed separately. I'll log an issue. Edit: #949 |
@jgoz yes, that sounds like a separate issue. |
@devongovett I've added some debug logging as you've suggest and and I'm getting the following on stdout (logging first the header followed by the request url):
I'm not sure where tarballs would be stored on the system in order to verify they are ok? I did not find any in |
|
||
const headers = {}; | ||
if (this.token) { | ||
headers.authorization = `Bearer ${this.token}`; | ||
if (this.token || (this.getOption('always-auth') && requestUrl.startsWith(registry))) { |
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.
Looks like there should also be a call to this.getScopedOption(registry.replace(/^https?:/, ''), 'always-auth')
here.
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.
You're right. Added in 35d617e.
@cpojer What is blocking thing for merge this PR to upstream? |
@zetoke @kittens and I are currently catching up on the repo (while also holding the fort internally at FB :D ). The post launch craziness made everything a bit unstable. Please give us some time until everything is settled down – if you'd like to help get the tests in a good state again, please send us a PR. |
@cpojer of course! Thanks a lot for your work! |
@devongovett love this approach! @kittens, @bestander what would we need to do to move this forward? Perhaps we can come to a consensus around this RFC? and get this out the door 💯 |
Can you please rebase this against |
Any chance this is getting published to NPM registry soonish? |
we'll cut the branch Monday-Tuesday On 16 October 2016 at 23:18, Kristoffer Lundén [email protected]
|
I installed yarn from the master branch just now, but it doesn't seem to be working for me. It seems to fetch the metadata correctly, but I get the
My .npmrc looks like this:
|
@SEAPUNK Is |
@SEAPUNK remove the first line from your npmrc and it should work. Currently it replaces the https://registry.npmjs.com/ with https://registry.yarnpkg.com/ here, which confuses the check here. |
@motss That just throws an early error:
|
@devongovett Wait, now it's giving me that error with the original npmrc. One sec, let me test a few things... |
@SEAPUNK I had the same trouble. But with fix from @devongovett it's working! |
Yeah, that fix didn't work for me. |
I installed yarn 0.16.0 just now, same problems. |
Not to mention that removing that first line from my npmrc breaks npm's install process. |
@SEAPUNK it's a bug. I will look at it when I have a chance. |
Alright, thanks. |
Also getting the The
And the private registry replies with "an invalid tar file" in the form of a JSON response: {
"error": "unregistered users are not allowed to access package @mycompany/company-package"
} This pull request was supposed to add support for scoped registrys (which we use heavily), so is it the |
I'm having the same issue as @kribblo. When doing a tcpdump on the sinopia box I see that it sends the authorization token with the GET call to the package metadata (
But then when it fetches the tar it doesn't:
|
Experiencing some weird issues. My npmrc looks something like this:
I went into
|
It seems to indeed be related to a "missing" trailing slash, here. If I add a trailing slash to the first entry in the array above, the resolving succeeds, though the tarball download fails (no token is sent). It's a bit worrying that it seems to fall back to sending a private registry token to the public registry, however. |
Hi! How do you get to install version 0.16.0? |
@vinngn1 |
Able to install private package out of the box after the upgrade. Thank @Gpx for the upgrade instruction and @devongovett and others for the fix. |
I didn't read all of this thread, but I was wondering - howcome nobody ran into the issue where auth header is not getting sent when downloading tarballs: #1687. |
@KidkArolis #839 (comment) just a few comments above yours |
@kribblo yeah, thanks :) I take it the issue hasn't been resolved yet. I have a way to reproduce it: https://github.com/KidkArolis/yarn-scopes-issue. And a potential fix: #1666. |
Summary
This implements support for private registries configured in
.npmrc
files. It extracts the registry to use and the auth token info. Supports bearer tokens and basic auth, scoped registries, and thealways-auth
option. Should fix #606.My flow experience is minimal, so if I messed something up or did something silly please let me know. 😀
Test plan
I tested with several npm configs against real live Sonatype Nexus, and Artifactory instances. Here are some cases: