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

Unable to use Authenticated sources with Central Package Management #13235

Closed
thompson-tomo opened this issue Feb 10, 2024 · 4 comments
Closed

Comments

@thompson-tomo
Copy link

thompson-tomo commented Feb 10, 2024

NuGet Product Used

MSBuild.exe

Product Version

17.8.3+195e7f5a3 for .NET

Worked before?

No response

Impact

I'm unable to use this version

Repro Steps & Context

Reproduction

Option 1

  1. Add a GlobalPackageReference to Directory.Packages.props for a package which requires Authentication
  2. In nuget.config ensure that package mapping points it to authenticated source
  3. Run dotnet build --configfile nuget.Config --configuration release /nodereuse:false on machine which doesn't have package in cache
  4. Observe error

Option 2:

  1. Add a PackageVersion to Directory.Packages.props for a package which requires Authentication
  2. Add a package reference to a project in the solution for the new package version added
  3. In nuget.config ensure that package mapping points it to authenticated source
  4. Run dotnet build --configfile nuget.Config --configuration release /nodereuse:false on machine which doesn't have package in cache
  5. Observe error

Config file

<packageSources>
	<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
	<add key="InternalNexus" value="https://url/nexus/repository/nuget-releases" />
</packageSources>

<packageSourceCredentials>
	<SKIDATANuget>
		<add key="Username" value="%NEXUS_USERNAME%" />
		<add key="ClearTextPassword" value="%NEXUS_PASSWORD%" />
	</SKIDATANuget>
</packageSourceCredentials>

<!-- Used to disable package sources  -->
<disabledPackageSources />
<!-- Define mappings by adding package ID patterns beneath the target source. -->
<packageSourceMapping>
	<packageSource key="NuGet.org">
		<package pattern="*" />
	</packageSource>
	<packageSource key="InternalNexus">
		<package pattern="SkiData.*" />
		<package pattern="JSNLOG.*" />
		<package pattern="Steeltoe.*" />
	</packageSource>
</packageSourceMapping>

%NEXUS_USERNAME% and %NEXUS_PASSWOR% are both CI/CD variables and even tested with explicitly setting the password in the nuget.config but same result. I am able to login to the nuget from my pc using the credientials and everything works fine when not using central package management.

Verbose Logs

Package source mapping matches found for package ID 'Microsoft.Extensions.Hosting.WindowsServices' are: 'NuGet.org'. (TaskId:46)
Unauthorized https://url/nexus/repository/nuget-releases/FindPackagesById()?id='Skidata.CNP.Build.Properties'&semVerLevel=2.0.0 144ms (TaskId:46)
Retrying 'FindPackagesByIdAsyncCore' for source 'https://url/nexus/repository/nuget-releases/FindPackagesById()?id='Skidata.CNP.Build.Properties'&semVerLevel=2.0.0'.
Response status code does not indicate success: 401 (Unauthorized). (TaskId:46)
@nkolev92
Copy link
Member

@thompson-tomo
CPM and authentication are unrelated concepts, so they're not blocking each other in any way.

However, looking at your config, your configs are not configured correctly.

See: https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#packagesourcecredentials

NuGet doesn't know that SKIDATANuget has credentials for InternalNexus.

@nkolev92 nkolev92 added Functionality:Restore Area:Authentication Triage:NeedsRepro WaitingForCustomer Applied when a NuGet triage person needs more info from the OP and removed Triage:Untriaged labels Feb 12, 2024
@thompson-tomo
Copy link
Author

Thanks @nkolev92 that was my mistake as when I was attempting to obfuscate my employer name/details etc i missed the credentials part.

My config is valid as it works prior to enabling central packagement.

@ghost ghost added WaitingForClientTeam Customer replied, needs attention from client team. Do not apply this label manually. and removed WaitingForCustomer Applied when a NuGet triage person needs more info from the OP labels Feb 12, 2024
@nkolev92
Copy link
Member

@thompson-tomo

CPM without transitive pinning is largely syntactic that doesn't really affect the core of restore.

I took your option #1 as an attempt at a repro, but I'm not really seeing a problem there.

@dotnet-policy-service dotnet-policy-service bot added WaitingForCustomer Applied when a NuGet triage person needs more info from the OP and removed WaitingForClientTeam Customer replied, needs attention from client team. Do not apply this label manually. labels Feb 13, 2024
@thompson-tomo
Copy link
Author

Apologies @nkolev92 I did manage to pinpoint the issue with it being connected to my nuget.config. Will close issue.

@dotnet-policy-service dotnet-policy-service bot removed the WaitingForCustomer Applied when a NuGet triage person needs more info from the OP label Feb 13, 2024
@thompson-tomo thompson-tomo closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2024
@dotnet-policy-service dotnet-policy-service bot added WaitingForClientTeam Customer replied, needs attention from client team. Do not apply this label manually. and removed WaitingForClientTeam Customer replied, needs attention from client team. Do not apply this label manually. labels Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants