Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

haproxy obfuscated internal IP in routing cookie #8334

Merged
merged 1 commit into from
Apr 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions images/router/haproxy/conf/haproxy-config.template
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ backend be_edge_http_{{$cfgIdx}}
{{ end }}
http-request set-header Forwarded for=%[src];host=%[req.hdr(host)];proto=%[req.hdr(X-Forwarded-Proto)]
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
server {{$endpoint.ID}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms cookie {{$endpoint.ID}}
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms cookie {{$endpoint.IdHash}}
{{ end }}
{{ end }}

Expand All @@ -236,7 +236,7 @@ backend be_secure_{{$cfgIdx}}
timeout check 5000ms
cookie OPENSHIFT_REENCRYPT_{{$cfgIdx}}_SERVERID insert indirect nocache httponly secure
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
server {{$endpoint.ID}} {{$endpoint.IP}}:{{$endpoint.Port}} ssl check inter 5000ms verify required ca-file {{ $workingDir }}/cacerts/{{$cfgIdx}}.pem cookie {{$endpoint.ID}}
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} ssl check inter 5000ms verify required ca-file {{ $workingDir }}/cacerts/{{$cfgIdx}}.pem cookie {{$endpoint.IdHash}}
{{ end }}
{{ end }}
{{ end }}{{/* $serviceUnit.ServiceAliasConfigs*/}}
Expand Down
9 changes: 9 additions & 0 deletions pkg/router/template/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package templaterouter

import (
"crypto/md5"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -230,6 +231,14 @@ func createRouterEndpoints(endpoints *kapi.Endpoints, excludeUDP bool) []Endpoin
} else {
ep.TargetName = ep.IP
}

// IdHash contains an obfuscated internal IP address
// that is the value passed in the cookie. The IP address
// is made more difficult to extract by including other
// internal information in the hash.
s := ep.ID + ep.TargetName + ep.PortName
ep.IdHash = fmt.Sprintf("%x", md5.Sum([]byte(s)))

out = append(out, ep)
}
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/router/template/router_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package templaterouter

import (
"crypto/md5"
"fmt"
"testing"

Expand Down Expand Up @@ -47,9 +48,10 @@ func TestAddEndpoints(t *testing.T) {
}

endpoint := Endpoint{
ID: "ep1",
IP: "ip",
Port: "port",
ID: "ep1",
IP: "ip",
Port: "port",
IdHash: fmt.Sprintf("%x", md5.Sum([]byte("ep1ipport"))),
}

router.AddEndpoints(suKey, []Endpoint{endpoint})
Expand All @@ -63,7 +65,7 @@ func TestAddEndpoints(t *testing.T) {
t.Errorf("Expected endpoint table to contain 1 entry")
} else {
actualEp := su.EndpointTable[0]
if endpoint.IP != actualEp.IP || endpoint.Port != actualEp.Port {
if endpoint.IP != actualEp.IP || endpoint.Port != actualEp.Port || endpoint.IdHash != actualEp.IdHash {
t.Errorf("Expected endpoint %v did not match actual endpoint %v", endpoint, actualEp)
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/router/template/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Endpoint struct {
Port string
TargetName string
PortName string
IdHash string
}

// certificateManager provides the ability to write certificates for a ServiceAliasConfig
Expand Down