Commit 57c0359c authored by Jens Langhammer's avatar Jens Langhammer

tier0: use sha256 for request fingerprinting

parent 3d35b7c5
Pipeline #3880 passed with stage
in 1 minute and 53 seconds
......@@ -10,7 +10,6 @@ require (
github.com/googleapis/gnostic v0.3.0 // indirect
github.com/gorilla/handlers v1.4.0
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/mitchellh/hashstructure v1.0.0
github.com/prometheus/client_golang v1.0.0
github.com/qbig/groupcache v0.0.0-20170504020517-747546dcc5ad
github.com/sirupsen/logrus v1.4.2
......
......@@ -16,6 +16,7 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
......@@ -42,8 +43,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/hashstructure v1.0.0 h1:ZkRJX1CyOoTkar7p/mLS5TZU4nJ1Rn/F8u9dGS02Q3Y=
github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
......
......@@ -13,7 +13,6 @@ import (
"git.beryju.org/BeryJu.org/p2/tier0/pkg/k8s"
"git.beryju.org/BeryJu.org/p2/tier0/pkg/metrics"
"git.beryju.org/BeryJu.org/p2/tier0/pkg/p2"
v1 "k8s.io/api/core/v1"
"github.com/gorilla/handlers"
"github.com/qbig/groupcache"
......@@ -38,11 +37,11 @@ func main() {
stop := make(chan struct{})
upstream := p2.NewGRPCUpstream(fmt.Sprintf("%s:50051", grpcClusterIP))
localCache := cache.NewCache(upstream)
localCache.SetPeersFromKubernetes(k8sc)
// Update Cache Peers by watching k8s
go k8sc.WatchNewCachePods(stop, func(pod v1.Pod) {
localCache.SetPeersFromKubernetes(k8sc)
})
// localCache.SetPeersFromKubernetes(k8sc)
// // Update Cache Peers by watching k8s
// go k8sc.WatchNewCachePods(stop, func(pod v1.Pod) {
// localCache.SetPeersFromKubernetes(k8sc)
// })
go localCache.StartCacheServer()
go localCache.StartMetricsTimer()
go metrics.StartServer()
......
......@@ -6,7 +6,7 @@ import (
"net"
"net/http"
"os"
"strconv"
"reflect"
"strings"
"time"
......@@ -17,7 +17,6 @@ import (
"git.beryju.org/BeryJu.org/p2/tier0/pkg/k8s"
"git.beryju.org/BeryJu.org/p2/tier0/pkg/p2"
"github.com/mitchellh/hashstructure"
"github.com/qbig/groupcache"
log "github.com/sirupsen/logrus"
)
......@@ -87,12 +86,9 @@ func RequestFingerprint(request http.Request) string {
} else {
fingerprintData[1] = ""
}
hash, err := hashstructure.Hash(request.Header, nil)
if err == nil {
fingerprintData[2] = strconv.FormatUint(hash, 10)
} else {
fingerprintData[2] = ""
}
request.Header.Del("If-Modified-Since")
log.Debugf("Fingerprinting request on headers '%s'", reflect.ValueOf(request.Header).MapKeys())
fingerprintData[2] = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprintf("%s", request.Header))))
fullHash := sha256.Sum256([]byte(strings.Join(fingerprintData, "")))
return fmt.Sprintf("%x", fullHash)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment