Using the az CLI Behind Zscaler
At work I use the az CLI behind a VPN/proxy package called Zscaler. I’m not a big fan of these TLS-intercepting-man-in-the-middle-attack sort of “security” products, but it is what it is.
The problem for me is that, if I move to a new machine, or if someone else is setting up a machine, I always forget how to make the az CLI trust Zscaler so it can function properly and not get a TLS certificate error. I’ve re-figured this out countless times, so this time I’m writing it down. It does seem to be slightly different on Mac and Windows and I’m not sure why. Perhaps it has to do with the different ways the network stack works or something.
The az CLI is Python-based so this will ostensibly work to generally solve Python issues, but I always encounter it as part of az, so I’m blogging it as such.
Zscaler does have some help for enabling trust but you sometimes have to fudge the steps, like with this.
On Mac
- Make sure you have the Zscaler certificate in your system keychain as a trusted CA. Likely if you have Zscaler running this is already set up.
- Install the latest
ca-certificatespackage or get the content from here. - Set the
REQUESTS_CA_BUNDLEenvironment variable to point at thecert.pemthat has all the CA certs in it.
This works because the Homebrew package for ca-certificates automatically includes all the certificates from your system keychain so you don’t have to manually append your custom/company CA info.
On Windows
- Go get the latest
ca-certificatesbundle from here. - Open that
cert.pemfile in your favorite text editor. Just make sure you keep the file withLFline endings. - Get your Zscaler CA certificate in PEM format. Open that up in the text editor, too.
- At the bottom of the
cert.pemmain file, paste in the Zscaler CA certificate contents, thereby adding it to the list of CAs. - Set the
REQUESTS_CA_BUNDLEenvironment variable to point at thecert.pemthat has all the CA certs in it.
Again, not sure why on Windows you need to have the Zscaler cert added to the main cert bundle but on Mac you don’t. This also could just be something environmental - like there’s something on my work machines that somehow auto-trusts Zscaler but does so to the exclusion of all else.
Regardless, this is what worked for me.