-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C#: Set proxy environment variables, if Dependabot proxy is detected #18029
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
Conversation
c5c1260
to
9731006
Compare
9731006
to
a107872
Compare
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs
Fixed
Show fixed
Hide fixed
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, added some comments/questions.
What's not working on macOS? Is it the dotnet calls, or the httpclient that's not working?
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependabotProxy.cs
Outdated
Show resolved
Hide resolved
httpClientHandler.Proxy = new WebProxy(this.dependabotProxy.Address); | ||
|
||
if (!String.IsNullOrEmpty(this.dependabotProxy.CertificatePath)) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this, because we need to support a certificate that's not signed by a well-known trusted root cert authority?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. The Dependabot Proxy uses a self-signed certificate that is generated when we initialise it in the Default Setup workflow. That's then passed to us in an environment variable, and we should trust it.
|
||
namespace Semmle.Extraction.CSharp.DependencyFetching | ||
{ | ||
public class DependabotProxy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably implement System.Net.IWebProxy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but I am not sure I see any immediate benefit to it. Although I guess it would simplify the implementation for the feed reachability checking? Happy to do that in a follow-up PR if it makes sense, but it would be nice to get this functionality shipped for now.
|
fca0b6a
to
dcfcb88
Compare
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependabotProxy.cs
Outdated
Show resolved
Hide resolved
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependabotProxy.cs
Outdated
Show resolved
Hide resolved
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependabotProxy.cs
Outdated
Show resolved
Hide resolved
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs
Outdated
Show resolved
Hide resolved
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependabotProxy.cs
Outdated
Show resolved
Hide resolved
If we don't expect this change to work on macos and windows, we should be explicit about it. Can we only create the dependabot proxy if we're on linux? |
@tamasvajk this is done as part of the Default Setup workflow with a dedicated action. Until recently, this only supported Linux. It does now support Windows and macOS as well, but the docs for the private registries feature will note the current limitations. In other words, it's not something we need to worry about in this C#-specific part. |
Does this mean that on Windows and MacOS, the |
…ment `IDisposable`
dcfcb88
to
2e80e09
Compare
@tamasvajk They do get set on Windows and macOS. The environment variables we set here just wouldn't affect However, the proxy we install for the feed reachability check would be affected. That would result in a weird situation on those platforms where we check whether the feeds that require the proxy (i.e. require authentication) are reachable, determine that they are, but then So I have now added a check to skip initialising the I have also addressed all of your other review comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@tamasvajk I tested this a bit more after the changes in response to your review, and ran into some flakiness with the |
|
||
using var writer = certFile.CreateText(); | ||
writer.Write(cert); | ||
writer.Close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm somewhat surprised that this is needed. The writer
is disposed at the end of this method, and we wouldn't access the file elsewhere before that. If you want to control the disposal a bit more fine grained, you could still use a using
block, and you could get rid of the Close
call.
using(var writer = certFile.CreateText())
{
writer.Write(cert);
}
This PR is part of work to enable private package registries to be used in Default Setup.
The existing Default Setup workflow will initialise the Dependabot package proxy, if a private package registry configuration is set. The host, port, and certificate used by the proxy are then passed to CodeQL in the
analyze
step.The changes in this PR modify the C# extractor to recognise when the corresponding environment variables are set. If so, we use the data from those environment variables to:
dotnet
via theHTTP_PROXY
andHTTPS_PROXY
environment variables.dotnet
viaSSL_CERT_FILE
.In testing so far, this works fine on Linux with fairly arbitrary versions of
dotnet
. It does not seem to work on macOS and likely also does not work on Windows.