From b4a6bbb633f279578416a116bde6e8ef1c1ac707 Mon Sep 17 00:00:00 2001 From: Noorain Panjwani Date: Mon, 9 Nov 2020 18:51:03 +0530 Subject: [PATCH] Fixed ingress route redirect problem. Fixes #1394 (#1395) --- gateway/Dockerfile | 4 ++-- gateway/modules/global/routing/http.go | 14 ++++++++++---- gateway/modules/global/routing/modify.go | 4 ++-- gateway/utils/constants.go | 2 +- .../kubernetes/local/space-cloud.yaml | 4 ++-- install-manifests/kubernetes/prod/space-cloud.yaml | 4 ++-- runner/model/version.go | 2 +- space-cli/cmd/version.go | 2 +- 8 files changed, 21 insertions(+), 15 deletions(-) diff --git a/gateway/Dockerfile b/gateway/Dockerfile index 2367f548c..e10213e4f 100644 --- a/gateway/Dockerfile +++ b/gateway/Dockerfile @@ -2,7 +2,7 @@ FROM golang:1.13.5-alpine3.10 WORKDIR /build # Take the current space cloud version as a argument -ARG SC_VERSION=0.19.6 +ARG SC_VERSION=0.19.7 # Copy all the source files COPY . . @@ -16,7 +16,7 @@ RUN GOOS=linux CGO_ENABLED=0 go build -a -ldflags '-s -w -extldflags "-static"' RUN echo $SC_VERSION && wget https://storage.googleapis.com/space-cloud/mission-control/mission-control-v$SC_VERSION.zip && unzip mission-control-v$SC_VERSION.zip FROM alpine:3.10 -ARG SC_VERSION=0.19.6 +ARG SC_VERSION=0.19.7 RUN apk --no-cache add ca-certificates diff --git a/gateway/modules/global/routing/http.go b/gateway/modules/global/routing/http.go index 8cee7dd31..47adf01f0 100644 --- a/gateway/modules/global/routing/http.go +++ b/gateway/modules/global/routing/http.go @@ -19,6 +19,12 @@ type modulesInterface interface { Auth() *auth.Module } +var httpClient = http.Client{ + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, +} + // HandleRoutes handles incoming http requests and routes them according to the configured rules. func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc { return func(writer http.ResponseWriter, request *http.Request) { @@ -36,7 +42,7 @@ func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc { return } - token, auth, status, err := r.modifyRequest(request.Context(), modules, route, request) + token, claims, status, err := r.modifyRequest(request.Context(), modules, route, request) if err != nil { writer.WriteHeader(status) _ = json.NewEncoder(writer).Encode(map[string]string{"error": err.Error()}) @@ -59,7 +65,7 @@ func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc { } // TODO: Use http2 client if that was the incoming request protocol - response, err := http.DefaultClient.Do(request) + response, err := httpClient.Do(request) if err != nil { writer.WriteHeader(http.StatusInternalServerError) _ = json.NewEncoder(writer).Encode(map[string]string{"error": err.Error()}) @@ -68,7 +74,7 @@ func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc { } defer utils.CloseTheCloser(response.Body) - if err := r.modifyResponse(request.Context(), response, route, token, auth); err != nil { + if err := r.modifyResponse(request.Context(), response, route, token, claims); err != nil { writer.WriteHeader(http.StatusInternalServerError) _ = json.NewEncoder(writer).Encode(map[string]string{"error": err.Error()}) return @@ -128,7 +134,7 @@ func setRequest(ctx context.Context, request *http.Request, route *config.Route, return nil } -func prepareHeaders(ctx context.Context, headers config.Headers, state map[string]interface{}) config.Headers { +func prepareHeaders(headers config.Headers, state map[string]interface{}) config.Headers { out := make([]config.Header, len(headers)) for i, header := range headers { // First create a new header object diff --git a/gateway/modules/global/routing/modify.go b/gateway/modules/global/routing/modify.go index 5afa50819..82b72490d 100644 --- a/gateway/modules/global/routing/modify.go +++ b/gateway/modules/global/routing/modify.go @@ -46,7 +46,7 @@ func (r *Routing) modifyRequest(ctx context.Context, modules modulesInterface, r // Set the headers state := map[string]interface{}{"args": params, "auth": auth} headers := append(r.globalConfig.RequestHeaders, route.Modify.RequestHeaders...) - prepareHeaders(ctx, headers, state).UpdateHeader(req.Header) + prepareHeaders(headers, state).UpdateHeader(req.Header) // Don't forget to reset the body if params != nil { @@ -87,7 +87,7 @@ func (r *Routing) modifyResponse(ctx context.Context, res *http.Response, route // Set the headers state := map[string]interface{}{"args": params, "auth": auth} headers := append(r.globalConfig.ResponseHeaders, route.Modify.ResponseHeaders...) - prepareHeaders(ctx, headers, state).UpdateHeader(res.Header) + prepareHeaders(headers, state).UpdateHeader(res.Header) // If params is not nil we need to template the response if params != nil { diff --git a/gateway/utils/constants.go b/gateway/utils/constants.go index 0049c2199..4c76a7064 100644 --- a/gateway/utils/constants.go +++ b/gateway/utils/constants.go @@ -5,7 +5,7 @@ import ( ) // BuildVersion is the current version of Space Cloud -const BuildVersion = "0.19.6" +const BuildVersion = "0.19.7" // DLQEventTriggerPrefix used as suffix for DLQ event trigger const DLQEventTriggerPrefix = "dlq_" diff --git a/install-manifests/kubernetes/local/space-cloud.yaml b/install-manifests/kubernetes/local/space-cloud.yaml index 9f2871b88..080b23663 100644 --- a/install-manifests/kubernetes/local/space-cloud.yaml +++ b/install-manifests/kubernetes/local/space-cloud.yaml @@ -200,7 +200,7 @@ spec: containers: - name: runner command: ["./app", "start"] - image: spaceuptech/runner:0.19.6 + image: spaceuptech/runner:0.19.7 imagePullPolicy: IfNotPresent # IfNotPresent | Always env: - name: "LOG_LEVEL" @@ -368,7 +368,7 @@ spec: containers: - name: gateway command: ["./app", "run"] - image: spaceuptech/gateway:0.19.6 + image: spaceuptech/gateway:0.19.7 imagePullPolicy: IfNotPresent # IfNotPresent | Always env: - name: "NODE_ID" diff --git a/install-manifests/kubernetes/prod/space-cloud.yaml b/install-manifests/kubernetes/prod/space-cloud.yaml index 71ffb13d1..701f2912e 100644 --- a/install-manifests/kubernetes/prod/space-cloud.yaml +++ b/install-manifests/kubernetes/prod/space-cloud.yaml @@ -200,7 +200,7 @@ spec: containers: - name: runner command: ["./app", "start"] - image: spaceuptech/runner:0.19.6 + image: spaceuptech/runner:0.19.7 imagePullPolicy: IfNotPresent # IfNotPresent | Always env: - name: "LOG_LEVEL" @@ -372,7 +372,7 @@ spec: containers: - name: gateway command: ["./app", "run"] - image: spaceuptech/gateway:0.19.6 + image: spaceuptech/gateway:0.19.7 imagePullPolicy: IfNotPresent # IfNotPresent | Always env: - name: "NODE_ID" diff --git a/runner/model/version.go b/runner/model/version.go index a587d26cf..53ae703f6 100644 --- a/runner/model/version.go +++ b/runner/model/version.go @@ -1,4 +1,4 @@ package model // Version represents the current runner version -const Version string = "v0.19.6" +const Version string = "v0.19.7" diff --git a/space-cli/cmd/version.go b/space-cli/cmd/version.go index e21857e49..810dcc897 100644 --- a/space-cli/cmd/version.go +++ b/space-cli/cmd/version.go @@ -1,3 +1,3 @@ package cmd -const version string = "0.19.6" +const version string = "0.19.7"