Skip to content

fix: NuGet auth config layering to fix 401 on private feed in Docker#1062

Merged
BenjaminMichaelis merged 3 commits intomainfrom
fix/docker-nuget-auth-hotfix
May 6, 2026
Merged

fix: NuGet auth config layering to fix 401 on private feed in Docker#1062
BenjaminMichaelis merged 3 commits intomainfrom
fix/docker-nuget-auth-hotfix

Conversation

@BenjaminMichaelis
Copy link
Copy Markdown
Member

Problem

PR #1060 merged with the --configfile approach for Docker NuGet auth. This approach:

  • Discards the repo's nuget.config entirely (including packageSourceMapping)
  • Caused 401 Unauthorized on the Azure DevOps private feed

The fixup commit from the original PR branch was never applied to main.

Fix

Switch to NuGet config layering (NuGet 5.7+):

  • CI generates a credentials-only config (no <packageSources>)
  • Dockerfile copies it to ~/.nuget/config/credentials.config
  • NuGet merges it with the repo's nuget.config automatically
  • nuget.config remains the single source of truth for feeds + packageSourceMapping

Changes

  • Dockerfile: cp /run/secrets/nugetconfig ~/.nuget/config/credentials.config instead of --configfile; add required=false on secret mount
  • Build-Test-And-Deploy.yml: credentials-only generated config (no <packageSources> section)

Testing

  • PR build: uses ACCESS_TO_NUGET_FEED=false (no auth needed, verifies image builds)
  • Main build: full auth path with layered config

BenjaminMichaelis and others added 2 commits May 6, 2026 16:30
…pping

Replace --configfile (which drops all other NuGet config) with copying a
credentials-only file to ~/.nuget/config/credentials.config so NuGet
merges it with the repo's nuget.config (including packageSourceMapping).

- Add required=false to secret mount (explicit optional behavior)
- Generate credentials-only config in CI (nuget.config remains single
  source of truth for feeds and packageSourceMapping)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Omit packageSources from the generated config so NuGet's config layering
keeps nuget.config as the single source of truth for feed URLs and
packageSourceMapping rules.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 6, 2026 23:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Docker private-feed restore failures by switching from dotnet restore --configfile ... (which overrides the repo nuget.config, breaking packageSourceMapping) to NuGet config layering: a credentials-only config is injected during Docker builds so the repo nuget.config remains authoritative for feeds and source mapping.

Changes:

  • Update Dockerfile to mount a NuGet auth secret (optional) and rely on NuGet’s config merge behavior instead of --configfile.
  • Update the deployment workflow to generate a credentials-only NuGet config (no <packageSources> section), preventing it from clobbering repo feed configuration.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
EssentialCSharp.Web/Dockerfile Switches restore to layered NuGet auth config instead of --configfile; makes secret mount optional.
.github/workflows/Build-Test-And-Deploy.yml Generates a credentials-only NuGet config for Docker secret injection (no package sources).

Comment on lines +21 to +26
RUN --mount=type=secret,id=nugetconfig,required=false \
if [ "$ACCESS_TO_NUGET_FEED" = "true" ] && [ -f /run/secrets/nugetconfig ]; then \
dotnet restore "EssentialCSharp.Web.slnx" --configfile /run/secrets/nugetconfig -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED; \
else \
dotnet restore "EssentialCSharp.Web.slnx" -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED; \
mkdir -p ~/.nuget/config && \
cp /run/secrets/nugetconfig ~/.nuget/config/credentials.config; \
fi && \
dotnet restore "EssentialCSharp.Web.slnx" -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED && \
Deleting ~/.nuget/config/credentials.config in the same RUN instruction
ensures the PAT never appears in the final layer snapshot (create + delete
in one RUN = net zero diff). Prevents credential leakage into BuildKit
layer cache.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@BenjaminMichaelis BenjaminMichaelis merged commit 621e630 into main May 6, 2026
7 checks passed
@BenjaminMichaelis BenjaminMichaelis deleted the fix/docker-nuget-auth-hotfix branch May 6, 2026 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants