Commit 4ad9a87
committed
fix: enforce packageSourceMapping and prevent credentials in build cache
Root causes of the 401 failures:
- Approach 1 (--configfile): the CI script wrote the literal string
\ into the XML file instead of the actual PAT
value (shell variable not expanded), so NuGet forwarded that literal
string to Azure DevOps 401. Also --configfile replaces all
config-file lookup, silently dropping packageSourceMapping.
- Approach 2 (config layering): credentials were copied to
~/.nuget/config/credentials.config, a path the .NET NuGet client
never scans. On Linux the user-level config is
~/.nuget/NuGet/NuGet.Config (single file). The credentials file was
ignored entirely 401.
Current approach (dotnet nuget update source) is correct; two fixes:
1. Prevent credentials from leaking into the Docker build-layer cache.
dotnet nuget update source writes the PAT into /src/nuget.config.
With cache-to: type=gha,mode=max that modified file is cached.
Fix: back up nuget.config before injection and restore it at the end
of the same RUN command so the committed layer contains only the
original credential-free file. The PAT itself never leaves the
BuildKit secret mount.
2. Enforce packageSourceMapping. Per NuGet docs, packageSourceMapping
is bypassed when the MSBuild RestoreSources property is set.
Removing RestoreSources from Directory.Packages.props lets
nuget.config (with its packageSourceMapping) be the single source of
truth:
- ContentFeedNuget private Azure DevOps feed only (no nuget.org
package with that name can be injected via dependency confusion)
- * nuget.org (including EssentialCSharp.Shared.Models, which is
a public package; confirmed by PR builds succeeding without private
feed credentials)
The AccessToNugetFeed condition on the ContentFeedNuget PackageVersion
and PackageReference ItemGroups continues to control whether the
private-feed package is part of the build.1 parent f598d60 commit 4ad9a87
2 files changed
Lines changed: 4 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | 7 | | |
15 | 8 | | |
16 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
0 commit comments