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

Non-programmatic support for http and https proxies in Docker image #178

Closed
naderghanbari opened this issue Jul 8, 2024 · 3 comments
Closed
Labels
enhancement New feature or request

Comments

@naderghanbari
Copy link

naderghanbari commented Jul 8, 2024

Describe the feature request

Unleash Proxy Docker image, and Unleash Proxy as a standalone Node.js app, to support configuring http/http proxies via environment variables.

Background

Unleash proxy docker image, and Unleash Proxy as a standalone Node.js app, do not seem to support http/http proxies (for instance a corporate proxy). So running them out of the box inside a corporate network that requires a proxy for egress traffic is not possible.

There is a discussion around this here but the suggested workarounds do not seem to work.

The workaround, is to create a new Node.js app, depend on unleash-proxy, and then start the app using the following, and then Dockerize it, etc.

import { createApp } = from '@unleash/proxy';
import { URL } from 'url';
import { getAgent } from '@npmcli/agent';

const agentDefaultOptions = {
    keepAlive: true,
    keepAliveMsecs: 30 * 1000,
    timeout: 10 * 1000,
};

const app = createApp({
    httpOptions: {
        // By using the getAgent function from npmcli/agent, the support 
        // for PROXY, HTTP_PROXY, HTTPS_PROXY and NO_PROXY is unmasked
        // unleash-client-node masks this support by providing its own agents
        agent: (url: URL) => getAgent(url, { options: agentDefaultOptions }),
    },
});

app.listen(3000, () =>
    console.log(`Unleash Proxy listening on http://localhost:3000/proxy`),
);

I understand this may require changes in the Unleash Node Client. Otherwise, if the changes I mentioned above look good to the maintainers, I will be happy to make a pull request.

Solution suggestions

Make use of getAgent from npm/cli to make use of the out of the box support for proxies provided by npm/cli.

@naderghanbari naderghanbari added the enhancement New feature or request label Jul 8, 2024
@chriswk chriswk moved this from New to In Progress in Issues and PRs Jul 10, 2024
@kwasniew
Copy link
Contributor

@naderghanbari we updated our own proxy (https://github.com/Unleash/unleash-proxy/releases/tag/v1.4.0) to use the latest Node SDK that added support for HTTP_PROXY and HTTPS_PROXY env vars. Please let us know if it solves your issue.

@naderghanbari
Copy link
Author

naderghanbari commented Jul 12, 2024

Thanks @kwasniew , I confirm version 1.4.0 is working for us. It supports HTTP_PROXY and HTTPS_PROXY. It however does not support NO_PROXY. For our use case it works, but I imagine for some it may not.

I will close this issue, but do you see any downside to the approach I posted in the OP? That is passing the defaultOptions to the getAgent function of @npmcli/agent (which supports all of these env vars)?

@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Jul 12, 2024
@kwasniew
Copy link
Contributor

@naderghanbari I described my design decision of not using @npmcli/agent here: Unleash/unleash-client-node#638. It comes down to TS support. If we get feedback about NO_PROXY we'll consider adding it later. Glad to hear the current solution works for your team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

2 participants