Skip to content

Commit 633cb16

Browse files
Enable TLS for committer all-in-one container in fabric-x integration tests
Signed-off-by: Shashank <yshashank959@gmail.com>
1 parent 8d6fccb commit 633cb16

4 files changed

Lines changed: 46 additions & 9 deletions

File tree

integration/nwo/fabricx/extensions/scv2/container.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"context"
1111
"fmt"
1212
"io"
13+
"path/filepath"
1314
"runtime"
1415
"time"
1516

@@ -34,7 +35,7 @@ var (
3435
scalableCommitterImages = map[string]string{
3536
v3.CommitterVersion: v3.ScalableCommitterImage,
3637
}
37-
envVars = map[string]func(peerMSPDir, scMSPID, channelName, ordererEndpoint string) []string{
38+
envVars = map[string]func(peerMSPDir, peerTLSDir, scMSPID, channelName, ordererEndpoint string, tlsEnabled bool, ordererTLSCACert string) []string{
3839
v3.CommitterVersion: v3.ContainerEnvVars,
3940
}
4041
containerCmds = map[string][]string{
@@ -96,7 +97,10 @@ func (e *Extension) launchContainer() {
9697
extraHosts = append(extraHosts, "host.docker.internal:host-gateway")
9798
}
9899

99-
containerEnvOverride := envVars[committerVersion](peerMSPDir, scMSPID, e.channel.Name, ordererEndpoint)
100+
peerTLSDir := peerDockerTLSDir(e.network, scPeer)
101+
ordererTLSCACert := filepath.Join("/", "root", "artifacts", "crypto", "ordererOrganizations", e.network.OrdererOrgs()[0].Domain, "orderers", fmt.Sprintf("%s.%s", e.network.Orderers[0].Name, e.network.OrdererOrgs()[0].Domain), "tls", "ca.crt")
102+
103+
containerEnvOverride := envVars[committerVersion](peerMSPDir, peerTLSDir, scMSPID, e.channel.Name, ordererEndpoint, e.network.TLSEnabled, ordererTLSCACert)
100104
containerCmd := containerCmds[committerVersion]
101105
containerSidecarPort := sidecarDefaultPort[committerVersion]
102106
containerQueryServicePort := queryServiceDefaultPort[committerVersion]

integration/nwo/fabricx/extensions/scv2/utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ func peerDockerMSPDir(n *network.Network, p *topology.Peer) string {
3030
)
3131
}
3232

33+
func peerDockerTLSDir(n *network.Network, p *topology.Peer) string {
34+
org := n.Organization(p.Organization)
35+
36+
return filepath.Join(
37+
"/",
38+
"root",
39+
"artifacts",
40+
"crypto",
41+
"peerOrganizations",
42+
org.Domain,
43+
"peers",
44+
fmt.Sprintf("%s.%s", p.Name, org.Domain),
45+
"tls",
46+
)
47+
}
48+
3349
func rootCrypto(n *network.Network) string {
3450
return filepath.Join(
3551
n.RootDir,

integration/nwo/fabricx/extensions/v3/test_utils.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ SPDX-License-Identifier: Apache-2.0
66

77
package v3
88

9+
import (
10+
"path"
11+
)
12+
913
const (
1014
CommitterVersion = "v3"
1115
ScalableCommitterImage = "hyperledger/fabric-x-committer-test-node:0.1.9"
1216
SidecarDefaultPort = "4001/tcp"
1317
QueryServiceDefaultPort = "7001/tcp"
1418
)
1519

16-
var ContainerCmd = []string{"run", "db", "orderer", "committer", "--insecure"}
20+
var ContainerCmd = []string{"run", "db", "orderer", "committer"}
1721

18-
func ContainerEnvVars(peerMSPDir, scMSPID, channelName, ordererEndpoint string) []string {
19-
return []string{
22+
func ContainerEnvVars(peerMSPDir, peerTLSDir, scMSPID, channelName, ordererEndpoint string, tlsEnabled bool, ordererTLSCACert string) []string {
23+
env := []string{
2024
"SC_SIDECAR_LOGGING_LOGSPEC=debug",
2125
"SC_SIDECAR_ORDERER_CHANNEL_ID=" + channelName,
2226
"SC_SIDECAR_ORDERER_SIGNED_ENVELOPES=true",
23-
"SC_SIDECAR_ORDERER_TLS_MODE=none",
2427
"SC_SIDECAR_ORDERER_IDENTITY_MSP_ID=" + scMSPID,
2528
"SC_SIDECAR_ORDERER_IDENTITY_MSP_DIR=" + peerMSPDir,
2629
"SC_QUERY_SERVICE_SERVER_ENDPOINT=:7001",
@@ -32,4 +35,15 @@ func ContainerEnvVars(peerMSPDir, scMSPID, channelName, ordererEndpoint string)
3235
"SC_VERIFIER_LOGGING_LOGSPEC=INFO",
3336
"SC_SIDECAR_SERVER_MAX_CONCURRENT_STREAMS=0",
3437
}
38+
if tlsEnabled {
39+
env = append(env,
40+
"SC_SIDECAR_ORDERER_TLS_MODE=tls",
41+
"SC_SIDECAR_ORDERER_TLS_CERT_FILE="+path.Join(peerTLSDir, "server.crt"),
42+
"SC_SIDECAR_ORDERER_TLS_KEY_FILE="+path.Join(peerTLSDir, "server.key"),
43+
"SC_SIDECAR_ORDERER_TLS_ROOT_CERT_FILE="+ordererTLSCACert,
44+
)
45+
} else {
46+
env = append(env, "SC_SIDECAR_ORDERER_TLS_MODE=none")
47+
}
48+
return env
3549
}

integration/nwo/fabricx/network/network.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (n *Network) DeployNamespace(chaincode *topology.ChannelChaincode) {
207207
OrdererConfig: fxconfig.OrdererConfig{
208208
Address: n.OrdererAddress(n.Orderers[0], fabric_network.ListenPort),
209209
TLSConfig: fxconfig.TLSConfig{
210-
Enabled: false,
210+
Enabled: n.TLSEnabled,
211211
RootCerts: []string{n.OrgOrdererTLSCACertificatePath(n.Organizations[0])},
212212
},
213213
},
@@ -234,8 +234,11 @@ func (n *Network) UpdateNamespace(chaincodeID, version, path, packageFile string
234234
// gomega.Eventually for retrying.
235235
func (n *Network) tryListInstalledNames() ([]Namespace, error) {
236236
cmd := &fxconfig.ListNamespaces{QueryConfig: fxconfig.QueryConfig{
237-
Address: "127.0.0.1:7001",
238-
TLSConfig: fxconfig.TLSConfig{},
237+
Address: "127.0.0.1:7001",
238+
TLSConfig: fxconfig.TLSConfig{
239+
Enabled: n.TLSEnabled,
240+
RootCerts: []string{n.OrgOrdererTLSCACertificatePath(n.Organizations[0])},
241+
},
239242
}}
240243
sess, err := n.StartSession(common.NewCommand(fxconfig.CMDPath(), cmd), cmd.SessionName())
241244
if err != nil {

0 commit comments

Comments
 (0)