Browse Source

Merge pull request #1345 from gravitl/hotfix_v0.14.5_ssl_mq

added ssl to server conns to mq enp
dcarns 3 years ago
parent
commit
18416f6070
3 changed files with 10 additions and 5 deletions
  1. 2 1
      main.go
  2. 5 2
      mq/mq.go
  3. 3 2
      servercfg/serverconf.go

+ 2 - 1
main.go

@@ -168,7 +168,8 @@ func startControllers() {
 // Should we be using a context vice a waitgroup????????????
 // Should we be using a context vice a waitgroup????????????
 func runMessageQueue(wg *sync.WaitGroup) {
 func runMessageQueue(wg *sync.WaitGroup) {
 	defer wg.Done()
 	defer wg.Done()
-	logger.Log(0, "connecting to mq broker at", servercfg.GetMessageQueueEndpoint())
+	brokerHost, secure := servercfg.GetMessageQueueEndpoint()
+	logger.Log(0, "connecting to mq broker at", brokerHost, "with TLS?", fmt.Sprintf("%v", secure))
 	var client = mq.SetupMQTT(false) // Set up the subscription listener
 	var client = mq.SetupMQTT(false) // Set up the subscription listener
 	ctx, cancel := context.WithCancel(context.Background())
 	ctx, cancel := context.WithCancel(context.Background())
 	go mq.Keepalive(ctx)
 	go mq.Keepalive(ctx)

+ 5 - 2
mq/mq.go

@@ -24,10 +24,13 @@ var peer_force_send = 0
 // SetupMQTT creates a connection to broker and return client
 // SetupMQTT creates a connection to broker and return client
 func SetupMQTT(publish bool) mqtt.Client {
 func SetupMQTT(publish bool) mqtt.Client {
 	opts := mqtt.NewClientOptions()
 	opts := mqtt.NewClientOptions()
-	opts.AddBroker(servercfg.GetMessageQueueEndpoint())
+	broker, secure := servercfg.GetMessageQueueEndpoint()
+	opts.AddBroker(broker)
 	id := ncutils.MakeRandomString(23)
 	id := ncutils.MakeRandomString(23)
 	opts.ClientID = id
 	opts.ClientID = id
-	opts.SetTLSConfig(&serverctl.TlsConfig)
+	if secure {
+		opts.SetTLSConfig(&serverctl.TlsConfig)
+	}
 	opts.SetAutoReconnect(true)
 	opts.SetAutoReconnect(true)
 	opts.SetConnectRetry(true)
 	opts.SetConnectRetry(true)
 	opts.SetConnectRetryInterval(time.Second << 2)
 	opts.SetConnectRetryInterval(time.Second << 2)

+ 3 - 2
servercfg/serverconf.go

@@ -222,14 +222,15 @@ func GetMQPort() string {
 }
 }
 
 
 // GetMessageQueueEndpoint - gets the message queue endpoint
 // GetMessageQueueEndpoint - gets the message queue endpoint
-func GetMessageQueueEndpoint() string {
+func GetMessageQueueEndpoint() (string, bool) {
 	host, _ := GetPublicIP()
 	host, _ := GetPublicIP()
 	if os.Getenv("MQ_HOST") != "" {
 	if os.Getenv("MQ_HOST") != "" {
 		host = os.Getenv("MQ_HOST")
 		host = os.Getenv("MQ_HOST")
 	} else if config.Config.Server.MQHOST != "" {
 	} else if config.Config.Server.MQHOST != "" {
 		host = config.Config.Server.MQHOST
 		host = config.Config.Server.MQHOST
 	}
 	}
-	return host + ":" + GetMQServerPort()
+	secure := strings.Contains(host, "mqtts") || strings.Contains(host, "ssl")
+	return host + ":" + GetMQServerPort(), secure
 }
 }
 
 
 // GetMasterKey - gets the configured master key of server
 // GetMasterKey - gets the configured master key of server