Skip to content

Commit 58aca5b

Browse files
committed
haproxy obfuscated internal IP in routing cookie
The cookie currently returns the openshift internal pod IP address. This is a security issue as an attacker can develop a map of the pods in the cluster just by observing the returned cookie. This change returns a hash of the internal address and internal service name to obfuscate the internal information. The service name is configured when the service is created and is not visible to outside users. This in combination with the internal ip:port is hashed and presented in the cookie. addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1318796
1 parent 0eb3b28 commit 58aca5b

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

images/router/haproxy/conf/haproxy-config.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ backend be_edge_http_{{$cfgIdx}}
214214
{{ end }}
215215
http-request set-header Forwarded for=%[src];host=%[req.hdr(host)];proto=%[req.hdr(X-Forwarded-Proto)]
216216
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
217-
server {{$endpoint.ID}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms cookie {{$endpoint.ID}}
217+
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms cookie {{$endpoint.IdHash}}
218218
{{ end }}
219219
{{ end }}
220220

@@ -236,7 +236,7 @@ backend be_secure_{{$cfgIdx}}
236236
timeout check 5000ms
237237
cookie OPENSHIFT_REENCRYPT_{{$cfgIdx}}_SERVERID insert indirect nocache httponly secure
238238
{{ range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
239-
server {{$endpoint.ID}} {{$endpoint.IP}}:{{$endpoint.Port}} ssl check inter 5000ms verify required ca-file {{ $workingDir }}/cacerts/{{$cfgIdx}}.pem cookie {{$endpoint.ID}}
239+
server {{$endpoint.IdHash}} {{$endpoint.IP}}:{{$endpoint.Port}} ssl check inter 5000ms verify required ca-file {{ $workingDir }}/cacerts/{{$cfgIdx}}.pem cookie {{$endpoint.IdHash}}
240240
{{ end }}
241241
{{ end }}
242242
{{ end }}{{/* $serviceUnit.ServiceAliasConfigs*/}}

pkg/router/template/router.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package templaterouter
22

33
import (
4+
"crypto/md5"
45
"encoding/json"
56
"fmt"
67
"io/ioutil"
@@ -502,6 +503,15 @@ func (r *templateRouter) AddEndpoints(id string, endpoints []Endpoint) bool {
502503
return false
503504
}
504505

506+
// IdHash contains an obfuscated internal IP address that is the value
507+
// passed in the cookie. The IP address is made more difficult to extract
508+
// by including other internal information in the hash.
509+
for i := range endpoints {
510+
endpoint := &endpoints[i]
511+
s := endpoint.ID + endpoint.TargetName + endpoint.PortName
512+
endpoint.IdHash = fmt.Sprintf("%x", md5.Sum([]byte(s)))
513+
}
514+
505515
frontend.EndpointTable = endpoints
506516
r.state[id] = frontend
507517

pkg/router/template/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Endpoint struct {
6262
Port string
6363
TargetName string
6464
PortName string
65+
IdHash string
6566
}
6667

6768
// certificateManager provides the ability to write certificates for a ServiceAliasConfig

0 commit comments

Comments
 (0)