-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CloudSync] Adding TLS to secure MQTT Client Broker Communication #465
Conversation
Signed-off-by: Nitu Gupta <[email protected]>
[Cloudsync] Added testcases to improve the Code coverage for MQTT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Please take a look at my comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL!
b756d1a
to
28ab1f0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -65,6 +67,13 @@ func (c *CloudSyncImpl) InitiateCloudSync(isCloudSet string) (err error) { | |||
if strings.Compare(strings.ToLower(isCloudSet), "true") == 0 { | |||
log.Println("CloudSync init set") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Println("CloudSync init set") | |
log.Info(logPrefix, "CloudSync init set") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!
secure := os.Getenv("SECURE") | ||
if len(secure) > 0 { | ||
if strings.Compare(strings.ToLower(secure), "true") == 0 { | ||
log.Println(logPrefix, "Orchestration init with secure option") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Println(logPrefix, "Orchestration init with secure option") | |
log.Info(logPrefix, "Orchestration init with secure option") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!
secure := os.Getenv("SECURE") | ||
if len(secure) > 0 { | ||
if strings.Compare(strings.ToLower(secure), "true") == 0 { | ||
log.Println(logPrefix, "Orchestration init with secure option") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logPrefix = "[cloudsyncmgr]"
change to logPrefix = "[cloudsyncmgr] "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!
@@ -115,7 +115,8 @@ func StartMQTTClient(brokerURL string, clientID string) string { | |||
return err.Error() | |||
} | |||
clientConfig.ClientOptions.SetOnConnectHandler(clientConfig.onConnect()) | |||
URL := clientConfig.SetBrokerURL("tcp") | |||
clientConfig.setProtocol() | |||
URL := clientConfig.SetBrokerURL() | |||
log.Info(logPrefix, " The broker is", URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before logPrefix = "[MQTTConnectionMgr]"
should be change to 1logPrefix = "[MQTTConnectionMgr] "`
log.Info(logPrefix, " The broker is", URL) | |
log.Info(logPrefix, "The broker is", URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!
internal/common/mqtt/mqttconfig.go
Outdated
certpool := x509.NewCertPool() | ||
ca, err := ioutil.ReadFile(caCertConfig) | ||
if err != nil { | ||
log.Warn(err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Warn(err.Error()) | |
log.Warn(logPrefix, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
internal/common/mqtt/mqttconfig.go
Outdated
return nil, err | ||
} | ||
copts.SetTLSConfig(tlsconfig) | ||
// TODO Use Username and password to provide authorization to MQTT Broker zuncomment the below two lines to enable authorization after creating password file for each user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO Use Username and password to provide authorization to MQTT Broker zuncomment the below two lines to enable authorization after creating password file for each user | |
// TODO: Use Username and Password to provide authorization to MQTT Broker uncomment the below two lines to enable authorization after creating password file for each user. This is temporary solution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a temporary solution. Its the solution as suggested by mosquitto broker. So its user dependent and hence commented. I can uncomment and put it but then what will be the password set by the user and username hence it is user dependent and also its one of the secure modes of communication as provided by Mosquitto broker as mentioned in the documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- login and password cannot be stored in the program and must be exported from a secure storage
- more suitable option is a signed certificate with a fixed SAN (we had difficulties with this, but I will investigate this issue in more detail later)
So I think this is a temporary solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes , it should be ideally but you have to pass the password through copts only thats the architecture design of Mosquitto broker . Secondly Certificates through SAN can give you secure communication channel which is already done. The issue was resolved by me. There is no issue in it. So I think there is some confusion from your side. SAN certificates were fine and are working fine now. As already mentioned in previous PR also the issue was resolved and it wasnot certificates issue.
Storing certificate at any location wouldnt change passing of password through copts only the path will change. SO i disagree with your point of this being a temporary solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I wrote above, this is a temporary solution, since the password cannot be stored in the program.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can take it step by step
- while we consider the option of communication with only one broker
- we have two options: a) add the phrase that this is a temporary solution, accept this request, and urgently prepare to read the login and password from an external file; b) we finish reading the login and password from an external file or from another place
If accepted in the current version: we need remove the OpenSSF "passing" and "silver" badge from our project (because it violates security requirements ), and also the container that is downloaded from dockerhub will not work fully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm more concerned about the unprotected storage password in the code (hardcoded). And as I said earlier, we can implement the issues of secure interaction with the broker later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to fix the secure location for password file storage . We can discuss that separately. And this file reading should not take much time. So once we fix the file location we can raise PR for that. @nitu-s-gupta : Please remove the lines..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nitu-s-gupta Please create an issue to discuss about cert and password.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nitu-s-gupta Please create an issue to discuss about cert and password.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Signed-off-by: Nitu Gupta <[email protected]>
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Certificates can be generated using openssl library and copied to /var/edge-orchestration/mqtt/certs folder. This will aloow the secure communication between mqtt broker and client.
Fixes # (#382)
Type of change
How Has This Been Tested?
1.MQTT mosquitto broker is configured to be running in the AWS endpoint. The certificates are copied to /etc/mosquitto/certs folder and corresponding path is specified in the configuration file
In the client side the root CA certificates are copied in the /var/edge-orchestration/mqtt/certs
2. The edge orchestration is build and run using following command with option CLOUD_SYNC set to true
Test Configuration:
Checklist: