-
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
RestoreSources set via MSBuild properties cannot use credentials #6045
Comments
WorkaroundIt appears you can workaround this by also adding the feed to a NuGet.config file in the project. But this seems to defeat the purpose of using MSBuild properties. We were trying to get away from manipulating our NuGet.config file through automation, as discussed in #3972 |
@natemcmaster where have you added your secret feed in user-profile nuger config file? in your example, I can only see credentials being added there but not the feed itself. And then you specify this feed via RestoreSources as MSBuild property but how would NuGet relate this feed with credentials provided in NuGet.config file without the feed name? |
I didn't add the feed to the user-profile nuget config file because I don't want the feed to apply to all projects on the machine. In this example, I want the feed scoped to a specific project. I understand why the problem is happening - NuGet doesn't have a way to figure out which credentials belong with the feed. In MSBuild, the RestoreSources property is effectively Would it be possible to support setting RestoreSources an itemgroup in addition to the RestoreSources property? We could then set the source name as metadata so NuGet can use this to find credentials. Example: <Project>
<ItemGroup>
<RestoreSources Include="https://mysecretfeed/v3/index.json" Condition="'$(CI)' == 'true'">
<Name>mysecretfeed</Name>
</RestoreSources>
<RestoreSources Include="https://api.nuget.org/v3/index.json" />
</ItemGroup>
</Project> You could even support setting the username/password explicitly, or by using other MSBuild properties and MSBuild variables. <RestoreSources Include="https://mysecretfeed/v3/index.json">
<Username>commonusername</Username>
<Password>$(MyPasswordFromEnvVar)</Password>
</RestoreSources> Just an idea. I'm sure there are other ways to solve this. |
I thought there was another issue where this was discussed, but a big thing to consider here is the fact that we don't support any of these properties in the UI yet. I'd like us to figure out that out before we continue adding new features. |
I think that UI thread was #5321 |
@rrelyea Any progress on this? I don't think this work should be blocked on figuring out UI. Not being able to use authenticated feeds via |
VS 15.8 and .NET SDK 2.1.400 plan to have support for authentication plugins. VSTS team is also on track for having their plugin available at the same time. @nkolev92 is driving this from the NuGet side. |
With these new auth plugins in 2.1.400, how do we configure a credential for one or many of the feeds listed in the |
Providing the credentials will be an interactive experience, which should negate the need for plain text configuration of credentials. You'd need to do dotnet restore --interactive and auth using device flow. |
If the build is on VSTS/TFS, the plugin will automatically provide credentials for feeds hosted in the same collection the build is running on. For external feeds, you would need to provide them as service endpoints. |
What about non interactive environments? Is there an xplat equivalent to |
I face the same issue and would like to see a pure MSBuild non interactive solution for that, too. The build shouldn't depend on a specific build environment. The proposed solution with username and password and getting the password from an environment variable is the way to go from my point of view, because that is supported by all CI/CD tools. |
I managed to get this working using a variation of this fix, except using MSBuild properties.
For some reason, the magic path See Nuget restore fails on Azure Devops with message “unable to load the service index for source” for more details. |
Unfortunately, that seems to only work because of a caching issue. I ran the restore using nuget restore, rather than dotnet restore to try it out. After that, dotnet restore worked. But on a new pipeline, it didn't work by itself because I didn't run nuget restore first. Fortunately, this solution will work for me because I can just pass in the feed ID that I am using and get , but it doesn't help with running the restore using MSBuild properties at all. |
Workaround:Using at least NuGet 4.8, run However, if you are multi-targeting using This works whether you use |
nuget.exe can restore multi targeting projects just fine. dotnet.exe vs nuget.exe is more about whether you only have SDK based projects, vs a mix of packages.config, PackageReference common csproj and/or SDK style. nuget.exe can do everything restore wise that dotnet.exe can. |
Thanks. The reason I stated that is because when I tried it with
I do not have packages.config, and all of the projects use the new .csproj format with But, without running Of course, |
I might have an easier answer for that.
They are evaluated in that order. |
To all who don't want to modify their nuget.config. Here's my current approach, until we have full support in MSBuild for that. The feed address and the credentials come from environment variables. I wrote a little tool that allows me to toggle the environment variables if i want to change the current private feed. Works fine in development and unattended environments. <?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value=".nuget/packages" />
<add key="repositoryPath" value=".nuget/installed" />
</config>
<packageSources>
<clear />
<add key="local" value=".nuget/repository" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="myget" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json"></add>
<add key="PrivateFeed" value="%Nuget_PrivateFeedAddress%" />
</packageSources>
<disabledPackageSources>
<add key="local" value="true" />
<add key="myget" value="true" />
<!--<add key="nuget.org" value="true" />-->
</disabledPackageSources>
<packageSourceCredentials>
<PrivateFeed>
<add key="Username" value="%Nuget_PrivateFeedUserName%" />
<add key="ClearTextPassword" value="%Nuget_PrivateFeedApiKey%" />
</PrivateFeed>
</packageSourceCredentials>
<apikeys>
<add key="PrivateFeed" value="%Nuget_PrivateFeedEncryptedApiKey%" />
</apikeys>
</configuration>
|
Is this issue taking into account the requirements of #6243? That issue was closed as dupe in favor of this one so I want to make sure this "uber" issue is accounting for it in the design. There needs to be a solution that can:
|
@mthalman -- with your requirements, is it OK if your nuget.config with your password is part of the build context and becomes part of an intermediate layer? |
@richlander - For the context of others, when you say "build context" you're referring to a Docker build. I would prefer that credentials not be required to be within the nuget.config at all whether it be inside of a Docker build or outside of it. Suggestions like those given in #6243 are appealing because the creds do not need to be stored on disk and can be passed as arguments. In some respects there isn't a perfect solution when it comes to Docker. Your options are the following:
|
I like the first option the best because it is the simplest and has a close analogue with a related docker run use case (build source by volume mounting in an SDK container). I also think this model is harder to do the wrong thing. Anything that uses files as the currency is more subject to accidents (like commiting secrets to git). |
This is an option I am interested as well. Currently, the restore process breaks our build process (Run in Docker). I don't really want to add a NuGet.config file or something inside the docker container... The preferred way would be something like this: dotnet restore --source https://mycustomsource.com/nuget --username JohnDoe --password YouDontKnowIt |
@nkolev92 since you closed #10178, I'd like to bring the following requests from it here, as the discussion so far in this thread has been focused mainly on MSBuild: Support should be added to the upstream tooling to pass the credentials into MSBuild something like:
|
Thanks for pasting that @ericsampson All feedback from the linked issues will be considered when looking into this issue! :) A quick clarification: |
@nkolev92 right, but that's talking about requested future functionality. |
Hey @ericsampson, I just wanted to clarify that api keys is not something we want to support with restore at all at this point. Restore works well with basic, negotiate, ntlm etc. Given that any potential changes like that required both client + server changes, preserving the status quo as far as auth mechanisms go is the approach I'd recommend at this point. |
@nkolev92 ok I understand, I think I misunderstood what was going on behind the scenes. So then it would look potentially like this? And so there'd need to be two new MSBuild properties as well, correspondingly |
I found this old issue while googling around and it seems there still isn't a solution implemented yet. As an alternative to providing all nuget.config settings in MSBuild (though I would actually prefer using MSBuild Items, mentioned above), is it/would it be possible to have <RestoreSources Condition=" '$(ContinuousIntegrationBuild)' == 'true' AND '$(Configuration)' == 'Debug' ">nuget.org;Private Debug Feed</RestoreSources> We're hoping to differentiate internal feeds by both debug/release configuration as well as by environment for CI/local dev. Previously we used RestoreConfigFile and had 2 separate CI-specific configs (Debug/Release) and just require developers to manually change the disabled feeds in the xml to switch between debug/release (because setting RestoreConfigFile from MSBuild properties in a project file/Directory.Build.props is not supported in Visual Studio; this feature is really only intended for command-line MSBuild use), but with the addition of Package Source Mapping this has increased multiple maintenance/duplication overhead and it would be nice to automatically switch feeds for dev environments as well. I think I like the long-term idea of some sort of ItemDefinition for sources so that metadata like name, credentials, etc. can be grouped/conditioned together. Any suggestions in the meantime? |
…restore (#622) ## Description Pull Request #601 implementation fails to restore. I believe I narrowed the problem down to the added `disabledPackageSources` property in nuget.config, though my access to the Nuget feed isn't currently working. This solution takes the disabling effect out of nuget.config and puts it in the Directory.Packages.props. In the .props file it conditionally restores the private Nuget feed based on the single bool prop, `AccessToNugetFeed`, defined in Directory.Build.props. Credit: [GitHub issue 1](NuGet/Home#6045), [GitHub issue 2](NuGet/Home#3972) --------- Co-authored-by: Benjamin Michaelis <[email protected]>
…restore (IntelliTect#622) ## Description Pull Request IntelliTect#601 implementation fails to restore. I believe I narrowed the problem down to the added `disabledPackageSources` property in nuget.config, though my access to the Nuget feed isn't currently working. This solution takes the disabling effect out of nuget.config and puts it in the Directory.Packages.props. In the .props file it conditionally restores the private Nuget feed based on the single bool prop, `AccessToNugetFeed`, defined in Directory.Build.props. Credit: [GitHub issue 1](NuGet/Home#6045), [GitHub issue 2](NuGet/Home#3972) --------- Co-authored-by: Benjamin Michaelis <[email protected]>
I'm attempting to use MSBuild properties to define the feeds a project can use to restore. This does not work if feeds require credentials. The credentials are not loaded from the global config file in $env:AppData\NuGet.
Details
NuGet: NuGet Command Line 4.5.0.2
dotnet.exe --version: 15.5.0-preview-007044
OS version: Win 10
Repro
$env:APPDATA\NuGet\NuGet.config
dotnet restore
Result
Restore fails with HTTP 401 Unauthorized.
The text was updated successfully, but these errors were encountered: