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

nuget sources add should not delete credentials from NuGet.config #7200

Closed
ap0llo opened this issue Aug 14, 2018 · 2 comments
Closed

nuget sources add should not delete credentials from NuGet.config #7200

ap0llo opened this issue Aug 14, 2018 · 2 comments
Labels
Area:Settings NuGet.Config and related issues Priority:2 Issues for the current backlog. Type:Bug
Milestone

Comments

@ap0llo
Copy link

ap0llo commented Aug 14, 2018

Details about Problem

NuGet product used: NuGet.exe

NuGet version: 4.7.1.5393

Detailed repro steps so we can see the same problem

Background

We run an internal NuGet server that requires authentication.
To configure the feed to use, we place a nuget.config file in the source code repository, but configure the credentials for the feed in the user's local NuGet.Config

Repro steps

  1. Place a nuget.config in a source code repository or empty folder.

    Example:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <clear />
        <add key="Feed1" value="http://example.com/feed1" />
      </packageSources>
    </configuration>
  2. Add the credentials for "Feed1" to %APPDATA%\NuGet\NuGet.config.

    Example (I used ClearTextPassword for the example but the behavior is the same when using an encrypted password):

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
      </packageSources>
      <packageSourceCredentials>
        <Feed1>
          <add key="Username" value="USERNAME" />
          <add key="ClearTextPassword" value="PASSWORD" />
        </Feed1>
      </packageSourceCredentials>
    </configuration>
  3. Run nuget restore or nuget install in the repository. NuGet combines the feed url and credentials from the different config files and succeeds to download packages.

  4. Run nuget sources add -name Feed2 -source http://example.com/feed1 from a directory outside the repository so NuGet does not load the repository-config file.

  5. Inspect %APPDATA%\NuGet\NuGet.config. As expected, the source "Feed2" was added.
    However, the credentials for Feed1 are no longer present in the config file:

Expected:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Feed2" value="http://example.com/feed2" />
  </packageSources>
  <packageSourceCredentials>
    <Feed1>
      <add key="Username" value="USERNAME" />
      <add key="ClearTextPassword" value="PASSWORD" />
    </Feed1>
  </packageSourceCredentials>
</configuration>

Actual:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Feed2" value="http://example.com/feed2" />
  </packageSources>
</configuration>
@zhili1208
Copy link
Contributor

I can repro this, it's because we rewrite the whole nuget.config when we modify the file, in this scenario, nuget added feed2 to nuget.config, but can't find feed1, then the feed1 credential is removed. we should consider this scenario.

@zhili1208 zhili1208 added Priority:2 Issues for the current backlog. Area:Settings NuGet.Config and related issues labels Aug 14, 2018
@zhili1208 zhili1208 added this to the Backlog milestone Aug 14, 2018
@PatoBeltran PatoBeltran modified the milestones: Backlog, 15.9, 4.9 Oct 19, 2018
@PatoBeltran
Copy link

This has been solved as part of the latest rework on the nuget.configuration code paths.

@rrelyea rrelyea changed the title nuget sources add strips credentials from a user's NuGet.config nuget sources add should not delete credentials from NuGet.config Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:Settings NuGet.Config and related issues Priority:2 Issues for the current backlog. Type:Bug
Projects
None yet
Development

No branches or pull requests

3 participants