0

I'm developing an app (written in Go/Golang and using the "official" MongoDB driver) that must access MongoDB databases in both MongoDB as well as Cosmos/Azure (using the MongoDB API). I use Studio3T to help out with the database tasks and my app runs as a command line utility that I launch from within iTerm running as bash.

I'm able to access the MongoDB databases--one of which is running locally on my Mac, the other 2 are on company servers behind our firewall (my Mac is running nearly always on a company VPN). It's the Cosmos instance in Azure that has been challenging to connect to.

I obtained the necessary Cosmos connection information from the Azure portal and tried to create the connection settings in Studio 3T and my app. At first, neither would work, but when I manually set the proxy settings in Studio3T to use our regular proxy server, it was able to connect to the Cosmos instance just fine. My app, on the other hand, still cannot connect, saying that the server is unknown.

I've tried multiple permutations of the connection string in my app--including one that mirrors the one generated by Studio3T--that looks like this:

mongodb://<user>:<pw>@<host>:<port>/admin?ssl=true&replicaSet=<repSet>&readPreference=primary&maxIdleTimeMS=120000&connectTimeoutMS=10000&authSource=admin&authMechanism=SCRAM-SHA-1

(items in brackets are set with exactly the same values that work in Studio3T)

What makes it confusing is that my Mac is set globally to use the same proxy server with exactly the same settings I put into Studio 3T, and the shell/bash environment where my app gets started has the http_proxy/https_proxy variables set to exactly the same settings and it still doesn't work. Also, I'm able to access all kinds of external Internet-based resources on my Mac, and it's really only this particular Cosmos instance in Azure that is inaccessible (and even then, it's only inaccessible to my Go program, not the Studio3T instance running on exactly the same machine and using exactly the same settings).

This is a classic "say the magic word" problem, the kind of thing that makes me wish I'd gone to cooking school rather than taking up writing software.

So, my questions are:

  1. What does Studio 3T do when it sees settings that enable using a custom proxy server? Is there some kind of internal logic in Studio 3T that allows its MongoDB connection to discover Azure-based instances of Cosmos using those settings? I noticed that the URI that Studio 3T generates has these params: 3t.proxyType=custom, 3t.proxyProtocol=htttp, 3t.proxyHost, 3t.proxyPort, which I assume are Studio3T-specific, but obviously must be something that Studio3T uses to signal its proxy handling behavior

  2. Is there something I can add to my Go program that would "set the stage" for the driver's attempt to connect to Cosmos so that it connects to the Cosmos instance like Studio3T is able to?

  3. Are there any environment settings I can tweak (including anything that's set globally at the MacOS-level in Network Preferences) that can facilitate my app's ability to navigate our proxy server and connect to Cosmos?

Any insight/suggestions/help you can give me would be greatly appreciated...

Paul Uzee
  • 11
  • 3

1 Answers1

1

A proxy address looks like this

http://USER:PASSWORD@COMPANY.EXAMPLE.TLD:PORT

Or something like this

http://aiw1dak1:powalkmd1@my.internal.company.local:8571

That is something you need to set in your mac computer to be able to make connections through a proxy, for example

export http_proxy = http://aiw1dak1:powalkmd1@my.internal.company.local:8571

More info here: https://www.serverlab.ca/tutorials/osx/administration-osx/configuring-a-network-proxy-for-osx/

That should set every network requests through the proxy, including MongoDB.

You can also go to the network settings and configure the network's proxy settings to make requests automatically, and you can request your company to give you a WPAD file.

Wolfgang
  • 1,328
  • 2
  • 8
  • 11
  • Thanks for the suggestions, but I had already tried all of the things mentioned in the article you linked to, and my system has been setup with all of the various standard proxy settings at every level (globally in Network Preferences, in my bash environment and in the various applications that have proxy settings). With all of that in place the only app that's able to connect to the Cosmos instance is Studio3T. I'm starting to dig around in some of the other places where networked resources are configured (e.g., /etc/hosts) and will also try to discover other ways the proxy can be accessed – Paul Uzee Dec 16 '21 at 16:29
  • Yeah it happened to me as well, thing is it probably uses python, which gets the proxy settings from somewhere else. You can try it. Try installing something with pip for example, or other package managers that use python. – Wolfgang Dec 16 '21 at 16:52