Skip to content

Commit 41c8f12

Browse files
yacovmmastersingh24
authored andcommitted
[FAB-11864] Add orderer client TLS cert
Change-Id: Ibed9be1aa0bdf7b5a6606691a841a87f505ab48c Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent cb59297 commit 41c8f12

File tree

4 files changed

+110
-27
lines changed

4 files changed

+110
-27
lines changed

orderer/common/localconfig/config.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type General struct {
4242
ListenAddress string
4343
ListenPort uint16
4444
TLS TLS
45+
Cluster Cluster
4546
Keepalive Keepalive
4647
GenesisMethod string
4748
GenesisProfile string
@@ -56,6 +57,13 @@ type General struct {
5657
Authentication Authentication
5758
}
5859

60+
type Cluster struct {
61+
RootCAs []string
62+
ClientCertificate string
63+
ClientPrivateKey string
64+
DialTimeout time.Duration
65+
}
66+
5967
// Keepalive contains configuration for gRPC servers.
6068
type Keepalive struct {
6169
ServerMinInterval time.Duration
@@ -260,7 +268,11 @@ func Load() (*TopLevel, error) {
260268

261269
func (c *TopLevel) completeInitialization(configDir string) {
262270
defer func() {
263-
// Translate any paths
271+
// Translate any paths for cluster TLS configuration if applicable
272+
coreconfig.TranslatePathInPlace(configDir, &c.General.Cluster.ClientPrivateKey)
273+
coreconfig.TranslatePathInPlace(configDir, &c.General.Cluster.ClientCertificate)
274+
c.General.Cluster.RootCAs = translateCAs(configDir, c.General.Cluster.RootCAs)
275+
// Translate any paths for general TLS configuration
264276
c.General.TLS.RootCAs = translateCAs(configDir, c.General.TLS.RootCAs)
265277
c.General.TLS.ClientRootCAs = translateCAs(configDir, c.General.TLS.ClientRootCAs)
266278
coreconfig.TranslatePathInPlace(configDir, &c.General.TLS.PrivateKey)

orderer/common/server/main.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,49 @@ func initializeProfilingService(conf *localconfig.TopLevel) {
132132
}
133133
}
134134

135+
func initializeClusterConfig(conf *localconfig.TopLevel) comm.ClientConfig {
136+
cc := comm.ClientConfig{
137+
KaOpts: comm.DefaultKeepaliveOptions,
138+
Timeout: conf.General.Cluster.DialTimeout,
139+
}
140+
141+
if (!conf.General.TLS.Enabled) || conf.General.Cluster.ClientCertificate == "" {
142+
return cc
143+
}
144+
145+
certFile := conf.General.Cluster.ClientCertificate
146+
certBytes, err := ioutil.ReadFile(certFile)
147+
if err != nil {
148+
logger.Fatalf("Failed to load client TLS certificate file '%s' (%s)", certFile, err)
149+
}
150+
151+
keyFile := conf.General.Cluster.ClientPrivateKey
152+
keyBytes, err := ioutil.ReadFile(keyFile)
153+
if err != nil {
154+
logger.Fatalf("Failed to load client TLS key file '%s' (%s)", keyFile, err)
155+
}
156+
157+
var serverRootCAs [][]byte
158+
for _, serverRoot := range conf.General.Cluster.RootCAs {
159+
rootCACert, err := ioutil.ReadFile(serverRoot)
160+
if err != nil {
161+
logger.Fatalf("Failed to load ServerRootCAs file '%s' (%s)",
162+
err, serverRoot)
163+
}
164+
serverRootCAs = append(serverRootCAs, rootCACert)
165+
}
166+
167+
cc.SecOpts = &comm.SecureOptions{
168+
CipherSuites: comm.DefaultTLSCipherSuites,
169+
ServerRootCAs: serverRootCAs,
170+
Certificate: certBytes,
171+
Key: keyBytes,
172+
UseTLS: true,
173+
}
174+
175+
return cc
176+
}
177+
135178
func initializeServerConfig(conf *localconfig.TopLevel) comm.ServerConfig {
136179
// secure server config
137180
secureOpts := &comm.SecureOptions{
@@ -174,7 +217,6 @@ func initializeServerConfig(conf *localconfig.TopLevel) comm.ServerConfig {
174217
}
175218
secureOpts.Key = serverKey
176219
secureOpts.Certificate = serverCertificate
177-
secureOpts.ServerRootCAs = serverRootCAs
178220
secureOpts.ClientRootCAs = clientRootCAs
179221
logger.Infof("Starting orderer with %s enabled", msg)
180222
}

orderer/common/server/main_test.go

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,34 +103,48 @@ func TestInitializeServerConfig(t *testing.T) {
103103
logger, _ = floggingtest.NewTestLogger(t)
104104

105105
testCases := []struct {
106-
name string
107-
certificate string
108-
privateKey string
109-
rootCA string
110-
clientCertificate string
106+
name string
107+
certificate string
108+
privateKey string
109+
rootCA string
110+
clientRootCert string
111+
clusterCert string
112+
clusterKey string
113+
clusterCA string
111114
}{
112-
{"BadCertificate", badFile, goodFile, goodFile, goodFile},
113-
{"BadPrivateKey", goodFile, badFile, goodFile, goodFile},
114-
{"BadRootCA", goodFile, goodFile, badFile, goodFile},
115-
{"BadClientCertificate", goodFile, goodFile, goodFile, badFile},
115+
{"BadCertificate", badFile, goodFile, goodFile, goodFile, "", "", ""},
116+
{"BadPrivateKey", goodFile, badFile, goodFile, goodFile, "", "", ""},
117+
{"BadRootCA", goodFile, goodFile, badFile, goodFile, "", "", ""},
118+
{"BadClientRootCertificate", goodFile, goodFile, goodFile, badFile, "", "", ""},
119+
{"ClusterBadCertificate", goodFile, goodFile, goodFile, goodFile, badFile, goodFile, goodFile},
120+
{"ClusterBadPrivateKey", goodFile, goodFile, goodFile, goodFile, goodFile, badFile, goodFile},
121+
{"ClusterBadRootCA", goodFile, goodFile, goodFile, goodFile, goodFile, goodFile, badFile},
116122
}
117123
for _, tc := range testCases {
118124
t.Run(tc.name, func(t *testing.T) {
119-
assert.Panics(t, func() {
120-
initializeServerConfig(
121-
&localconfig.TopLevel{
122-
General: localconfig.General{
123-
TLS: localconfig.TLS{
124-
Enabled: true,
125-
ClientAuthRequired: true,
126-
Certificate: tc.certificate,
127-
PrivateKey: tc.privateKey,
128-
RootCAs: []string{tc.rootCA},
129-
ClientRootCAs: []string{tc.clientCertificate},
130-
},
131-
},
125+
conf := &localconfig.TopLevel{
126+
General: localconfig.General{
127+
TLS: localconfig.TLS{
128+
Enabled: true,
129+
ClientAuthRequired: true,
130+
Certificate: tc.certificate,
131+
PrivateKey: tc.privateKey,
132+
RootCAs: []string{tc.rootCA},
133+
ClientRootCAs: []string{tc.clientRootCert},
132134
},
133-
)
135+
Cluster: localconfig.Cluster{
136+
ClientCertificate: tc.clusterCert,
137+
ClientPrivateKey: tc.clusterKey,
138+
RootCAs: []string{tc.clusterCA},
139+
},
140+
},
141+
}
142+
assert.Panics(t, func() {
143+
if tc.clusterCert == "" {
144+
initializeServerConfig(conf)
145+
} else {
146+
initializeClusterConfig(conf)
147+
}
134148
},
135149
)
136150
})

sampleconfig/orderer.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ General:
3030
# TLS: TLS settings for the GRPC server.
3131
TLS:
3232
Enabled: false
33+
# PrivateKey governs the file location of the private key of the TLS certificate.
3334
PrivateKey: tls/server.key
35+
# Certificate governs the file location of the server TLS certificate.
3436
Certificate: tls/server.crt
3537
RootCAs:
3638
- tls/ca.crt
3739
ClientAuthRequired: false
3840
ClientRootCAs:
39-
4041
# Keepalive settings for the GRPC server.
4142
Keepalive:
4243
# ServerMinInterval is the minimum permitted time between client pings.
@@ -48,7 +49,21 @@ General:
4849
# ServerTimeout is the duration the server waits for a response from
4950
# a client before closing the connection.
5051
ServerTimeout: 20s
51-
52+
# Cluster settings for ordering service nodes that communicate with other ordering service nodes
53+
# such as Raft based ordering service.
54+
Cluster:
55+
# ClientCertificate governs the file location of the client TLS certificate
56+
# used to establish mutual TLS connections with other ordering service nodes.
57+
ClientCertificate:
58+
# ClientPrivateKey governs the file location of the private key of the client TLS certificate.
59+
ClientPrivateKey:
60+
# DialTimeout governs the maximum duration of time after which connection
61+
# attempts are considered as failed.
62+
DialTimeout: 5s
63+
# RootCAs governs the file locations of certificates of the Certificate Authorities
64+
# which authorize connections to remote ordering service nodes.
65+
RootCAs:
66+
- tls/ca.crt
5267
# Log Level: The level at which to log. This accepts logging specifications
5368
# per: fabric/docs/Setup/logging-control.md
5469
LogLevel: info

0 commit comments

Comments
 (0)