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

Proxy support is broken #3115

Open
zmwangx opened this issue Aug 7, 2021 · 1 comment
Open

Proxy support is broken #3115

zmwangx opened this issue Aug 7, 2021 · 1 comment

Comments

@zmwangx
Copy link

zmwangx commented Aug 7, 2021

Describe the bug

Proxy support was introduced in #1215, but it is currently broken.

To Reproduce

Steps to reproduce the behavior:

  1. Somehow make api.netlify.com unavailable, e.g. by being on a closed network where a proxy is required. For reproduction purposes, one can force this by modifying /etc/hosts and pointing api.netlify.com to a local container / VM where we spin up a trivial HTTP server that simply stalls on any incoming request.
  2. Have a proxy server set up, e.g. mitmproxy or Charles.
  3. Run any command through a proxy, e.g. HTTP_PROXY=http://localhost:8888 netlify login.

At this point netlify-cli would simply stall, and if you monitor the proxy server you'll notice that no request is going through it.

Configuration

N/A.

Expected behavior

Any network request originating from netlify-cli should be proxied.

CLI Output

N/A.

Additional context

This happens because getConfig happens before the proxy is even configured (with getAgent)

cli/src/utils/command.js

Lines 46 to 57 in 7a55e98

const cachedConfig = await this.getConfig({ cwd, state, token, ...apiUrlOpts })
const { configPath, config, buildDir, repositoryRoot, siteInfo } = cachedConfig
const normalizedConfig = normalizeConfig(config)
const { flags } = this.parse(BaseCommand)
const agent = await getAgent({
exit: this.exit,
httpProxy: flags.httpProxy,
certificateFile: flags.httpProxyCertificateFilename,
})
const apiOpts = { ...apiUrlOpts, agent }
const globalConfig = await getGlobalConfig()

getConfig calls resolveConfig which is @netlify/config.

const resolveConfig = require('@netlify/config')

Looking at @netlify/config's resolveConfig: https://github.com/netlify/build/blob/6813d73a21a6c4a6b99576c5b7bc60fae5d8bac4/packages/config/src/main.js#L32-L36 we see that there are API requests made at this stage unless offline is true. These requests obviously aren't going through the proxy.

I guess to actually fully support proxies you need to add proxy support to @netlify/config as well.


Knowing the cause of the issue, here's a risky workaround btw: just set offline to true in src/utils/command.js:

-    const cachedConfig = await this.getConfig({ cwd, state, token, ...apiUrlOpts })
+    const cachedConfig = await this.getConfig({ cwd, state, token, offline: true, ...apiUrlOpts })

One can hot edit this directly into node_modules/netlify-cli/src/utils/command.js. (Don't complain to me if anything breaks, obviously.)


Related: I believe #2016 is exactly this problem.

@zmwangx zmwangx added the type: bug code to address defects in shipped code label Aug 7, 2021
@erezrokah
Copy link
Contributor

Thanks @zmwangx, I believe this is a duplicate of #2399, but I'm closing #2399 in favor of this one since due to the more detailed description here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants