Kubernetes Hostalias redirecting to Kubernetes service without Request Headers

9/11/2018

Running this in MINIKUBE before I push to AWS

I am trying a "Man in the middle" on one of my pods. Idea, change the hosts file inside my docker container that lives inside a kubernetes pod. The hosts file will see a request to api.app.org and redirect any calls to this host to ip address "10.101.63.179". The application running on the kubernetes service is an express app that captures http requests and directs them to the appropriate method for consumption. The app looks at the request headers and breaks out the "host" and the "URL". Should look like this

host = api.app.org

URL = "/v2/1234"

Expected : The kubernetes service will be sent an HTTP request.
example : api.app.org/v2/1234
Node Express app is called and manages execution based on "host" and the rest of the URL. "/v2/1234"

Actual:
1. HOSTS file is updated via Kubernetes hostalias added inside the deployment. Code below.
2. Call from within application makes an HTTP request to "api.app.org/v2/1234" .
3. The HOSTS file redirects the HTTP request to IP address "10.101.63.179"
-- so far so good --

(inside express app now) .

  1. Runs a method to extract Host and the rest of the URL.
    -- example : host should equal ( api.app.org )
    -- example : url should equal (/v2/1234) .

PROBLEM...

host = 10.101.63.179 .

URL = / .


CODE : /etc/hosts . host file from docker image inside kubernetes pod : ran (kubectl exec -it -c -- /bin/bash ) .

# Entries added by HostAliases. 10.101.63.179 api.stats.com 10.101.63.179 api.ap.org


CODE: Kubernetes Deployment YAML

apiVersion: extensions/v1beta1 kind: Deployment metadata: namespace: testharness labels: run: raven-svc name: raven-svc spec: replicas: 1 selector: matchLabels: run: raven-svc template: metadata: labels: run: raven-svc spec: containers: - name: raven-svc image: raven:vFin imagePullPolicy: IfNotPresent ports: - containerPort: 3000 hostAliases: - ip: "10.101.63.179" hostnames: - "api.stats.com" - "api.ap.org" restartPolicy: Always

-- Wes Duff
docker
hosts
kubernetes
redirect

1 Answer

9/11/2018

The hosts file as basically at IP level in the stack so it wouldn't strip any layer 6-7 headers(http/https). Also kubernetes sets up iptables to route between pods and generally that's all at the IP level too.

Is 10.101.63.179 an ingress controller by any chance? that could be stripping your headers.

-- Rico
Source: StackOverflow