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.
This commit is contained in:
Hector Sanjuan 2019-05-09 21:23:49 +02:00
parent 949e6f2364
commit a86c7cae2b
2 changed files with 26 additions and 4 deletions

View File

@ -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
}

View File

@ -1333,13 +1333,22 @@ func (c *Cluster) Peers(ctx context.Context) []*api.ID {
rpcutil.CopyIDsToIfaces(peers),
)
finalPeers := []*api.ID{}
for i, err := range errs {
if err != nil {
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 {