I am trying to access the Microsoft Azure translator API from inside docker in WSL2:
curl -v "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: xxx" -H "Content-Type: application/json; charset=UTF-8" -d "[{'Text':'Hello friend.'}]"
The query works from WSL2 outside of docker with the Windows wireguard VPN active and networkingMode=mirrored active, suggesting that "it works" from WSL2 over the VPN to the Azure API. Without the VPN inside the docker container the query also works fine, suggesting it's a network issue but only when the VPN is activated. Certain other queries work fine when both inside docker and with the VPN active, e.g, curl -v https://monip.org works fine.
The query that fails seems to fail at the TLS handshake stage, so a basic connection is established:
* Host api.cognitive.microsofttranslator.com:443 was resolved.
* IPv6: (none)
* IPv4: 20.43.132.97
* Trying 20.43.132.97:443...
* Connected to api.cognitive.microsofttranslator.com (20.43.132.97) port 443
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
-> hangs here
When it works I get the following directly after the point where it hangs.
...
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
...
I originally noticed the issue in Python3 code but the same issue appears with curl. Both the docker image and wsl2 in these tests are Ubuntu 22.04 but I also saw it in the python 3.12.2-slim docker image.
What might be going wrong?