Skip to content

Instantly share code, notes, and snippets.

@markusthoemmes
Last active April 16, 2020 10:08
Show Gist options
  • Save markusthoemmes/c42479255ce9973c6289326ed93f1959 to your computer and use it in GitHub Desktop.
Save markusthoemmes/c42479255ce9973c6289326ed93f1959 to your computer and use it in GitHub Desktop.
HTTPS Proxy testing with mitmproxy

HTTPS Proxy testing with mitmproxy

Basic functionality test

  1. Get a machine to run mitmproxy. Anything that can get an IP will work.
  2. Download mitmproxy: wget https://snapshots.mitmproxy.org/5.0.1/mitmproxy-5.0.1-linux.tar.gz
  3. Unpack: tar -xf mitmproxy-5.0.1-linux.tar.gz
  4. Just run mitmproxy: ./mitmproxy --set block_global=false. Disabling block_global is important to allow any traffic.
  5. Get the relevant certificate: cat ~/.mitmproxy/mitmproxy-ca-cert.pem
  6. Try out it works: curl --proxy $IP:8080 --cacert mitmproxy-ca-cert.pem https://www.canihazip.com/s

On Openshift

Create a ConfigMap containing the certificate from above:

apiVersion: v1
data:
  ca-bundle.crt: | 
    <MY_PEM_ENCODED_CERTS>
kind: ConfigMap
metadata:
  name: user-ca-bundle 
  namespace: openshift-config

Configure the global proxy object to talk to our setup proxy using the specified cert:

apiVersion: config.openshift.io/v1
kind: Proxy
metadata:
  name: cluster
spec:
  httpProxy: http://$IP:8080
  httpsProxy: http://$IP:8080
  noProxy: example.com
  trustedCA:
    name: user-ca-bundle

Apply a Knative Service and observe how the request goes via the Proxy, even if it's HTTPS:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    spec:
      containers:
        - image: gcr.io/knative-samples/helloworld-go # The URL to the image of the app
          env:
            - name: TARGET # The environment variable printed out by the sample app
              value: "Go Sample v1"
> 08:14:15 GET  HTTPS               gcr.io /v2/                                                                              401 ~plication/json   84b 108ms
  08:14:15 GET  HTTPS               gcr.io /v2/token?scope=repository%3Aknative-samples%2Fhelloworld-go%3Apull&service=gcr.~ 200 ~plication/json  408b 130ms
  08:14:16 GET  HTTPS               gcr.io /v2/knative-samples/helloworld-go/manifests/latest                                200 ~nifest.v2+json 2.16k 326ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment