How to Capture Fiddler Trace in Linux Container (For APIM Self-hosted Gateway)

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

In certain conditions, we may need to monitor all HTTP/HTTPS traffic from APIM self-hosted gateway, which is deployed into Linux Docker Container.

 

Capturing Fiddler trace is one of the available options. However, there are limitations:

  1. APIM self-hosted gateway image is built by Azure APIM product group and we cannot build the Fiddler tool into the container image.
  2. APIM self-hosted gateway is a Linux container. Fiddler Classic only works in Windows environment.

The instructions below guide you how to bypass the limitations and capture Fiddler trace in Linux containers (for APIM self-hosted gateway).

 

Pre-requirements:  

Before starting, you must setup the environment at first.   

To set up a local development environment, you need to have:  

  1. API Management instance. If you don't have one, please follow this tutorial.  
  2. Deploy an Azure API Management self-hosted gateway to Docker. If you don't have one, please follow this tutorial.
  3. Install Fiddler Classic into your local computer. To download Fiddler Classic, please click this link

 

Steps to implement: 

  1. Open Fiddler. Go to Options… => Connections, select Allow remote computes to connect. In the screenshot below, Fiddler listens on port 8888. Then Fiddler will capture traffic from another machine (any OS).

Lucy_Weng_0-1605080047411.png

 

Lucy_Weng_1-1605080047460.png

 

  1. Go to HTTPS and DISABLE Decrypt HTTPS traffic.

Lucy_Weng_2-1605080047493.png

 

  1. Open CMD on the start menu. Check your local IP with the command ipconfig. My IP is 100.64.77.231 as shown in the screenshot below.

Lucy_Weng_3-1605080047502.png

 

  1. Open the file env.conf for the APIM self-hosted gateway. Specify the HTTP/HTTPS proxy here. Fiddler by default listens the port 8888, as discussed in the Step One.Lucy_Weng_4-1605080047507.png

     

  2. Deploy the Docker container by following this tutorial. Please use the modified file env.conf in step 4.

 

  1. Use command "docker exec your-container-id env" to check if HTTP/HTTPS proxy is enabled as environment variables within the docker container. As shown in the screenshot below, the traffic is flowed into the Fiddler, but the HTTPS requests are still encrypted.

Lucy_Weng_5-1605080047517.png

 

  1. If we need to decrypt the HTTPS traffic, we need to install Fiddler root certificate into the container CA certificate list. Go back to Fiddler. Open Options => HTTPS => Actions. Select Export Root Certificate to Desktop. The certificate name should be FiddlerRoot.cer by default.

Lucy_Weng_6-1605080047537.png

 

  1. Copy the root certificate to the docker container by using the following command:
  • docker cp C:\Users\your-user-name\Desktop\FiddlerRoot.cer your-container-id:/home/fiddlerPublicCert.cer
  1. As update CA certificates in the Docker container needs the admin permission, we can exec into the Docker container in iterative mode by using the following command:
  • docker exec -u root -it your-container-id /bin/sh
  1. Update the CA certificates to enable the fiddler root cert by the following command:
  • update-ca-certificates

Lucy_Weng_7-1605080047548.png

 

  1. Go back to Fiddler. Open Options => HTTPS. Enable Decrypt HTTPS traffic.

Lucy_Weng_8-1605080047568.png

 

  1. To test if Fiddler can capture the requests in Docker container, we can send the simple requests to the APIM self-hosted gateway via CURL. In the tests below, I sent two HEAD requests to the self-hosted gateway and Fiddler successfully capture both.

Lucy_Weng_9-1605080047579.png

 

Lucy_Weng_10-1605080047654.png

 

REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.