You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/09/26 13:49:03 UTC

[GitHub] [skywalking-kubernetes-event-exporter] kezhenxu94 commented on a change in pull request #11: support tls for SkyWalking client

kezhenxu94 commented on a change in pull request #11:
URL: https://github.com/apache/skywalking-kubernetes-event-exporter/pull/11#discussion_r716207138



##########
File path: pkg/exporter/skywalking.go
##########
@@ -67,7 +78,39 @@ func (exporter *SkyWalking) Init(ctx context.Context) error {
 		return err
 	}
 
-	conn, err := grpc.Dial(config.Address, grpc.WithInsecure())
+	var dialOption grpc.DialOption
+	if config.EnableTLS {
+		if isFileExisted(config.ClientCertPath) && isFileExisted(config.ClientKeyPath) {
+			clientCert, err := tls.LoadX509KeyPair(config.ClientCertPath, config.ClientKeyPath)
+			if err != nil {
+				log.Fatalf("Failed to load client certificate and key. %s.", err)

Review comment:
       return the error instead of failing here

##########
File path: pkg/exporter/skywalking.go
##########
@@ -67,7 +78,39 @@ func (exporter *SkyWalking) Init(ctx context.Context) error {
 		return err
 	}
 
-	conn, err := grpc.Dial(config.Address, grpc.WithInsecure())
+	var dialOption grpc.DialOption
+	if config.EnableTLS {
+		if isFileExisted(config.ClientCertPath) && isFileExisted(config.ClientKeyPath) {
+			clientCert, err := tls.LoadX509KeyPair(config.ClientCertPath, config.ClientKeyPath)
+			if err != nil {
+				log.Fatalf("Failed to load client certificate and key. %s.", err)
+			}
+			trustedCert, err := ioutil.ReadFile(config.TrustedCertPath)
+			if err != nil {
+				log.Fatalf("Failed to load trusted certificate. %s.", err)

Review comment:
       return the error instead of failing here

##########
File path: pkg/exporter/skywalking.go
##########
@@ -67,7 +78,39 @@ func (exporter *SkyWalking) Init(ctx context.Context) error {
 		return err
 	}
 
-	conn, err := grpc.Dial(config.Address, grpc.WithInsecure())
+	var dialOption grpc.DialOption
+	if config.EnableTLS {
+		if isFileExisted(config.ClientCertPath) && isFileExisted(config.ClientKeyPath) {
+			clientCert, err := tls.LoadX509KeyPair(config.ClientCertPath, config.ClientKeyPath)
+			if err != nil {
+				log.Fatalf("Failed to load client certificate and key. %s.", err)
+			}
+			trustedCert, err := ioutil.ReadFile(config.TrustedCertPath)
+			if err != nil {
+				log.Fatalf("Failed to load trusted certificate. %s.", err)
+			}
+			certPool := x509.NewCertPool()
+			if !certPool.AppendCertsFromPEM(trustedCert) {
+				log.Fatalf("Failed to append trusted certificate to certificate pool. %s.", err)

Review comment:
       return the error instead of failing here




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org