From 23bf3349d769af941295ec4c2e43f71147ec92a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 25 Nov 2020 17:05:45 +0100 Subject: [PATCH] worker: More robust remote checks --- cmd/lotus-seal-worker/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-seal-worker/main.go b/cmd/lotus-seal-worker/main.go index 1f20bffbd26..b1df138c720 100644 --- a/cmd/lotus-seal-worker/main.go +++ b/cmd/lotus-seal-worker/main.go @@ -362,6 +362,17 @@ var runCmd = &cli.Command{ remote := stores.NewRemote(localStore, nodeApi, sminfo.AuthHeader(), cctx.Int("parallel-fetch-limit")) + fh := &stores.FetchHandler{Local: localStore} + remoteHandler := func(w http.ResponseWriter, r *http.Request) { + if !auth.HasPerm(r.Context(), nil, apistruct.PermAdmin) { + w.WriteHeader(401) + _ = json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing admin permission"}) + return + } + + fh.ServeHTTP(w, r) + } + // Create / expose the worker wsts := statestore.New(namespace.Wrap(ds, modules.WorkerCallsPrefix)) @@ -385,7 +396,7 @@ var runCmd = &cli.Command{ mux.Handle("/rpc/v0", rpcServer) mux.Handle("/rpc/streams/v0/push/{uuid}", readerHandler) - mux.PathPrefix("/remote").HandlerFunc((&stores.FetchHandler{Local: localStore}).ServeHTTP) + mux.PathPrefix("/remote").HandlerFunc(remoteHandler) mux.PathPrefix("/").Handler(http.DefaultServeMux) // pprof ah := &auth.Handler{