From 28e04a653fd62c8f031818e0a9567d093e62f728 Mon Sep 17 00:00:00 2001 From: "ruokai.lai" Date: Tue, 7 Mar 2017 11:52:02 +1100 Subject: [PATCH] fix an error produced by analyze-local-images remotely --- contrib/analyze-local-images/main.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/contrib/analyze-local-images/main.go b/contrib/analyze-local-images/main.go index f36526e2..f4c9d9af 100644 --- a/contrib/analyze-local-images/main.go +++ b/contrib/analyze-local-images/main.go @@ -23,7 +23,6 @@ import ( "fmt" "io/ioutil" "log" - "net" "net/http" "os" "os/exec" @@ -173,7 +172,7 @@ func AnalyzeLocalImage(imageName string, minSeverity types.Priority, endpoint, m log.Printf("Setting up HTTP server (allowing: %s)\n", allowedHost) ch := make(chan error) - go listenHTTP(tmpPath, allowedHost, ch) + go listenHTTP(tmpPath, ch) select { case err := <-ch: return fmt.Errorf("An error occured when starting HTTP server: %s", err) @@ -362,20 +361,14 @@ func historyFromCommand(imageName string) ([]string, error) { return layers, nil } -func listenHTTP(path, allowedHost string, ch chan error) { - restrictedFileServer := func(path, allowedHost string) http.Handler { +func listenHTTP(path string, ch chan error) { + restrictedFileServer := func(path string) http.Handler { fc := func(w http.ResponseWriter, r *http.Request) { - host, _, err := net.SplitHostPort(r.RemoteAddr) - if err == nil && strings.EqualFold(host, allowedHost) { - http.FileServer(http.Dir(path)).ServeHTTP(w, r) - return - } - w.WriteHeader(403) + http.FileServer(http.Dir(path)).ServeHTTP(w, r) } return http.HandlerFunc(fc) } - - ch <- http.ListenAndServe(":"+strconv.Itoa(httpPort), restrictedFileServer(path, allowedHost)) + ch <- http.ListenAndServe(":"+strconv.Itoa(httpPort), restrictedFileServer(path)) } func analyzeLayer(endpoint, path, layerName, parentLayerName string) error {