Repository navigation
Closed
Description
Using an Azure DevOps build results in:
1 warning found (use docker --debug to expand):
- SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "FEED_ACCESS_TOKEN") (line 39)
I realize that this is the recommended way to use the ACP in a dockerfile. I just thought you might like to be aware that this warning now shows up when running a build.
Part of my build.yml
- task: NuGetAuthenticate@1
displayName: 'Authenticate to Azure Artifacts'
- task: Docker@2
displayName: 'Build Docker image'
inputs:
command: 'build'
dockerfile: '$(setVars.dockerfile)'
buildContext: '$(dockerBuildContext)'
repository: '$(setVars.imageName)'
tags: |
dev-latest
$(Build.SourceVersion)
arguments: '--build-arg FEED_ACCESS_TOKEN=$(VSS_NUGET_ACCESSTOKEN)'Relevant bits of my dockerfile
# Debug base: Debian for fast vsdbg performance (VS Fast Mode uses this)
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
RUN apt-get update && apt-get install -y --no-install-recommends wget \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
EXPOSE 8080
# Runtime base: Alpine for dev/prod (small image size)
FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS base-alpine
RUN apk add --no-cache icu-libs tzdata ca-certificates
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
WORKDIR /app
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
# Install Azure Artifacts Credential Provider
RUN dotnet tool install --global Microsoft.Artifacts.CredentialProvider.NuGet.Tool --verbosity quiet
ENV PATH="${PATH}:/root/.dotnet/tools"
COPY --link ["Directory.Build.props", "."]
COPY --link ["nuget.config", "."]
COPY --link ["MyApp.csproj", "."]
# Set Azure Artifacts credentials as ARG (passed via --build-arg, safe in multi-stage build)
ARG FEED_ACCESS_TOKEN
ENV ARTIFACTS_CREDENTIALPROVIDER_EXTERNAL_FEED_ENDPOINTS="{\"endpointCredentials\":[{\"endpoint\":\"https://pkgs.dev.azure.com/__redacted__/nuget/v3/index.json\",\"password\":\"${FEED_ACCESS_TOKEN}\"}]}"
RUN dotnet restore "MyApp.csproj" -r linux-musl-x64
COPY --link . .
RUN dotnet build "./MyApp.csproj" -c $BUILD_CONFIGURATION -o /app/build /p:BuildingInsideDocker=true --no-restore
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN apk add --no-cache npm && npm install --prefix "./ClientApp" && npm run prod --prefix "./ClientApp"
RUN dotnet publish "./MyApp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false -r linux-musl-x64 --self-contained false --no-restore
# Dev: Alpine with ca-certificates for local docker-compose (runs as root for update-ca-certificates)
FROM base-alpine AS dev
WORKDIR /app
COPY --link --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]
# Final: Alpine minimal for cloud (non-root for security)
FROM dev AS final
USER $APP_UIDReacted by embetten
Metadata
Metadata
Assignees
Labels
No labels
Activity
embetten commentedon Mar 11, 2026
Do you mind reviewing and trying out the changes in #656 to see if that resolves the warning and allows you to build successfully? Thanks for the issue
moraekyle commentedon Mar 11, 2026
I see now that you had a link to this sample file in the README.md, but it wasn't near as prominent as the link to https://github.com/dotnet/dotnet-docker/blob/main/documentation/scenarios/nuget-credentials.md#using-the-azure-artifact-credential-provider.
I'll give this a try, but I think I've done something like this today, and I got away from it because it gave me warnings when I proceeded with
dotnet buildanddotnet publish. My AI tool suggested that was becausedotnet buildstill invokes the nuget "path" even though I used--no-restore.Give me a few and I'll report back.
UPDATE: Yeah, that's what I thought. It DOES work, sure. But I get this with the
dotnet buildbut notdotnet publishcommands:embetten commentedon Mar 12, 2026
I just pushed updates to #656 which I tested locally and confirmed working.
From the
he plugin credential provider could not acquire credentials. ...messages I would assume the env variables are not being set correctly.A key difference in the pr changes the scope: export VSS_NUGET_URI_PREFIXES and export VSS_NUGET_ACCESSTOKEN (or ARTIFACTS_CREDENTIALPROVIDER_EXTERNAL_FEED_ENDPOINTS ) must be in the same RUN step as dotnet restore (and any other command that triggers a restore, like dotnet build or dotnet publish). Since they're exported rather than set via ENV, they only exist for that single RUN command.
moraekyle commentedon Mar 12, 2026
I'll check tomorrow. Thank you. How does
VSS_NUGET_URI_PREFIXEShelp with a specific NuGet feed in AzDO? In other words, how does it know the full URL for the feed?A couple other things:
ARTIFACTS_CREDENTIALPROVIDER_URI_PREFIXESandARTIFACTS_CREDENTIALPROVIDER_ACCESSTOKENinstead?ARTIFACTS_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED.embetten commentedon Mar 12, 2026
it does not - this change generalizes and simplifies the example. It basically says the credprovider will hand back the
ARTIFACTS_CREDENTIALPROVIDER_ACCESSTOKENfor any feed url that starts withhttps://pkgs.dev.azure.comwhich should be all ado feeds not using the legacy url. If you have multiple feeds with different identities or want to scope the token to a single feedARTIFACTS_CREDENTIALPROVIDER_EXTERNAL_FEED_ENDPOINTSwould be a better fit tbh.Thanks for the feedback and collaboration - let me know your thoughts
moraekyle commentedon Mar 12, 2026
TL;DR - If I use
RUN --mountfor bothdotnet restoreanddotnet publish, we're good to go. No warnings from Docker nor NuGet.embetten - I can't tell you how grateful I am for your quick and direct responses! You've taught me more in this thread about this provider than I could have understood from reading the docs.
It looks like we'll have to do the
RUN --mountfor thedotnet build, too. I was hoping to avoid that (just because I feel like dockerfile is already too verbose), but oh well. Here's my final dockerfile that seems to work. (I'm still testing whether or not I care about the ACP caching disabled.)(I did add the
ENV ARTIFACTS_CREDENTIALPROVIDER_URI_PREFIXESearlier to save a single line. 😄 )docs: move to docker secret mount for passing in pat token (#656)
embetten commentedon Mar 13, 2026
closing - updated our repo sample with updated guidance. Will follow up with dockef