From 7e463a4644fc774061305fcacfc82f3722947ce4 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Sat, 3 Nov 2018 10:21:19 +0800 Subject: [PATCH] hack: scheduler ping/version escape auth --- pkg/proxy/http.go | 2 +- pkg/util/gin/middleware/keystone_auth.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/proxy/http.go b/pkg/proxy/http.go index 4b27030e0d..4d23731a0d 100644 --- a/pkg/proxy/http.go +++ b/pkg/proxy/http.go @@ -2,6 +2,7 @@ package proxy import ( "context" + "crypto/tls" "fmt" "net/http" "net/http/httputil" @@ -9,7 +10,6 @@ import ( "yunion.io/x/log" "yunion.io/x/onecloud/pkg/httperrors" - "crypto/tls" ) type EndpointGenerator func(context.Context, http.ResponseWriter, *http.Request) (string, error) diff --git a/pkg/util/gin/middleware/keystone_auth.go b/pkg/util/gin/middleware/keystone_auth.go index 53cf65db9d..39067df06d 100644 --- a/pkg/util/gin/middleware/keystone_auth.go +++ b/pkg/util/gin/middleware/keystone_auth.go @@ -3,6 +3,7 @@ package middleware import ( "fmt" "net/http" + "strings" "gopkg.in/gin-gonic/gin.v1" @@ -15,6 +16,15 @@ const ( func KeystoneTokenVerifyMiddleware() gin.HandlerFunc { return func(c *gin.Context) { + // hack + escapeAuth := []string{"ping", "version", "metrics"} + for _, s := range escapeAuth { + if strings.HasSuffix(c.Request.URL.Path, s) { + c.Next() + return + } + } + token := c.Request.Header.Get(XAuthTokenKey) if len(token) == 0 { c.AbortWithError(http.StatusBadRequest, fmt.Errorf("Not found %s in http header.", XAuthTokenKey))