From a86c7cae2bec7b80c395036dc2d67251eb05edf6 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 9 May 2019 21:23:49 +0200 Subject: [PATCH] rpc auth: handle some auth errors gracefully particuarly we will ignore authorization errors for some broadcasts and somply not include those responses in the assembled one. --- api/ipfsproxy/ipfsproxy.go | 4 ++++ cluster.go | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/api/ipfsproxy/ipfsproxy.go b/api/ipfsproxy/ipfsproxy.go index de407843..8c361cdd 100644 --- a/api/ipfsproxy/ipfsproxy.go +++ b/api/ipfsproxy/ipfsproxy.go @@ -624,6 +624,10 @@ func (proxy *Server) repoStatHandler(w http.ResponseWriter, r *http.Request) { for i, err := range errs { if err != nil { + if rpc.IsAuthorizationError(err) { + logger.Debug(err) + continue + } logger.Errorf("%s repo/stat errored: %s", peers[i], err) continue } diff --git a/cluster.go b/cluster.go index 9d0bf0fd..1ffaeb5e 100644 --- a/cluster.go +++ b/cluster.go @@ -1333,12 +1333,21 @@ func (c *Cluster) Peers(ctx context.Context) []*api.ID { rpcutil.CopyIDsToIfaces(peers), ) + finalPeers := []*api.ID{} + for i, err := range errs { - if err != nil { - peers[i] = &api.ID{} - peers[i].ID = members[i] - peers[i].Error = err.Error() + if err == nil { + finalPeers = append(finalPeers, peers[i]) + continue } + + if rpc.IsAuthorizationError(err) { + continue + } + + peers[i] = &api.ID{} + peers[i].ID = members[i] + peers[i].Error = err.Error() } return peers @@ -1382,6 +1391,11 @@ func (c *Cluster) globalPinInfoCid(ctx context.Context, comp, method string, h c continue } + if rpc.IsAuthorizationError(e) { + logger.Debug("rpc auth error:", e) + continue + } + // Deal with error cases (err != nil): wrap errors in PinInfo logger.Errorf("%s: error in broadcast response from %s: %s ", c.id, members[i], e) pin.PeerMap[peer.IDB58Encode(members[i])] = &api.PinInfo{ @@ -1447,6 +1461,10 @@ func (c *Cluster) globalPinInfoSlice(ctx context.Context, comp, method string) ( erroredPeers := make(map[peer.ID]string) for i, r := range replies { if e := errs[i]; e != nil { // This error must come from not being able to contact that cluster member + if rpc.IsAuthorizationError(e) { + logger.Debug("rpc auth error", e) + continue + } logger.Errorf("%s: error in broadcast response from %s: %s ", c.id, members[i], e) erroredPeers[members[i]] = e.Error() } else {