mirror of
https://github.com/status-im/consul.git
synced 2025-02-18 08:36:46 +00:00
Merge pull request #15086 from hashicorp/peering/establish-forbidden
This commit is contained in:
commit
d1868bbfd0
@ -21,6 +21,8 @@ import (
|
|||||||
"github.com/hashicorp/go-cleanhttp"
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/acl"
|
"github.com/hashicorp/consul/acl"
|
||||||
"github.com/hashicorp/consul/agent/cache"
|
"github.com/hashicorp/consul/agent/cache"
|
||||||
@ -374,6 +376,9 @@ func (s *HTTPHandlers) wrap(handler endpoint, methods []string) http.HandlerFunc
|
|||||||
if acl.IsErrPermissionDenied(err) || acl.IsErrNotFound(err) {
|
if acl.IsErrPermissionDenied(err) || acl.IsErrNotFound(err) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if e, ok := status.FromError(err); ok && e.Code() == codes.PermissionDenied {
|
||||||
|
return true
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,7 +556,7 @@ func (s *Server) exchangeSecret(ctx context.Context, peering *pbpeering.Peering,
|
|||||||
// If we got a permission denied error that means out establishment secret is invalid, so we do not retry.
|
// If we got a permission denied error that means out establishment secret is invalid, so we do not retry.
|
||||||
grpcErr, ok := grpcstatus.FromError(err)
|
grpcErr, ok := grpcstatus.FromError(err)
|
||||||
if ok && grpcErr.Code() == codes.PermissionDenied {
|
if ok && grpcErr.Code() == codes.PermissionDenied {
|
||||||
return nil, fmt.Errorf("a new peering token must be generated: %w", grpcErr.Err())
|
return nil, grpcstatus.Errorf(codes.PermissionDenied, "a new peering token must be generated: %s", grpcErr.Message())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dialErrors = multierror.Append(dialErrors, fmt.Errorf("failed to exchange peering secret through address %q: %w", addr, err))
|
dialErrors = multierror.Append(dialErrors, fmt.Errorf("failed to exchange peering secret through address %q: %w", addr, err))
|
||||||
|
@ -510,6 +510,9 @@ func TestPeeringService_Establish_ThroughMeshGateway(t *testing.T) {
|
|||||||
PeerName: "my-peer-acceptor",
|
PeerName: "my-peer-acceptor",
|
||||||
PeeringToken: peeringToken,
|
PeeringToken: peeringToken,
|
||||||
})
|
})
|
||||||
|
grpcErr, ok := grpcstatus.FromError(err)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, codes.PermissionDenied, grpcErr.Code())
|
||||||
testutil.RequireErrorContains(t, err, "a new peering token must be generated")
|
testutil.RequireErrorContains(t, err, "a new peering token must be generated")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user