Skip to content

Commit

Permalink
Merge pull request #5008 from filecoin-project/fix/worker-remote
Browse files Browse the repository at this point in the history
worker: More robust remote checks
  • Loading branch information
magik6k authored Nov 26, 2020
2 parents 42173e2 + 23bf334 commit aa27844
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/lotus-seal-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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{
Expand Down

0 comments on commit aa27844

Please sign in to comment.