-
Notifications
You must be signed in to change notification settings - Fork 255
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
NuGet.exe restore does not use basic auth credentials from config #456
Comments
@roryprimrose, do you have the credentials set in %AppData%NuGet config file ? Looks like that's the one being picked up while restoring during build |
No, I point nuget.exe to a config in the same folder. It is here that the credentials get picked up as seen in the log line "Using credentials from config. UserName: [Username]". I also tried ditching my config file and using powershell to add the credential via the command line before executing the restore. Exactly the same thing happened though. |
@roryprimrose are you able to use the credentials from |
See previous two comments. This question has already been addressed. |
Not really. The question was around if you can use the above suggestion as a workaround? If not we can look for another workaround until this gets fixed and a nuget.exe released |
I think I have already covered that and found the same result. I tried using the command line to add the credentials as part of the build. This would put the credentials into %appdata% nuget.config. The creds were used to query the packages but not used to download them. |
Can you verify the content of your global nuget.config. This is rather odd since this is a mainline scenario and I'm very surprised by it. We can obviously take a look first thing in the morning. |
Not really. This is running in a VSO build so it would depend on that config. As you can see in the powershell though, I am getting nuget.exe to point to my specific config. If it is any help in proving this yourself. I have a web project that has the nuget server package installed and then the following module (supports basic auth with a single config user):
|
Thanks, I was missing the part where you run in vso. That makes sense now. |
@roryprimrose , I did a setup locally with a nuget.server which has the basic auth module that you have shared and the issue doesn't repro with nuget.exe 2.8.6. However, when proper permissions are not set on the "packages" folder ( for the nuget.server website user account), I hit this issue. In your case does trying to download the package via browser [https://nuget.myserver.com/api/v2/package/mysystem.core/1.0.1] work ? |
Ah, interesting. I have pointed the packagesPath config to ~/App_Data/Packages to ensure that the packages are not publicly exposed. I am surprised that this is a security issue because I expected that the server code would have read access to the packages folder on behalf of the user. What permissions are required outside of any IIS/ASP.Net defaults? I'll so some more testing around this when I get a little more time. |
Just tested this locally using IISExpress. I authenticated via the browser and the auth cookie was set (configured to use ~/App_Data/Packages as well). I then listed packages and directly downloaded one of the packages using the browser. I got the package and my trace logs also indicated what happened.
I then created a restore scenario that used the same setup in my build process against the same IISExpress instance. This worked sucessfully.
Why am I not seeing the same behavior when VSO build hits my custom NuGet server? |
How did you get nugetm.exe to vso? Is it exactly the same binary? |
I got it from the CommandLine NuGet package and put it in my repo. It is version 2.8.60318.667 |
I also tested with nuget 2.8.50926.602 and found the same. With both these versions, I consistently get the problem locally. I don't know what I missed when I tested this locally the other day. |
If you try downloading a package from your custom nuget server ( not locally hosted in IISExpress) via browser ( using /api/v2// ) does it work ? If there is a permissions related issue, it should fail. |
@roryprimrose, I am closing the issue as we couldn't repro it and it seems like a permission issue. |
Sorry, I missed your last comment. I'll try to get a fiddler trace today. I don't think it is a permissions issue. I have a workaround where I cache the IP address of a previously successful authentication attempt. I then allow that IP to make any call within a few minutes. This workaround (bad as it is for security) works fine both locally and hosted in Azure. Without the IP cache I get the same lack of authentication provision as described above. |
@roryprimrose I checked our code and didn't find anything wrong. It does send out basic authentication headers. Please use fiddler to capture all requests and responses. Then search for requests of "GET https://nuget.myserver.com/api/v2/package/othersystem.client/2.0.2". There should be at least two requests. The response of the first request should look like this:
Note the line
where xxxx is the password. Could you verify that the right response and request headers are there? If no, then it's a bug in NuGet and we'll fix this bug. If yes, then it's a setup issue with the server (most likely the username specified in your nuget.config does not have the permission to access the packages folder on the server). |
I spent a couple of hours working on this yesterday. I can't reliably reproduce this now. I looked at a restore scenario that uses both local and Azure based NuGet server. Looks like it is working on the command line ATM. Interestingly, a restore via the VS IDE fails though. I still don't think it is a permissions issue because it works sometimes in some circumstances and works reliably with the IP cache. I just can't narrow down where this is going wrong. I'll close this for now unless I can reliably reproduce the issue. |
@nicholi One more question. Are you restoring/installing into a project with packages.config or project.json? @martinsuchan 's follow up bug - #1158 |
Still using packages.config. I haven't migrated to all the new nuget3/vs2k15 features just yet, but slowly moving towards them. I have migrated to the new automatic package restore method. I have a feeling also just removing the sources and re-adding them with credentials again may have fixed more things then anything else. As I'm now ok even without @stevewilliamsuk's fix. |
@yishaigalatzer I'm not sure if that was an intended scenario for it or not, going to find out. I've even created simple tutorial how to deploy your NuGet Server on Azure and secure it with Basic Authentication. The repro for my bug mentioned earlier is based on this guide. |
@nicholi if you lucky enough that re-adding it fixes it for you that's great. However, it definitely has not fixed the issue for our setup (can't tell you the number of times I tried removing and re-adding config). I have a very similar setup, Nuget.Server package and Basic Auth. @yishaigalatzer do you have enough information based on all the examples and comments to reproduce the problem and look into it? If not what more do we need to provide? It seems likely that bug is related to the difference between having https://somehost.com/nuget/ in the configuration and which isn't being picked up for requests going to https://somehost.com/api/v2/. Either it's a client issue, i.e. it should get the username / password per host or Nuget.Server should be using /api/v2/ instead of /nuget/. Are you able to outline some kind of plan to resolve this issue? It's obviously a very frustrating problem for those people experiencing it. As a follow up to the Nuget Gallery comment, if that's what we are supposed to be using, why is there no mention of it in the nuget documentation http://docs.nuget.org/create/hosting-your-own-nuget-feeds. I assume that many many people wanting to host their own feeds are following that guide and using the Nuget.Server package. I would be happy to use the Gallery project instead if it supports an Authentication system that I can hook into my LDAP server, but there's no mention of it in the docs as an option at all. |
@johncmckim I'm missing one bit of feedback. The report from @martinsuchan talks about I manage to connect to the feed and download the packages through VS2015 UI (though they are not applicable to NET452 projects they download fine). So I still don't know if there is any other scenario broken here other than the one tracked at - #1158 @martinsuchan - Yes I wasn't aware it was (sorry relatively new to the team, I checked last night and yet it is supposed to work). @johncmckim - Here is the difference between NuGet Gallery and nuget.server. Both support authentication, the former is more complicated to install, but provides a lot more features. NuGet.Server Intended for small projects with a few packages. Mostly allows decoupling from using a fileshare, locking files and access over Http where fileshare access is not available. NuGet Gallery More of a mirror of the nuget.org V2 site, with a database behind the scenes and a lot more available features. Here is one of the blogs I found on how to set it up with authentication. This might not be the most up to date one. You are right that the docs do not point to the nuget gallery solution, or go into the details above. I'll make sure that happens. |
No I was wrong, I started randomly getting prompted for passwords when manually installing/upgrading packages through the UI interface from the private repo. From what I've found you need to have multiple credentials entered for different paths, otherwise the client doesn't know what to do. One for plain /nuget/ (I'm assuming this is for using the repo through the UI), one for /api/v2/ (for package restore to actually work), and I also have one for /api/v2/package/ (used when I push packages with api key). I have the last one disabled. @johncmckim I'd make sure you have the latest nuget.exe and Nuget.Server package. Also try and assure the nuget.org repos are first in your list, and the protocolVersion=3 one is present. Otherwise yeah...fun and frustrating. Ultra P.S. Also transition to the new automatic package restore method. |
We're seeing some strange auth issues here too. Using nuget.exe 3.1.0-beta downloaded from the link in the blog post, with an authenticated v3 source with credentials stored in nuget.config, running
gives the following behavior:
index.json and the SearchQueryService are on the same host, if that's interesting |
How did you get an authenticated v3 feed? |
We believe this is fixed in the latest version of nuget.exe. We have verified the following scenarios for basic auth:
I'm going to close this bug for now, use the link below to verify that this fixes your scenarios: If you are still seeing issues with the above nuget.exe please open an issue with exact repro steps and a server that we can hit to test nuget.exe similar to how @martinsuchan set up the repro. |
This just happened on my machine - Windows 10, Visual Studio 2015 Pro with UWP Tools v1.1, NuGet 3.2.60914. When rebuilding UWP app sample -> about 100 Basic Authentication dialogs popped up even though I got our custom feed with saved basic authentication credentials properly added in feed sources. Note this sample used only default UWP NuGet package Microsoft.NETCore.UniversalWindowsPlatform, no package from our custom feed. |
Do you get a consistent repro? As in does this happen every time or just once? We just did an overhaul for auth in 3.3 so it would be interesting to test it. Last it doesn't matter if packages are in the authenticated source or not because the code cannot know that until they get queried |
It looks like I got consistent repro (Windows 10, Visual Studio 2015 Pro with UWP Tools v1.1, NuGet 3.2.60914):
|
I can confirm this is no longer happening with NuGet 3.3.0. |
@martinsuchan thanks for getting back to us! Much appreciated |
@stevewilliamsuk thank you for the insight and the suggestion. Works like a charm! |
I'm trying to set up a private NuGet feed that uses an API key for pushing packages and a simple basic auth IHttpModule to protect reads. The system fails on the build server when the build attempts to do a NuGet restore from the private feed.
The nuget.exe is invoked with the following powershell:
The referenced config file contains the following (with sensitive info removed):
The powershell script logs the following for the restore:
I put some rudimentary logging into the HttpModule and it definitely gets the credentials from config to correctly read the package feed and identify the packages. However it looks like it doesn't use these credentials for actually downloading the package.
I even added in cookie support for caching the basic auth credential in the hope that nuget.exe would use the same CookieContainer but it doesn't.
This is the log from the module:
You can see here that for each set of requests, auth fails and then the auth credentials are read from config and provided, the cookie is set and the repeated requests is successful. This continues all the way until nuget.exe attempts to download the packages. At this point the auth credentials from config are not provided which results in a hard fail with no repeat with credentials.
The text was updated successfully, but these errors were encountered: