Skip to content

Commit e5cac85

Browse files
committed
[FAB-4166]: Remove a func of stoping peer remotely
This commit takes care to remove peer admin API which allowed to send remote stop command. Since no ACL in place to ensure only authorized and permitted entities sends stop command to the peer, it should be disabled preventing adversaries attacks. Change-Id: I699c6ae1cdf43f294db5a06f13a0271168ff58cf Signed-off-by: Artem Barger <[email protected]>
1 parent 89f1da4 commit e5cac85

File tree

6 files changed

+31
-221
lines changed

6 files changed

+31
-221
lines changed

core/admin.go

+1-20
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,14 @@ limitations under the License.
1717
package core
1818

1919
import (
20-
"os"
21-
22-
"golang.org/x/net/context"
23-
2420
"github.com/golang/protobuf/ptypes/empty"
2521
"github.com/hyperledger/fabric/common/flogging"
26-
"github.com/hyperledger/fabric/core/config"
2722
pb "github.com/hyperledger/fabric/protos/peer"
23+
"golang.org/x/net/context"
2824
)
2925

3026
var log = flogging.MustGetLogger("server")
3127

32-
// Here for unit testing purposes
33-
var osExit = os.Exit
34-
3528
// NewAdminServer creates and returns a Admin service instance.
3629
func NewAdminServer() *ServerAdmin {
3730
s := new(ServerAdmin)
@@ -56,18 +49,6 @@ func (*ServerAdmin) StartServer(context.Context, *empty.Empty) (*pb.ServerStatus
5649
return status, nil
5750
}
5851

59-
// StopServer stops the server
60-
func (*ServerAdmin) StopServer(context.Context, *empty.Empty) (*pb.ServerStatus, error) {
61-
status := &pb.ServerStatus{Status: pb.ServerStatus_STOPPED}
62-
log.Debugf("returning status: %s", status)
63-
64-
pidFile := config.GetPath("peer.fileSystemPath") + "/peer.pid"
65-
log.Debugf("Remove pid file %s", pidFile)
66-
os.Remove(pidFile)
67-
defer osExit(1)
68-
return status, nil
69-
}
70-
7152
// GetModuleLogLevel gets the current logging level for the specified module
7253
// TODO Modify the signature so as to remove the error return - it's always been nil
7354
func (*ServerAdmin) GetModuleLogLevel(ctx context.Context, request *pb.LogLevelRequest) (*pb.LogLevelResponse, error) {

core/admin_test.go

-18
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,6 @@ func TestStartServer(t *testing.T) {
4646
assert.Nil(t, err, "Error should have been nil")
4747
}
4848

49-
func TestStopServer(t *testing.T) {
50-
oldOsExit := osExit
51-
52-
defer func() { osExit = oldOsExit }()
53-
54-
var got int
55-
myExit := func(code int) {
56-
got = code
57-
}
58-
59-
osExit = myExit
60-
response, err := adminServer.StopServer(context.Background(), &empty.Empty{})
61-
assert.NotNil(t, response, "Response should have been set")
62-
assert.Nil(t, err, "Error should have been nil")
63-
64-
assert.Equal(t, 1, got, "Exit code should be 1")
65-
}
66-
6749
func TestLoggingCalls(t *testing.T) {
6850
flogging.MustGetLogger("test")
6951
flogging.SetPeerStartupModulesMap()

peer/node/node.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@ import (
2525

2626
const (
2727
nodeFuncName = "node"
28-
shortDes = "Operate a peer node: start|stop|status."
29-
longDes = "Operate a peer node: start|stop|status."
28+
shortDes = "Operate a peer node: start|status."
29+
longDes = "Operate a peer node: start|status."
3030
)
3131

32-
var (
33-
stopPidFile string
34-
)
3532
var logger = flogging.MustGetLogger("nodeCmd")
3633

3734
// Cmd returns the cobra command for Node
3835
func Cmd() *cobra.Command {
3936
nodeCmd.AddCommand(startCmd())
4037
nodeCmd.AddCommand(statusCmd())
41-
nodeCmd.AddCommand(stopCmd())
4238

4339
return nodeCmd
4440
}

peer/node/stop.go

-115
This file was deleted.

protos/peer/admin.pb.go

+28-61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/peer/admin.proto

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ service Admin {
2929
// Return the serve status.
3030
rpc GetStatus(google.protobuf.Empty) returns (ServerStatus) {}
3131
rpc StartServer(google.protobuf.Empty) returns (ServerStatus) {}
32-
rpc StopServer(google.protobuf.Empty) returns (ServerStatus) {}
3332
rpc GetModuleLogLevel(LogLevelRequest) returns (LogLevelResponse) {}
3433
rpc SetModuleLogLevel(LogLevelRequest) returns (LogLevelResponse) {}
3534
rpc RevertLogLevels(google.protobuf.Empty) returns (google.protobuf.Empty) {}

0 commit comments

Comments
 (0)