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

[UseDotNetV2] Not setting "no_proxy" nuget config on Windows agents #16935

Closed
gigi81 opened this issue Sep 21, 2022 · 7 comments · Fixed by #19252
Closed

[UseDotNetV2] Not setting "no_proxy" nuget config on Windows agents #16935

gigi81 opened this issue Sep 21, 2022 · 7 comments · Fixed by #19252
Labels
Area:RM RM task team

Comments

@gigi81
Copy link

gigi81 commented Sep 21, 2022

Entering this information will route you directly to the right team and expedite traction.

Question, Bug, or Feature?
Type: Bug

Enter Task Name: UseDotNet

Environment

  • Server - Azure Pipelines or TFS on-premises? Azure Pipelines
  • Agent - Hosted or Private: Private

Issue Description

When UseDotNet (V2) runs on a Windows agent, it runs a series of nuget.exe commands at the end to setup the proxy configuration. However these series of commands do not set the "no_proxy" parameter resulting in a wrong configuration and following dotnet restore step failing.

Task logs

Setting up proxy configuration for NuGet.
D:\ado\agents\agent-1_work_tool\NuGet\4.4.1\x64\nuget.exe config -set http_proxy=http://myproxy.com:8080
D:\ado\agents\agent-1_work_tool\NuGet\4.4.1\x64\nuget.exe config -set http_proxy.user=undefined
D:\ado\agents\agent-1_work_tool\NuGet\4.4.1\x64\nuget.exe config -set http_proxy.password=undefined

Work Around

Added this step after UseDotNet@2 to make it work.

- task: CmdLine@2
  displayName: 'Nuget config work around'
  condition: eq( variables['Agent.OS'], 'Windows_NT' )
  inputs:
    script: 'nuget.exe config -set no_proxy=.mydomain.com'

Fix

The issues is in nugetinstaller.ts
Which is not using the proxyBypassHosts parameter to set the no_proxy nuget parameter.
There should be another command issued to set the no_proxy parameter.

@github-actions
Copy link

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

@github-actions github-actions bot added the stale label Mar 20, 2023
@gigi81
Copy link
Author

gigi81 commented Mar 20, 2023

Issue still present

@github-actions github-actions bot removed the stale label Mar 20, 2023
@github-actions
Copy link

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

@github-actions github-actions bot added the stale label Sep 16, 2023
@gigi81
Copy link
Author

gigi81 commented Sep 16, 2023

Still an issue

@github-actions github-actions bot removed the stale label Sep 16, 2023
@v-mohithgc v-mohithgc added the Area:RM RM task team label Oct 5, 2023
@wkz123
Copy link

wkz123 commented Oct 9, 2023

For the love of... please fix this!

@danko-d
Copy link

danko-d commented Jan 4, 2024

You cannot simply use the content of .proxybypass for the no_proxy setting of nuget.config, because they are different formats:

For example, a valid .proxybypass like my\.domain\.org wouldn't work for the no_proxy setting.

@mhudasch
Copy link

mhudasch commented Jun 19, 2024

Big thank you @danko-d for mentioning this.

It took me several days to investigate that:

Hosts that should be bypassed by the agent are defined according to https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/proxy?view=azure-devops&tabs=windows#specify-proxy-bypass-urls
As described these expressions are in ECMA Script regex escaped format (for example my\.bypasshost\.org) so that those lines can easily used by the pipeline tasks running in node (so the expressions must be in this format or else handling by other tasks will break)

Later those setting are string joined with comma and added to the service user nuget.config (%AppData%/NuGet/NuGet.Config) with using nuget config set no_proxy as suggested by @gigi81.
This is problematic for several reasons (and for a long time at that). When running a server with multiple agent services using the same service user changes to the NuGet.config file on user-level impact all paralell executing jobs by the agent services.
The 'workaround' by @gigi81 using nuget config set no_proxy before restore becomes a racecondition to edit the NuGet.config file by multiple jobs and might fail randomly (and very hard to reproduce).
It would be way better to take the agent settings and set the environment variables that are supported by nuget.exe for the best scoping of these settings.

Finally nuget.exe (since v4+) supports proxy settings in NuGet.config but only on user-level, and http_proxy / no_proxy environment variables. As you can see here https://github.com/NuGet/NuGet.Client/blob/a32bce39889f724fbd11cfd12e946f802168b583/src/NuGet.Core/NuGet.Configuration/Proxy/ProxyCache.cs#L80 if there is http_proxy setting present in the users' NuGet.config file, all settings (inlcuding no_proxy) take precedence over environment variables. The previously joined no_proxy values get splitted again and put into the bypassList. Later those values are used here https://github.com/NuGet/NuGet.Client/blob/a32bce39889f724fbd11cfd12e946f802168b583/src/NuGet.Core/NuGet.Configuration/Proxy/WebProxy.cs#L76. As you can see in the WildcardToRegex method, those values in the list are regex-escaped again which causes a 'double-escaping' turning our sample my\.bypasshost\.org to my\\.bypasshost\\.org which in turn never matches the incoming host of a nuget package source.

I recognize this is an edge case but I would really like a fix for this issue and maybe in the span of two years no less.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:RM RM task team
Projects
None yet
5 participants