-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Go: Support private registries via GOPROXY
#19248
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
base: main
Are you sure you want to change the base?
Conversation
cmd.Env = append(cmd.Env, fmt.Sprintf("HTTP_PROXY=%s", proxy_address)) | ||
cmd.Env = append(cmd.Env, fmt.Sprintf("HTTPS_PROXY=%s", proxy_address)) |
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.
You can append two things at once. append
is variadic.
cmd.Env = append(cmd.Env, fmt.Sprintf("HTTP_PROXY=%s", proxy_address)) | |
cmd.Env = append(cmd.Env, fmt.Sprintf("HTTPS_PROXY=%s", proxy_address)) | |
cmd.Env = append(cmd.Env, fmt.Sprintf("HTTP_PROXY=%s", proxy_address), fmt.Sprintf("HTTPS_PROXY=%s", proxy_address)) |
if proxy_port, proxy_port_set := os.LookupEnv(PROXY_PORT); proxy_port_set { | ||
proxy_address = fmt.Sprintf("http://%s:%s", proxy_host, proxy_port) | ||
slog.Info("Found private registry proxy", slog.String("proxy_address", proxy_address)) | ||
} |
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.
Is it the desired behaviour that if the host is set but not the port then the host isn't used? Is there some kind of default port that could be tried? Or should there be some logging in this case, so that when it doesn't work the user can easily see what has happened?
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.
We wouldn't expect users to set any of these. These environment variables are set in the default setup workflow and we would only ever expect both to be set at the same time. In particular, the proxy uses a random, available port on the runner.
} else { | ||
// We only care about private registry configurations that are relevant to Go and | ||
// filter others out at this point. | ||
proxy_configs = make([]RegistryConfig, 0) |
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.
You could use the length of val
as a third argument to make, which specifies the capacity of the underlying array. Or maybe it isn't worth it if you only ever expect very few.
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.
We only expect a few (indeed, the UI only supports configuring one at the moment). That said, I have noticed since that calling make
to initialise the array isn't necessary since append
will apparently do this if it is nil
anyway.
cmd.Env = append(cmd.Env, fmt.Sprintf("GOPROXY=%s", goproxy_val)) | ||
cmd.Env = append(cmd.Env, "GOPRIVATE=") | ||
cmd.Env = append(cmd.Env, "GONOPROXY=") |
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.
As above, you can append them all at once.
This PR is part of work to enable private package registries to be used in Default Setup. See prior work for C#: #18029 and #18850
The existing Default Setup workflow will initialise the Dependabot package proxy, if a private package registry configuration is set. The host, port, certificate, and configurations used by the proxy are then passed to CodeQL in the
analyze
step. For Go, we will likely need to modify this to make these environment variables available to theautobuild
step as well.The changes in this PR modify the Go extractor to recognise when the corresponding environment variables are set. If so, we use the data from those environment variables to:
go
via theHTTP_PROXY
andHTTPS_PROXY
environment variables.go
viaSSL_CERT_FILE
.goproxy_server
configurations and use them to set an appropriate value for theGOPROXY
environment variable.This has the effect that
go
will attempt to make requests to obtain packages to theGOPROXY
servers. These will go via the Dependabot proxy configured byHTTP_PROXY
andHTTPS_PROXY
, which handles the needed authentication for theGOPROXY
servers.