You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2021/03/11 03:30:48 UTC

[servicecomb-service-center] branch master updated: [SCB-2094] Mongo URI uses cipher for encryption (#891)

This is an automated email from the ASF dual-hosted git repository.

tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new 63ca82d  [SCB-2094] Mongo URI uses cipher for encryption (#891)
63ca82d is described below

commit 63ca82dde5e8c5108b5f61d062024124b7c962da
Author: robotLJW <79...@qq.com>
AuthorDate: Thu Mar 11 11:30:37 2021 +0800

    [SCB-2094] Mongo URI uses cipher for encryption (#891)
---
 datasource/mongo/client/mongo.go                      | 14 +++++++++++---
 datasource/mongo/client/mongo_test.go                 |  3 +++
 datasource/mongo/event/instance_event_handler_test.go |  3 +++
 datasource/mongo/heartbeat/cache/heartbeat_test.go    |  1 +
 datasource/mongo/heartbeat/checker/heartbeat_test.go  |  3 +++
 go.mod                                                |  4 ++--
 6 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/datasource/mongo/client/mongo.go b/datasource/mongo/client/mongo.go
index 3c27476..4f7e761 100644
--- a/datasource/mongo/client/mongo.go
+++ b/datasource/mongo/client/mongo.go
@@ -23,12 +23,14 @@ import (
 	"io/ioutil"
 	"time"
 
-	"github.com/apache/servicecomb-service-center/pkg/gopool"
-	"github.com/apache/servicecomb-service-center/pkg/log"
 	"github.com/go-chassis/go-chassis/v2/storage"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/mongo"
 	"go.mongodb.org/mongo-driver/mongo/options"
+
+	"github.com/apache/servicecomb-service-center/pkg/gopool"
+	"github.com/apache/servicecomb-service-center/pkg/log"
+	"github.com/apache/servicecomb-service-center/server/plugin/security/cipher"
 )
 
 const (
@@ -128,7 +130,13 @@ func (mc *MongoClient) HealthCheck(ctx context.Context) {
 }
 
 func (mc *MongoClient) newClient(ctx context.Context) (err error) {
-	clientOptions := []*options.ClientOptions{options.Client().ApplyURI(mc.dbconfig.URI)}
+	var uri string
+	uri, err = cipher.Decrypt(mc.dbconfig.URI)
+	if err != nil {
+		log.Info("cipher fallback: " + err.Error())
+		uri = mc.dbconfig.URI
+	}
+	clientOptions := []*options.ClientOptions{options.Client().ApplyURI(uri)}
 	if mc.dbconfig.SSLEnabled {
 		if mc.dbconfig.RootCA == "" {
 			err = ErrRootCAMissing
diff --git a/datasource/mongo/client/mongo_test.go b/datasource/mongo/client/mongo_test.go
index a3983a9..e896439 100644
--- a/datasource/mongo/client/mongo_test.go
+++ b/datasource/mongo/client/mongo_test.go
@@ -23,6 +23,9 @@ import (
 	"context"
 	"testing"
 
+	_ "github.com/apache/servicecomb-service-center/server/init"
+	_ "github.com/apache/servicecomb-service-center/server/plugin/security/cipher/buildin"
+
 	"github.com/go-chassis/go-chassis/v2/storage"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/mongo"
diff --git a/datasource/mongo/event/instance_event_handler_test.go b/datasource/mongo/event/instance_event_handler_test.go
index ebfe1da..88063da 100644
--- a/datasource/mongo/event/instance_event_handler_test.go
+++ b/datasource/mongo/event/instance_event_handler_test.go
@@ -32,6 +32,9 @@ import (
 	"github.com/apache/servicecomb-service-center/datasource/mongo/db"
 	"github.com/apache/servicecomb-service-center/datasource/mongo/sd"
 	"github.com/apache/servicecomb-service-center/server/syncernotify"
+
+	_ "github.com/apache/servicecomb-service-center/server/init"
+	_ "github.com/apache/servicecomb-service-center/server/plugin/security/cipher/buildin"
 )
 
 func init() {
diff --git a/datasource/mongo/heartbeat/cache/heartbeat_test.go b/datasource/mongo/heartbeat/cache/heartbeat_test.go
index 7d10325..49bb7ca 100644
--- a/datasource/mongo/heartbeat/cache/heartbeat_test.go
+++ b/datasource/mongo/heartbeat/cache/heartbeat_test.go
@@ -19,6 +19,7 @@ package heartbeatcache
 
 import (
 	_ "github.com/apache/servicecomb-service-center/server/init"
+	_ "github.com/apache/servicecomb-service-center/server/plugin/security/cipher/buildin"
 )
 
 import (
diff --git a/datasource/mongo/heartbeat/checker/heartbeat_test.go b/datasource/mongo/heartbeat/checker/heartbeat_test.go
index 1bd8ff2..8ac65c0 100644
--- a/datasource/mongo/heartbeat/checker/heartbeat_test.go
+++ b/datasource/mongo/heartbeat/checker/heartbeat_test.go
@@ -22,6 +22,9 @@ import (
 	"testing"
 	"time"
 
+	_ "github.com/apache/servicecomb-service-center/server/init"
+	_ "github.com/apache/servicecomb-service-center/server/plugin/security/cipher/buildin"
+
 	pb "github.com/go-chassis/cari/discovery"
 	"github.com/go-chassis/go-chassis/v2/storage"
 	"github.com/stretchr/testify/assert"
diff --git a/go.mod b/go.mod
index 7bca2b1..64ee4d9 100644
--- a/go.mod
+++ b/go.mod
@@ -19,8 +19,8 @@ require (
 	github.com/ghodss/yaml v1.0.0
 	github.com/go-chassis/cari v0.2.0
 	github.com/go-chassis/foundation v0.3.0
-	github.com/go-chassis/go-archaius v1.4.0
-	github.com/go-chassis/go-chassis/v2 v2.1.1-0.20210218100404-85e04ad6bd31
+	github.com/go-chassis/go-archaius v1.5.1
+	github.com/go-chassis/go-chassis/v2 v2.1.2-0.20210310004133-c9bc42149a18
 	github.com/go-chassis/kie-client v0.1.0
 	github.com/golang/protobuf v1.4.2 // indirect
 	github.com/google/go-cmp v0.5.4 // indirect