Skip to content

Commit

Permalink
Merge pull request #49 from kqzh/add_handshake_flag
Browse files Browse the repository at this point in the history
feat: add handshake_key
  • Loading branch information
kqzh authored Jan 9, 2024
2 parents 328bee2 + 926ca90 commit 4451d76
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 31 deletions.
3 changes: 2 additions & 1 deletion cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
caPath = flag.String("ca_path", "/usr/local/certs/ca.crt", "path to CA file")
enableSSL = flag.Bool("enable_ssl", false, "Enable SSL for agent")
insecureSkipVerify = flag.Bool("insecure_skip_verify", false, "Skip server side cert verification")
handshakeKey = flag.String("handshake_key", "3.0.0", "Specify the key for handshake with nebula")
)

func main() {
Expand Down Expand Up @@ -78,7 +79,7 @@ func main() {
tlsConfig.InsecureSkipVerify = *insecureSkipVerify
}

metaCfg, err := clients.NewMetaConfig(*agent, *meta, GitInfoSHA, *hbs, tlsConfig)
metaCfg, err := clients.NewMetaConfig(*agent, *meta, GitInfoSHA, *handshakeKey, *hbs, tlsConfig)
if err != nil {
log.WithError(err).Fatalf("Failed to create meta config.")
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ require (
github.com/kr/pretty v0.3.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/vesoft-inc/fbthrift v0.0.0-20230214024353-fa2f34755b28
github.com/vesoft-inc/nebula-go/v3 v3.6.0
github.com/vesoft-inc/nebula-go/v3 v3.6.2-0.20240108060629-6eb07e9b9e0f
golang.org/x/net v0.20.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
35 changes: 26 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,21 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/vesoft-inc/fbthrift v0.0.0-20230214024353-fa2f34755b28 h1:gpoPCGeOEuk/TnoY9nLVK1FoBM5ie7zY3BPVG8q43ME=
github.com/vesoft-inc/fbthrift v0.0.0-20230214024353-fa2f34755b28/go.mod h1:xu7e9za8StcJhBZmCDwK1Hyv4/Y0xFsjS+uqp10ECJg=
github.com/vesoft-inc/nebula-go/v3 v3.6.0 h1:ahwkfkHl9O8G07mhGi0vmnXBCcTTgZjAdPYyjQkysWI=
github.com/vesoft-inc/nebula-go/v3 v3.6.0/go.mod h1:mjMPlpNKnHYhe1pWz4caT7x9R+wKoX7dIm6u1+Rdcws=
github.com/vesoft-inc/nebula-go/v3 v3.6.2-0.20240108060629-6eb07e9b9e0f h1:X5KvPu/W6sO5NvTocDLWgn9OCUwVx6PbY16PQoEvm7E=
github.com/vesoft-inc/nebula-go/v3 v3.6.2-0.20240108060629-6eb07e9b9e0f/go.mod h1:YTNAQzimjXLXUaEDOzty/eCCye+9zkZRuUzXz9LQUpU=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -102,15 +105,19 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -121,24 +128,34 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
Expand Down
51 changes: 31 additions & 20 deletions internal/clients/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ const (
)

type MetaConfig struct {
GitInfoSHA string
HBInterval int
MetaAddr *nebula.HostAddr // meta service address to connect
AgentAddr *nebula.HostAddr // info to be reported to the meta service
TLSConfig *tls.Config
GitInfoSHA string
HBInterval int
MetaAddr *nebula.HostAddr // meta service address to connect
AgentAddr *nebula.HostAddr // info to be reported to the meta service
TLSConfig *tls.Config
HandShakeKey string
}

func NewMetaConfig(agentAddr, metaAddr, gitSHA string, hbInterval int, tlsConfig *tls.Config) (*MetaConfig, error) {
func NewMetaConfig(agentAddr, metaAddr, gitSHA, handshakeKey string, hbInterval int, tlsConfig *tls.Config) (*MetaConfig, error) {
cfg := &MetaConfig{
GitInfoSHA: gitSHA,
HBInterval: hbInterval,
TLSConfig: tlsConfig,
GitInfoSHA: gitSHA,
HBInterval: hbInterval,
TLSConfig: tlsConfig,
HandShakeKey: handshakeKey,
}
var err error

Expand Down Expand Up @@ -61,7 +63,7 @@ func NewMeta(config *MetaConfig) (*NebulaMeta, error) {
}
var err error

if m.client, err = connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig); err != nil {
if m.client, err = connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig, m.config.HandShakeKey); err != nil {
return nil, err
}

Expand All @@ -73,7 +75,7 @@ func NewMeta(config *MetaConfig) (*NebulaMeta, error) {
// We will reconnect when:
// 1. the meta service leader changed
// 2. get individual info from individual meta service, such as dir info
func connect(metaAddr, agentAddr *nebula.HostAddr, tlsConfig *tls.Config) (*meta.MetaServiceClient, error) {
func connect(metaAddr, agentAddr *nebula.HostAddr, tlsConfig *tls.Config, handshakeKey string) (*meta.MetaServiceClient, error) {
addr := utils.StringifyAddr(metaAddr)
log.WithField("meta address", addr).Info("try to connect meta service")

Expand Down Expand Up @@ -104,11 +106,16 @@ func connect(metaAddr, agentAddr *nebula.HostAddr, tlsConfig *tls.Config) (*meta
return nil, err
}

req := newVerifyClientVersionReq(agentAddr)
req := newVerifyClientVersionReq(agentAddr, handshakeKey)
resp, err := client.VerifyClientVersion(req)
if err != nil || resp.Code != nebula.ErrorCode_SUCCEEDED {
log.WithError(err).WithField("addr", addr).Error("incompatible version between client and server")
if err == nil {
err = fmt.Errorf("verifyClientVersion err: %s", string(resp.GetErrorMsg()))
}

log.WithError(err).WithField("addr", metaAddr)
client.Close()

return nil, err
}

Expand Down Expand Up @@ -145,7 +152,7 @@ func (m *NebulaMeta) heartbeat() error {
for {
resp, err := m.client.AgentHeartbeat(req)
if err != nil {
c, err := connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig)
c, err := connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig, m.config.HandShakeKey)
if err != nil {
return err
}
Expand All @@ -171,7 +178,7 @@ func (m *NebulaMeta) heartbeat() error {
return LeaderNotFoundError
}
m.config.MetaAddr = resp.GetLeader()
c, err := connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig)
c, err := connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig, m.config.HandShakeKey)
if err != nil {
return err
}
Expand All @@ -190,10 +197,10 @@ func (m *NebulaMeta) heartbeat() error {

// getMetaDirInfo get individual meta dir info of given meta service.
// Because follower meta service could not report its dir info to the leader one.
func getMetaDirInfo(metaAddr, agentAddr *nebula.HostAddr, tlsConfig *tls.Config) (*nebula.DirInfo, error) {
func getMetaDirInfo(metaAddr, agentAddr *nebula.HostAddr, tlsConfig *tls.Config, handshakeKey string) (*nebula.DirInfo, error) {
log.WithField("addr", utils.StringifyAddr(metaAddr)).
Debugf("Try to get dir info from meta service: %s\n", utils.StringifyAddr(metaAddr))
c, err := connect(metaAddr, agentAddr, tlsConfig)
c, err := connect(metaAddr, agentAddr, tlsConfig, handshakeKey)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -227,7 +234,7 @@ func (m *NebulaMeta) refreshInfo(services []*meta.ServiceInfo) error {
for _, s := range services {
k := utils.StringifyAddr(s.GetAddr())
if s.GetRole() == meta.HostRole_META {
d, err := getMetaDirInfo(s.Addr, m.config.AgentAddr, m.config.TLSConfig)
d, err := getMetaDirInfo(s.Addr, m.config.AgentAddr, m.config.TLSConfig, m.config.HandShakeKey)
if err != nil {
return fmt.Errorf("get meta dir for %s failed: %w", k, err)
}
Expand All @@ -243,9 +250,13 @@ func (m *NebulaMeta) refreshInfo(services []*meta.ServiceInfo) error {
return nil
}

func newVerifyClientVersionReq(agentAddr *nebula.HostAddr) *meta.VerifyClientVersionReq {
func newVerifyClientVersionReq(agentAddr *nebula.HostAddr, handshakeKey string) *meta.VerifyClientVersionReq {
if handshakeKey == "" {
handshakeKey = nebula.Version
}

return &meta.VerifyClientVersionReq{
ClientVersion: []byte(nebula.Version),
ClientVersion: []byte(handshakeKey),
Host: agentAddr,
}
}

0 comments on commit 4451d76

Please sign in to comment.