Skip to content

Commit dc41091

Browse files
committed
[FAB-15157] Gracefully handle TLS absense in config
This change set makes an orderer crash with a user friendly message when trying to start up a cluster orderer (i.e etcdraft) without TLS enabled. Change-Id: If198a9bba1e9a4b1e607fcd0a141e66e70902050 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 1462531 commit dc41091

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

orderer/common/server/etcdraft_test.go

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,36 @@ func TestSpawnEtcdRaft(t *testing.T) {
4545

4646
defer gexec.CleanupBuildArtifacts()
4747

48-
t.Run("EtcdRaft launch failure", func(t *testing.T) {
49-
testEtcdRaftOSNFailure(gt, tempDir, orderer, fabricRootDir)
48+
t.Run("Invalid bootstrap block", func(t *testing.T) {
49+
testEtcdRaftOSNFailureInvalidBootstrapBlock(gt, tempDir, orderer, fabricRootDir)
50+
})
51+
52+
t.Run("No TLS", func(t *testing.T) {
53+
testEtcdRaftOSNNoTLS(gt, tempDir, orderer, fabricRootDir, configtxgen)
5054
})
5155

5256
t.Run("EtcdRaft launch success", func(t *testing.T) {
5357
testEtcdRaftOSNSuccess(gt, tempDir, configtxgen, cwd, orderer, fabricRootDir)
5458
})
5559
}
5660

57-
func testEtcdRaftOSNSuccess(gt *GomegaWithT, tempDir, configtxgen, cwd, orderer, fabricRootDir string) {
61+
func createBootstrapBlock(gt *GomegaWithT, tempDir, configtxgen, cwd string) string {
5862
// Create the genesis block for the system channel
5963
genesisBlockPath := filepath.Join(tempDir, "genesis.block")
6064
cmd := exec.Command(configtxgen, "-channelID", "system", "-profile", "SampleDevModeEtcdRaft",
6165
"-outputBlock", genesisBlockPath)
6266
cmd.Env = append(cmd.Env, fmt.Sprintf("FABRIC_CFG_PATH=%s", filepath.Join(cwd, "testdata")))
6367
configtxgenProcess, err := gexec.Start(cmd, nil, nil)
6468
gt.Expect(err).NotTo(HaveOccurred())
65-
6669
gt.Eventually(configtxgenProcess, time.Minute).Should(gexec.Exit(0))
6770
gt.Expect(configtxgenProcess.Err).To(gbytes.Say("Writing genesis block"))
6871

72+
return genesisBlockPath
73+
}
74+
75+
func testEtcdRaftOSNSuccess(gt *GomegaWithT, tempDir, configtxgen, cwd, orderer, fabricRootDir string) {
76+
genesisBlockPath := createBootstrapBlock(gt, tempDir, configtxgen, cwd)
77+
6978
// Launch the OSN
7079
ordererProcess := launchOrderer(gt, orderer, tempDir, genesisBlockPath, fabricRootDir)
7180
defer ordererProcess.Kill()
@@ -90,7 +99,7 @@ func testEtcdRaftOSNSuccess(gt *GomegaWithT, tempDir, configtxgen, cwd, orderer,
9099
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("becomeLeader"))
91100
}
92101

93-
func testEtcdRaftOSNFailure(gt *GomegaWithT, tempDir, orderer, fabricRootDir string) {
102+
func testEtcdRaftOSNFailureInvalidBootstrapBlock(gt *GomegaWithT, tempDir, orderer, fabricRootDir string) {
94103
// Grab an application channel genesis block
95104
genesisBlockPath := filepath.Join(filepath.Join("testdata", "mychannel.block"))
96105
genesisBlockBytes, err := ioutil.ReadFile(genesisBlockPath)
@@ -109,6 +118,29 @@ func testEtcdRaftOSNFailure(gt *GomegaWithT, tempDir, orderer, fabricRootDir str
109118
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say(expectedErr))
110119
}
111120

121+
func testEtcdRaftOSNNoTLS(gt *GomegaWithT, tempDir, orderer, fabricRootDir string, configtxgen string) {
122+
cwd, err := filepath.Abs(".")
123+
gt.Expect(err).NotTo(HaveOccurred())
124+
125+
genesisBlockPath := createBootstrapBlock(gt, tempDir, configtxgen, cwd)
126+
127+
cmd := exec.Command(orderer)
128+
cmd.Env = []string{
129+
"ORDERER_GENERAL_LISTENPORT=5611",
130+
"ORDERER_GENERAL_GENESISMETHOD=file",
131+
"ORDERER_GENERAL_SYSTEMCHANNEL=system",
132+
fmt.Sprintf("ORDERER_FILELEDGER_LOCATION=%s", filepath.Join(tempDir, "ledger")),
133+
fmt.Sprintf("ORDERER_GENERAL_GENESISFILE=%s", genesisBlockPath),
134+
fmt.Sprintf("FABRIC_CFG_PATH=%s", filepath.Join(fabricRootDir, "sampleconfig")),
135+
}
136+
ordererProcess, err := gexec.Start(cmd, nil, nil)
137+
gt.Expect(err).NotTo(HaveOccurred())
138+
defer ordererProcess.Kill()
139+
140+
expectedErr := "TLS is required for running ordering nodes of type etcdraft."
141+
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say(expectedErr))
142+
}
143+
112144
func launchOrderer(gt *GomegaWithT, orderer, tempDir, genesisBlockPath, fabricRootDir string) *gexec.Session {
113145
cwd, err := filepath.Abs(".")
114146
gt.Expect(err).NotTo(HaveOccurred())

orderer/common/server/main.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func Start(cmd string, conf *localconfig.TopLevel) {
106106
lf, _ := createLedgerFactory(conf)
107107

108108
clusterDialer := &cluster.PredicateDialer{}
109-
clusterClientConfig := initializeClusterClientConfig(conf)
109+
clusterClientConfig := initializeClusterClientConfig(conf, clusterType, bootstrapBlock)
110110
clusterDialer.SetConfig(clusterClientConfig)
111111

112112
r := createReplicator(lf, bootstrapBlock, conf, clusterClientConfig.SecOpts, signer)
@@ -339,7 +339,10 @@ func configureClusterListener(conf *localconfig.TopLevel, generalConf comm.Serve
339339
return serverConf, srv
340340
}
341341

342-
func initializeClusterClientConfig(conf *localconfig.TopLevel) comm.ClientConfig {
342+
func initializeClusterClientConfig(conf *localconfig.TopLevel, clusterType bool, bootstrapBlock *cb.Block) comm.ClientConfig {
343+
if clusterType && !conf.General.TLS.Enabled {
344+
logger.Panicf("TLS is required for running ordering nodes of type %s.", consensusType(bootstrapBlock))
345+
}
343346
cc := comm.ClientConfig{
344347
AsyncConnect: true,
345348
KaOpts: comm.DefaultKeepaliveOptions,
@@ -504,6 +507,11 @@ func initializeBootstrapChannel(genesisBlock *cb.Block, lf blockledger.Factory)
504507
}
505508

506509
func isClusterType(genesisBlock *cb.Block) bool {
510+
_, exists := clusterTypes[consensusType(genesisBlock)]
511+
return exists
512+
}
513+
514+
func consensusType(genesisBlock *cb.Block) string {
507515
if genesisBlock.Data == nil || len(genesisBlock.Data.Data) == 0 {
508516
logger.Fatalf("Empty genesis block")
509517
}
@@ -519,8 +527,7 @@ func isClusterType(genesisBlock *cb.Block) bool {
519527
if !exists {
520528
logger.Fatalf("Orderer config doesn't exist in bundle derived from genesis block")
521529
}
522-
_, exists = clusterTypes[ordConf.ConsensusType()]
523-
return exists
530+
return ordConf.ConsensusType()
524531
}
525532

526533
func initializeGrpcServer(conf *localconfig.TopLevel, serverConfig comm.ServerConfig) *comm.GRPCServer {

orderer/common/server/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func TestInitializeServerConfig(t *testing.T) {
174174
if tc.clusterCert == "" {
175175
initializeServerConfig(conf, nil)
176176
} else {
177-
initializeClusterClientConfig(conf)
177+
initializeClusterClientConfig(conf, false, nil)
178178
}
179179
},
180180
)
@@ -386,7 +386,7 @@ func TestUpdateTrustedRoots(t *testing.T) {
386386
}
387387

388388
predDialer := &cluster.PredicateDialer{}
389-
clusterConf := initializeClusterClientConfig(conf)
389+
clusterConf := initializeClusterClientConfig(conf, true, nil)
390390
predDialer.SetConfig(clusterConf)
391391

392392
callback = func(bundle *channelconfig.Bundle) {

orderer/common/server/util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313

1414
"github.com/hyperledger/fabric/common/ledger/blkstorage/fsblkstorage"
1515
"github.com/hyperledger/fabric/common/ledger/blockledger"
16-
"github.com/hyperledger/fabric/common/ledger/blockledger/file"
17-
"github.com/hyperledger/fabric/common/ledger/blockledger/json"
18-
"github.com/hyperledger/fabric/common/ledger/blockledger/ram"
16+
fileledger "github.com/hyperledger/fabric/common/ledger/blockledger/file"
17+
jsonledger "github.com/hyperledger/fabric/common/ledger/blockledger/json"
18+
ramledger "github.com/hyperledger/fabric/common/ledger/blockledger/ram"
1919
config "github.com/hyperledger/fabric/orderer/common/localconfig"
2020
)
2121

0 commit comments

Comments
 (0)