Merge pull request #8978 from filecoin-project/fix/marketnode-storageauth
fix: Delegate storage auth on market nodes
This commit is contained in:
@@ -44,6 +44,7 @@ import (
|
||||
mktsdagstore "github.com/filecoin-project/lotus/markets/dagstore"
|
||||
"github.com/filecoin-project/lotus/markets/storageadapter"
|
||||
"github.com/filecoin-project/lotus/miner"
|
||||
"github.com/filecoin-project/lotus/node/modules"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/storage"
|
||||
"github.com/filecoin-project/lotus/storage/ctladdr"
|
||||
@@ -97,6 +98,9 @@ type StorageMinerAPI struct {
|
||||
Epp gen.WinningPoStProver `optional:"true"`
|
||||
DS dtypes.MetadataDS
|
||||
|
||||
// StorageService is populated when we're not the main storage node (e.g. we're a markets node)
|
||||
StorageService modules.MinerStorageService `optional:"true"`
|
||||
|
||||
ConsiderOnlineStorageDealsConfigFunc dtypes.ConsiderOnlineStorageDealsConfigFunc `optional:"true"`
|
||||
SetConsiderOnlineStorageDealsConfigFunc dtypes.SetConsiderOnlineStorageDealsConfigFunc `optional:"true"`
|
||||
ConsiderOnlineRetrievalDealsConfigFunc dtypes.ConsiderOnlineRetrievalDealsConfigFunc `optional:"true"`
|
||||
@@ -119,6 +123,14 @@ type StorageMinerAPI struct {
|
||||
|
||||
var _ api.StorageMiner = &StorageMinerAPI{}
|
||||
|
||||
func (sm *StorageMinerAPI) StorageAuthVerify(ctx context.Context, token string) ([]auth.Permission, error) {
|
||||
if sm.StorageService != nil {
|
||||
return sm.StorageService.AuthVerify(ctx, token)
|
||||
}
|
||||
|
||||
return sm.AuthVerify(ctx, token)
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) ServeRemote(perm bool) func(w http.ResponseWriter, r *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if perm == true {
|
||||
|
||||
+34
-14
@@ -124,8 +124,6 @@ func FullNodeHandler(a v1api.FullNode, permissioned bool, opts ...jsonrpc.Server
|
||||
|
||||
// MinerHandler returns a miner handler, to be mounted as-is on the server.
|
||||
func MinerHandler(a api.StorageMiner, permissioned bool) (http.Handler, error) {
|
||||
m := mux.NewRouter()
|
||||
|
||||
mapi := proxy.MetricedStorMinerAPI(a)
|
||||
if permissioned {
|
||||
mapi = api.PermissionedStorMinerAPI(mapi)
|
||||
@@ -136,23 +134,45 @@ func MinerHandler(a api.StorageMiner, permissioned bool) (http.Handler, error) {
|
||||
rpcServer.Register("Filecoin", mapi)
|
||||
rpcServer.AliasMethod("rpc.discover", "Filecoin.Discover")
|
||||
|
||||
m.Handle("/rpc/v0", rpcServer)
|
||||
m.Handle("/rpc/streams/v0/push/{uuid}", readerHandler)
|
||||
m.PathPrefix("/remote").HandlerFunc(a.(*impl.StorageMinerAPI).ServeRemote(permissioned))
|
||||
rootMux := mux.NewRouter()
|
||||
|
||||
// debugging
|
||||
m.Handle("/debug/metrics", metrics.Exporter())
|
||||
m.PathPrefix("/").Handler(http.DefaultServeMux) // pprof
|
||||
// remote storage
|
||||
{
|
||||
m := mux.NewRouter()
|
||||
m.PathPrefix("/remote").HandlerFunc(a.(*impl.StorageMinerAPI).ServeRemote(permissioned))
|
||||
|
||||
if !permissioned {
|
||||
return m, nil
|
||||
var hnd http.Handler = m
|
||||
if permissioned {
|
||||
hnd = &auth.Handler{
|
||||
Verify: a.StorageAuthVerify,
|
||||
Next: m.ServeHTTP,
|
||||
}
|
||||
}
|
||||
|
||||
rootMux.PathPrefix("/remote").Handler(hnd)
|
||||
}
|
||||
|
||||
ah := &auth.Handler{
|
||||
Verify: a.AuthVerify,
|
||||
Next: m.ServeHTTP,
|
||||
// local APIs
|
||||
{
|
||||
m := mux.NewRouter()
|
||||
m.Handle("/rpc/v0", rpcServer)
|
||||
m.Handle("/rpc/streams/v0/push/{uuid}", readerHandler)
|
||||
// debugging
|
||||
m.Handle("/debug/metrics", metrics.Exporter())
|
||||
m.PathPrefix("/").Handler(http.DefaultServeMux) // pprof
|
||||
|
||||
var hnd http.Handler = m
|
||||
if permissioned {
|
||||
hnd = &auth.Handler{
|
||||
Verify: a.AuthVerify,
|
||||
Next: m.ServeHTTP,
|
||||
}
|
||||
}
|
||||
|
||||
rootMux.PathPrefix("/").Handler(hnd)
|
||||
}
|
||||
return ah, nil
|
||||
|
||||
return rootMux, nil
|
||||
}
|
||||
|
||||
func handleImport(a *impl.FullNodeAPI) func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user