Istio sidecar proxy blocks all requests sent through the reverse proxy to the target service if the request.Host is not properly set to the internal target service host. This PR sets the target service hosts before establishing the proxy for the client in order to pass the Istio sidecar proxy check.
34 lines
679 B
Go
34 lines
679 B
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httputil"
|
|
"net/url"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
func (api *API) WorkflowApiserverProxy(w http.ResponseWriter, r *http.Request) {
|
|
u := api.workflowApiUrl
|
|
ssUrl, err := url.Parse(u)
|
|
if err != nil {
|
|
msg := fmt.Sprintf("Error parsing url %v: %v", u, err)
|
|
http.Error(w, msg, http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
vars := mux.Vars(r)
|
|
path := fmt.Sprintf("/%s", vars["path"])
|
|
director := func(req *http.Request) {
|
|
req.URL.Scheme = ssUrl.Scheme
|
|
req.URL.Host = ssUrl.Host
|
|
req.URL.Path = path
|
|
req.Host = ssUrl.Host
|
|
}
|
|
proxy := &httputil.ReverseProxy{
|
|
Director: director,
|
|
}
|
|
proxy.ServeHTTP(w, r)
|
|
}
|