Skip to content

Commit 2003b89

Browse files
committed
feat: implement TLS and mTLS support for server and client
- Added TLS and mTLS configuration for both server and client - Implemented secure communication unit tests - Fixed linter issues and test configurations - Updated Docker ENV and YAML configurations - Refactored ServerConfig references to ClientConfig Signed-off-by: Dean Amar <Dean.Amar@ibm.com>
1 parent a4e7b77 commit 2003b89

43 files changed

Lines changed: 1028 additions & 228 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/config/app_config_test.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestReadConfigSidecar(t *testing.T) {
4949
ChannelID: "mychannel",
5050
},
5151
Committer: sidecar.CoordinatorConfig{
52-
Endpoint: *makeEndpoint("localhost", 9001),
52+
Config: makeClientConfig("localhost", 9001),
5353
},
5454
Ledger: sidecar.LedgerConfig{
5555
Path: "./ledger/",
@@ -84,7 +84,7 @@ func TestReadConfigSidecar(t *testing.T) {
8484
ChannelID: "mychannel",
8585
},
8686
Committer: sidecar.CoordinatorConfig{
87-
Endpoint: *makeEndpoint("coordinator", 9001),
87+
Config: makeClientConfig("coordinator", 9001),
8888
},
8989
Ledger: sidecar.LedgerConfig{
9090
Path: "/root/sc/ledger",
@@ -128,14 +128,10 @@ func TestReadConfigCoordinator(t *testing.T) {
128128
name: "sample",
129129
configFilePath: "samples/coordinator.yaml",
130130
expectedConfig: &coordinator.Config{
131-
Server: makeServer("", 9001),
132-
Monitoring: makeMonitoring("", 2119),
133-
VerifierConfig: connection.ClientConfig{
134-
Endpoints: []*connection.Endpoint{makeEndpoint("signature-verifier", 5001)},
135-
},
136-
ValidatorCommitterConfig: connection.ClientConfig{
137-
Endpoints: []*connection.Endpoint{makeEndpoint("validator-persister", 6001)},
138-
},
131+
Server: makeServer("", 9001),
132+
Monitoring: makeMonitoring("", 2119),
133+
VerifierConfig: *makeClientConfig("signature-verifier", 5001),
134+
ValidatorCommitterConfig: *makeClientConfig("validator-persister", 6001),
139135
DependencyGraphConfig: &coordinator.DependencyGraphConfig{
140136
NumOfLocalDepConstructors: 1,
141137
WaitingTxsLimit: 10_000,
@@ -334,7 +330,7 @@ func TestReadConfigLoadGen(t *testing.T) {
334330
},
335331
Adapter: adapters.AdapterConfig{
336332
OrdererClient: &adapters.OrdererClientConfig{
337-
SidecarEndpoint: makeEndpoint("sidecar", 4001),
333+
SidecarConfig: makeClientConfig("sidecar", 4001),
338334
Orderer: broadcastdeliver.Config{
339335
Connection: broadcastdeliver.ConnectionConfig{
340336
Endpoints: connection.NewOrdererEndpoints(
@@ -438,10 +434,11 @@ func defaultSampleDBConfig() *vc.DatabaseConfig {
438434
}
439435
}
440436

441-
func makeEndpoint(host string, port int) *connection.Endpoint {
442-
return &connection.Endpoint{
443-
Host: host,
444-
Port: port,
437+
func makeClientConfig(host string, port int) *connection.ClientConfig {
438+
return &connection.ClientConfig{
439+
Endpoints: []*connection.Endpoint{
440+
makeEndpoint(host, port),
441+
},
445442
}
446443
}
447444

@@ -451,6 +448,13 @@ func makeServer(host string, port int) *connection.ServerConfig {
451448
}
452449
}
453450

451+
func makeEndpoint(host string, port int) *connection.Endpoint {
452+
return &connection.Endpoint{
453+
Host: host,
454+
Port: port,
455+
}
456+
}
457+
454458
func makeMonitoring(host string, port int) monitoring.Config {
455459
return monitoring.Config{Server: makeServer(host, port)}
456460
}

cmd/config/create_config_file.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ type (
3434
// Instance endpoints.
3535
ServiceEndpoints ServiceEndpoints
3636

37+
// Service Tls options and certificates.
38+
ServiceTLS connection.ConfigTLS
39+
3740
// System's resources.
3841
Endpoints SystemEndpoints
3942
DB DatabaseConfig
4043

4144
// Per service configurations.
45+
ClientsCreds ClientsTLSConfig // coordinator, sidecar
4246
BlockSize uint64 // orderer, loadgen
4347
BlockTimeout time.Duration // orderer
4448
ConfigBlockPath string // orderer, sidecar, loadgen
@@ -75,6 +79,15 @@ type (
7579
Endpoints []*connection.Endpoint
7680
}
7781

82+
// ClientsTLSConfig contains the client's config TLS.
83+
ClientsTLSConfig struct {
84+
Vc connection.ConfigTLS
85+
Verifier connection.ConfigTLS
86+
Coordinator connection.ConfigTLS
87+
Sidecar connection.ConfigTLS
88+
Query connection.ConfigTLS
89+
}
90+
7891
// ConfigBlock represents the configuration of the config block.
7992
ConfigBlock = workload.ConfigBlock //nolint:revive
8093
)

cmd/config/samples/loadgen.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ monitoring:
1616
bucket-count: 1000
1717

1818
orderer-client:
19-
sidecar-endpoint: sidecar:4001
19+
sidecar-client-config:
20+
endpoints:
21+
- sidecar:4001
2022
orderer:
2123
connection:
2224
endpoints:

cmd/config/samples/sidecar.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ orderer:
3131
# Security: 256
3232
# Hash: SHA2
3333
committer:
34-
endpoint: coordinator:9001
34+
client:
35+
endpoints:
36+
- coordinator:9001
3537
ledger:
3638
path: /root/sc/ledger
3739

cmd/config/templates/coordinator.yaml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
#
55
server:
66
endpoint: {{ .ServiceEndpoints.Server | default "localhost:0" }}
7+
server-creds:
8+
tls-mode: {{ .ServiceTLS.Mode }}
9+
server-name: {{ .ServiceTLS.ServerName }}
10+
cert-path: {{ .ServiceTLS.CertPath }}
11+
key-path: {{ .ServiceTLS.KeyPath }}
12+
ca-cert-paths:
13+
{{- range .ServiceTLS.CACertPaths }}
14+
- {{ . }}
15+
{{- end }}
16+
717
monitoring:
818
server:
919
endpoint: {{ .ServiceEndpoints.Metrics | default "localhost:0" }}
@@ -13,11 +23,30 @@ verifier:
1323
{{- range .Endpoints.Verifier }}
1424
- {{ .Server }}
1525
{{- end }}
26+
client-creds:
27+
tls-mode: {{ .ClientsCreds.Verifier.Mode }}
28+
server-name: {{ .ClientsCreds.Verifier.ServerName }}
29+
key-path: {{ .ClientsCreds.Verifier.KeyPath }}
30+
cert-path: {{ .ClientsCreds.Verifier.CertPath }}
31+
ca-cert-paths:
32+
{{- range .ClientsCreds.Verifier.CACertPaths }}
33+
- {{ . }}
34+
{{- end }}
35+
1636
validator-committer:
1737
endpoints:
18-
{{- range .Endpoints.VCService }}
38+
{{- range .Endpoints.VCService }}
1939
- {{ .Server }}
20-
{{- end }}
40+
{{- end }}
41+
client-creds:
42+
tls-mode: {{ .ClientsCreds.Vc.Mode }}
43+
server-name: {{ .ClientsCreds.Vc.ServerName }}
44+
key-path: {{ .ClientsCreds.Vc.KeyPath }}
45+
cert-path: {{ .ClientsCreds.Vc.CertPath }}
46+
ca-cert-paths:
47+
{{- range .ClientsCreds.Vc.CACertPaths }}
48+
- {{ . }}
49+
{{- end }}
2150

2251
dependency-graph:
2352
num-of-local-dep-constructors: 1

cmd/config/templates/loadgen_client_orderer.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@
66
# It should be complimented by the common load generator configuration.
77

88
orderer-client:
9-
sidecar-endpoint: {{ .Endpoints.Sidecar.Server }}
9+
sidecar-client-config:
10+
endpoints:
11+
- {{ .Endpoints.Sidecar.Server }}
12+
client-creds:
13+
tls-mode: {{ .ClientsCreds.Sidecar.Mode }}
14+
server-name: {{ .ClientsCreds.Sidecar.ServerName }}
15+
cert-path: {{ .ClientsCreds.Sidecar.CertPath }}
16+
key-path: {{ .ClientsCreds.Sidecar.KeyPath }}
17+
ca-cert-paths:
18+
{{- range .ClientsCreds.Sidecar.CACertPaths }}
19+
- {{ . }}
20+
{{- end }}
1021
orderer:
1122
connection:
1223
endpoints:

cmd/config/templates/loadgen_client_sidecar.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@
66
# It should be complimented by the common load generator configuration.
77

88
sidecar-client:
9-
sidecar-endpoint: {{ .Endpoints.Sidecar.Server }}
9+
sidecar-client-config:
10+
endpoints:
11+
- {{ .Endpoints.Sidecar.Server }}
12+
client-creds:
13+
tls-mode: {{ .ClientsCreds.Sidecar.Mode }}
14+
server-name: {{ .ClientsCreds.Sidecar.ServerName }}
15+
cert-path: {{ .ClientsCreds.Sidecar.CertPath }}
16+
key-path: {{ .ClientsCreds.Sidecar.KeyPath }}
17+
ca-cert-paths:
18+
{{- range .ClientsCreds.Sidecar.CACertPaths }}
19+
- {{ . }}
20+
{{- end }}
1021
orderer-servers:
1122
{{- range .Endpoints.Orderer }}
1223
- endpoint: {{ .Server }}

cmd/config/templates/queryexecutor.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
# Configuration for the server
66
server:
77
endpoint: {{ .ServiceEndpoints.Server | default "localhost:0" }}
8+
server-creds:
9+
tls-mode: {{ .ServiceTLS.Mode }}
10+
server-name: {{ .ServiceTLS.ServerName }}
11+
cert-path: {{ .ServiceTLS.CertPath }}
12+
key-path: {{ .ServiceTLS.KeyPath }}
13+
ca-cert-paths:
14+
{{- range .ServiceTLS.CACertPaths }}
15+
- {{ . }}
16+
{{- end }}
817
monitoring:
918
server:
1019
endpoint: {{ .ServiceEndpoints.Metrics | default "localhost:0" }}

cmd/config/templates/sidecar.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
#
55
server:
66
endpoint: {{ .ServiceEndpoints.Server | default "localhost:0" }}
7+
server-creds:
8+
tls-mode: {{ .ServiceTLS.Mode }}
9+
server-name: {{ .ServiceTLS.ServerName }}
10+
cert-path: {{ .ServiceTLS.CertPath }}
11+
key-path: {{ .ServiceTLS.KeyPath }}
12+
ca-cert-paths:
13+
{{- range .ServiceTLS.CACertPaths }}
14+
- {{ . }}
15+
{{- end }}
716
keep-alive:
817
params:
918
time: 300s
@@ -24,7 +33,18 @@ orderer:
2433
channel-id: {{ .ChannelID }}
2534
consensus-type: BFT
2635
committer:
27-
endpoint: {{ .Endpoints.Coordinator.Server }}
36+
client:
37+
endpoints:
38+
- {{ .Endpoints.Coordinator.Server }}
39+
client-creds:
40+
tls-mode: {{ .ClientsCreds.Coordinator.Mode }}
41+
server-name: {{ .ClientsCreds.Coordinator.ServerName }}
42+
cert-path: {{ .ClientsCreds.Coordinator.CertPath }}
43+
key-path: {{ .ClientsCreds.Coordinator.KeyPath }}
44+
ca-cert-paths:
45+
{{- range .ClientsCreds.Coordinator.CACertPaths }}
46+
- {{ . }}
47+
{{- end }}
2848

2949
ledger:
3050
path: {{ .LedgerPath }}

cmd/config/templates/signatureverifier.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
#
55
server:
66
endpoint: {{ .ServiceEndpoints.Server | default "localhost:0" }}
7+
server-creds:
8+
tls-mode: {{ .ServiceTLS.Mode }}
9+
server-name: {{ .ServiceTLS.ServerName }}
10+
cert-path: {{ .ServiceTLS.CertPath }}
11+
key-path: {{ .ServiceTLS.KeyPath }}
12+
ca-cert-paths:
13+
{{- range .ServiceTLS.CACertPaths }}
14+
- {{ . }}
15+
{{- end }}
16+
717
monitoring:
818
server:
919
endpoint: {{ .ServiceEndpoints.Metrics | default "localhost:0" }}

0 commit comments

Comments
 (0)