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 2020/12/07 02:56:53 UTC

[servicecomb-service-center] branch master updated: SCB-2094 Bug fixes: Unavailable SSL (#775)

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 9bdf36b  SCB-2094 Bug fixes: Unavailable SSL (#775)
9bdf36b is described below

commit 9bdf36b123ba915d929d8bfa7b18fbb13e172987
Author: little-cui <su...@qq.com>
AuthorDate: Mon Dec 7 10:56:46 2020 +0800

    SCB-2094 Bug fixes: Unavailable SSL (#775)
---
 datasource/etcd/cache/common.go       | 12 ++++++------
 datasource/etcd/client/remote/etcd.go |  7 +++++--
 datasource/etcd/engine.go             | 28 ++++++++++++++--------------
 datasource/etcd/etcd.go               |  2 +-
 datasource/etcd/ms.go                 |  3 ---
 datasource/mongo/mongo.go             |  2 +-
 pkg/util/context.go                   |  8 ++++----
 pkg/util/net.go                       |  4 +++-
 server/bootstrap/bootstrap.go         |  2 +-
 server/config/config.go               |  5 +----
 server/config/server.go               |  5 +----
 server/core/microservice.go           |  2 +-
 server/handler/context/context.go     |  2 +-
 server/server.go                      |  1 +
 14 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/datasource/etcd/cache/common.go b/datasource/etcd/cache/common.go
index 69bd802..8e501f8 100644
--- a/datasource/etcd/cache/common.go
+++ b/datasource/etcd/cache/common.go
@@ -23,17 +23,17 @@ import (
 	"sync"
 
 	"github.com/apache/servicecomb-service-center/datasource"
+	"github.com/apache/servicecomb-service-center/pkg/util"
 )
 
-type ContextKey string
 type ClustersIndex map[string]int
 
 const (
-	CtxFindConsumer         ContextKey = "_consumer"
-	CtxFindProvider         ContextKey = "_provider"
-	CtxFindProviderInstance ContextKey = "_provider_instance"
-	CtxFindTags             ContextKey = "_tags"
-	CtxFindRequestRev       ContextKey = "_rev"
+	CtxFindConsumer         util.CtxKey = "_consumer"
+	CtxFindProvider         util.CtxKey = "_provider"
+	CtxFindProviderInstance util.CtxKey = "_provider_instance"
+	CtxFindTags             util.CtxKey = "_tags"
+	CtxFindRequestRev       util.CtxKey = "_rev"
 
 	Find = "_find"
 	Dep  = "_dep"
diff --git a/datasource/etcd/client/remote/etcd.go b/datasource/etcd/client/remote/etcd.go
index 4f4d4a6..1dba232 100644
--- a/datasource/etcd/client/remote/etcd.go
+++ b/datasource/etcd/client/remote/etcd.go
@@ -73,6 +73,9 @@ func (c *Client) Initialize() (err error) {
 		// parse the endpoints from config
 		c.parseEndpoints()
 	}
+	log.Info(fmt.Sprintf("parse %v -> endpoints: %v, ssl: %v",
+		etcd.Configuration().Clusters, c.Endpoints, etcd.Configuration().SslEnabled))
+
 	if c.TLSConfig == nil && etcd.Configuration().SslEnabled {
 		var err error
 		// go client tls限制,提供身份证书、不认证服务端、不校验CN
@@ -99,8 +102,8 @@ func (c *Client) Initialize() (err error) {
 
 	close(c.ready)
 
-	log.Warnf("get etcd client %v completed, auto sync endpoints interval is %s.",
-		c.Endpoints, c.AutoSyncInterval)
+	log.Warn(fmt.Sprintf("get etcd client %v completed, ssl: %v, dial timeout: %s, auto sync endpoints interval is %s.",
+		c.Endpoints, c.TLSConfig != nil, c.DialTimeout, c.AutoSyncInterval))
 	return
 }
 
diff --git a/datasource/etcd/engine.go b/datasource/etcd/engine.go
index 5404a6f..62c934b 100644
--- a/datasource/etcd/engine.go
+++ b/datasource/etcd/engine.go
@@ -25,11 +25,11 @@ import (
 	"strings"
 	"time"
 
+	"github.com/apache/servicecomb-service-center/datasource"
 	"github.com/apache/servicecomb-service-center/datasource/etcd/path"
+	serviceUtil "github.com/apache/servicecomb-service-center/datasource/etcd/util"
 	"github.com/apache/servicecomb-service-center/pkg/cluster"
 	"github.com/apache/servicecomb-service-center/pkg/gopool"
-
-	serviceUtil "github.com/apache/servicecomb-service-center/datasource/etcd/util"
 	"github.com/apache/servicecomb-service-center/pkg/log"
 	"github.com/apache/servicecomb-service-center/pkg/util"
 	"github.com/apache/servicecomb-service-center/server/core"
@@ -46,7 +46,8 @@ func (ds *DataSource) SelfRegister(ctx context.Context) error {
 	return nil
 }
 
-func (ds *DataSource) selfRegister(ctx context.Context) error {
+func (ds *DataSource) selfRegister(pCtx context.Context) error {
+	ctx := core.AddDefaultContextValue(pCtx)
 	err := ds.registerService(ctx)
 	if err != nil {
 		return err
@@ -55,8 +56,7 @@ func (ds *DataSource) selfRegister(ctx context.Context) error {
 	return ds.registerInstance(ctx)
 }
 
-func (ds *DataSource) registerService(pCtx context.Context) error {
-	ctx := core.AddDefaultContextValue(pCtx)
+func (ds *DataSource) registerService(ctx context.Context) error {
 	respE, err := core.ServiceAPI.Exist(ctx, core.GetExistenceRequest())
 	if err != nil {
 		log.Error("query service center existence failed", err)
@@ -67,7 +67,7 @@ func (ds *DataSource) registerService(pCtx context.Context) error {
 		respG, err := core.ServiceAPI.GetOne(ctx, core.GetServiceRequest(respE.ServiceId))
 		if respG.Response.GetCode() != pb.ResponseSuccess {
 			log.Errorf(err, "query service center service[%s] info failed", respE.ServiceId)
-			return fmt.Errorf("service center service file lost")
+			return datasource.ErrServiceNotExists
 		}
 		core.Service = respG.Service
 		return nil
@@ -78,27 +78,27 @@ func (ds *DataSource) registerService(pCtx context.Context) error {
 		log.Error("register service center failed", err)
 		return err
 	}
+	if respS.Response.GetCode() != pb.ResponseSuccess {
+		log.Error("register service center failed, msg: "+respS.Response.GetMessage(), nil)
+		return errors.New(respS.Response.GetMessage())
+	}
 	core.Service.ServiceId = respS.ServiceId
 	log.Infof("register service center service[%s]", respS.ServiceId)
 	return nil
 }
 
-func (ds *DataSource) registerInstance(pCtx context.Context) error {
+func (ds *DataSource) registerInstance(ctx context.Context) error {
 	core.Instance.InstanceId = ""
 	core.Instance.ServiceId = core.Service.ServiceId
-
-	ctx := core.AddDefaultContextValue(pCtx)
-
 	respI, err := core.InstanceAPI.Register(ctx, core.RegisterInstanceRequest())
 	if err != nil {
 		log.Error("register failed", err)
 		return err
 	}
 	if respI.Response.GetCode() != pb.ResponseSuccess {
-		err = fmt.Errorf("register service center[%s] instance failed, %s",
-			core.Instance.ServiceId, respI.Response.GetMessage())
-		log.Error(err.Error(), nil)
-		return err
+		log.Error(fmt.Sprintf("register service center[%s] instance failed, %s",
+			core.Instance.ServiceId, respI.Response.GetMessage()), nil)
+		return errors.New(respI.Response.GetMessage())
 	}
 	core.Instance.InstanceId = respI.InstanceId
 	log.Infof("register service center instance[%s/%s], endpoints is %s",
diff --git a/datasource/etcd/etcd.go b/datasource/etcd/etcd.go
index 23ea7b4..a8d136d 100644
--- a/datasource/etcd/etcd.go
+++ b/datasource/etcd/etcd.go
@@ -56,7 +56,7 @@ type DataSource struct {
 
 func NewDataSource(opts datasource.Options) (datasource.DataSource, error) {
 	// TODO: construct a reasonable DataSource instance
-	log.Warnf("dependency data source enable etcd mode")
+	log.Warnf("data source enable etcd mode")
 
 	inst := &DataSource{
 		SchemaEditable:    opts.SchemaEditable,
diff --git a/datasource/etcd/ms.go b/datasource/etcd/ms.go
index f439f33..1527490 100644
--- a/datasource/etcd/ms.go
+++ b/datasource/etcd/ms.go
@@ -52,8 +52,6 @@ func (ds *DataSource) RegisterService(ctx context.Context, request *pb.CreateSer
 	service := request.Service
 	serviceFlag := util.StringJoin([]string{
 		service.Environment, service.AppId, service.ServiceName, service.Version}, "/")
-
-	datasource.SetServiceDefaultValue(service)
 	domainProject := util.ParseDomainProject(ctx)
 
 	serviceKey := &pb.MicroServiceKey{
@@ -67,7 +65,6 @@ func (ds *DataSource) RegisterService(ctx context.Context, request *pb.CreateSer
 
 	reporter := checkQuota(ctx, domainProject)
 	defer reporter.Close(ctx)
-
 	if reporter != nil && reporter.Err != nil {
 		log.Errorf(reporter.Err, "create micro-service[%s] failed, operator: %s",
 			serviceFlag, remoteIP)
diff --git a/datasource/mongo/mongo.go b/datasource/mongo/mongo.go
index 6e96711..0dc6870 100644
--- a/datasource/mongo/mongo.go
+++ b/datasource/mongo/mongo.go
@@ -39,7 +39,7 @@ type DataSource struct {
 
 func NewDataSource(opts datasource.Options) (datasource.DataSource, error) {
 	// TODO: construct a reasonable DataSource instance
-	log.Warn("dependency data source enable etcd mode")
+	log.Warn("data source enable mongo mode")
 
 	inst := &DataSource{
 		SchemaEditable: opts.SchemaEditable,
diff --git a/pkg/util/context.go b/pkg/util/context.go
index 220af73..b77bbc2 100644
--- a/pkg/util/context.go
+++ b/pkg/util/context.go
@@ -24,10 +24,10 @@ import (
 )
 
 const (
-	CtxDomain        = "domain"
-	CtxProject       = "project"
-	CtxTargetDomain  = "target-domain"
-	CtxTargetProject = "target-project"
+	CtxDomain        CtxKey = "domain"
+	CtxProject       CtxKey = "project"
+	CtxTargetDomain  CtxKey = "target-domain"
+	CtxTargetProject CtxKey = "target-project"
 )
 
 type StringContext struct {
diff --git a/pkg/util/net.go b/pkg/util/net.go
index 08f4f17..1ad72c6 100644
--- a/pkg/util/net.go
+++ b/pkg/util/net.go
@@ -26,13 +26,15 @@ import (
 	"strings"
 )
 
+const CtxRemoteIP CtxKey = "x-remote-ip"
+
 type IPPort struct {
 	IP   string
 	Port uint16
 }
 
 func GetIPFromContext(ctx context.Context) string {
-	v, ok := FromContext(ctx, "x-remote-ip").(string)
+	v, ok := FromContext(ctx, CtxRemoteIP).(string)
 	if !ok {
 		return "UNKNOWN"
 	}
diff --git a/server/bootstrap/bootstrap.go b/server/bootstrap/bootstrap.go
index 07f3deb..e42b4aa 100644
--- a/server/bootstrap/bootstrap.go
+++ b/server/bootstrap/bootstrap.go
@@ -16,8 +16,8 @@
  */
 package bootstrap
 
-//etcd
 import (
+	//etcd
 	_ "github.com/apache/servicecomb-service-center/datasource/etcd/bootstrap"
 
 	//mongo
diff --git a/server/config/config.go b/server/config/config.go
index 91545ad..facab7a 100644
--- a/server/config/config.go
+++ b/server/config/config.go
@@ -149,10 +149,7 @@ func newInfo() ServerInformation {
 
 			EnablePProf: GetInt("server.pprof.mode", 0, WithStandby("enable_pprof")) != 0,
 
-			SslEnabled:    GetInt("ssl.mode", 1, WithStandby("ssl_mode")) != 0,
-			SslMinVersion: GetString("ssl.minVersion", "TLSv1.2", WithStandby("ssl_min_version")),
-			SslVerifyPeer: GetInt("ssl.verifyClient", 1, WithStandby("ssl_verify_client")) != 0,
-			SslCiphers:    GetString("ssl.ciphers", "", WithStandby("ssl_ciphers")),
+			SslEnabled: GetInt("ssl.mode", 1, WithStandby("ssl_mode")) != 0,
 
 			CompactIndexDelta: GetInt64("registry.compact.indexDelta", 100, WithStandby("compact_index_delta")),
 			CompactInterval:   GetDuration("registry.compact.interval", 12*time.Hour, WithStandby("compact_interval")),
diff --git a/server/config/server.go b/server/config/server.go
index f48a63e..c0138af 100644
--- a/server/config/server.go
+++ b/server/config/server.go
@@ -36,10 +36,7 @@ type ServerConfig struct {
 	LimitConnections int64  `json:"limitConnections"`
 	LimitIPLookup    string `json:"limitIPLookup"`
 
-	SslEnabled    bool   `json:"sslEnabled,string"`
-	SslMinVersion string `json:"sslMinVersion"`
-	SslVerifyPeer bool   `json:"sslVerifyPeer,string"`
-	SslCiphers    string `json:"sslCiphers"`
+	SslEnabled bool `json:"sslEnabled,string"`
 
 	AutoSyncInterval  time.Duration `json:"-"`
 	CompactIndexDelta int64         `json:"-"`
diff --git a/server/core/microservice.go b/server/core/microservice.go
index cb0ddbd..a79e410 100644
--- a/server/core/microservice.go
+++ b/server/core/microservice.go
@@ -49,7 +49,7 @@ const (
 	RegistryDefaultLeaseRenewalinterval int32 = 30
 	RegistryDefaultLeaseRetrytimes      int32 = 3
 
-	CtxScSelf = "_sc_self"
+	CtxScSelf util.CtxKey = "_sc_self"
 )
 
 func init() {
diff --git a/server/handler/context/context.go b/server/handler/context/context.go
index caf0558..d837431 100644
--- a/server/handler/context/context.go
+++ b/server/handler/context/context.go
@@ -50,7 +50,7 @@ func (c *Handler) Handle(i *chain.Invocation) {
 		return
 	}
 
-	i.WithContext("x-remote-ip", util.GetRealIP(r))
+	i.WithContext(util.CtxRemoteIP, util.GetRealIP(r))
 
 	i.Next()
 }
diff --git a/server/server.go b/server/server.go
index 2453151..5440e9e 100644
--- a/server/server.go
+++ b/server/server.go
@@ -111,6 +111,7 @@ func (s *ServiceCenterServer) initDatasource() {
 	kind := datasource.ImplName(config.GetString("registry.kind", "", config.WithStandby("registry_plugin")))
 	if err := datasource.Init(datasource.Options{
 		PluginImplName:    kind,
+		SslEnabled:        config.GetSSL().SslEnabled,
 		InstanceTTL:       config.GetRegistry().InstanceTTL,
 		SchemaEditable:    config.GetRegistry().SchemaEditable,
 		CompactInterval:   config.GetRegistry().CompactInterval,