Coder Social home page Coder Social logo

sdk's Introduction

Network Service Mesh sdk

This repo is for platform independent sdk code

For platform specific sdk code, please see the sdk-${platform} repos:

sdk's People

Contributors

anastasia-malysheva avatar bszirtes avatar caboteria avatar d-uzlov avatar denis-tingaikin avatar dependabot[bot] avatar dualbreath avatar edwarnicke avatar ekanufrienko avatar fkautz avatar glazychev-art avatar haiodo avatar jellonek avatar lazyniv avatar lioneljouin avatar ljkiraly avatar lobkovilya avatar lvfxx avatar marinashustowa avatar mixaster995 avatar nikitaskrynnik avatar nsmbot avatar pperiyasamy avatar semenov-spirent avatar sol-0 avatar tiberivs avatar tigrulya-exe avatar vitalygushin avatar wazsone avatar xzfc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sdk's Issues

Generalize authorize chain element

The current chain element looks only at the last token in the path chain. This is insufficient for the full spectrum of policy we are likely to want to enforce.

Expand on the authorize chain element by providing as its 'input' object:

  1. The Connection
  2. The TLSInfo (as retrieved by peer.FromContext for Server or grpc.Peer for the client)
  3. Operation - One of Request/Close
  4. Role - One of Client/Endpoint

Create exclude prefixes SDK chain elements.

We need exclude prefixes Chain element for server.

As well we need exclude prefixes application to listen for Kubernetes network prefixes and CRD and update resource. Chain element should periodically track resource state and re-read exclude prefixes.

Adapters ignores context from adpated client/server

Problem statement

We need to store context from the adapter server/client and pass it to the next client/server to avoid the problem with losing
values from adapted server/client context.

Note: Here we are passing context https://github.com/networkservicemesh/sdk/blob/master/pkg/networkservice/core/adapters/client_to_server.go#L41
and actually all values from the chain are losing.

Solution

  1. Use here reference to the context instead of boolean flag and apply changes to fix compilation errors
  2. Pass context from the adapted chain serve/client to the next client/server.
  3. Add test to cover

Sometimes unit test 'TestNewClient_StopRefreshAtClose' has goroutine leak

Context

https://github.com/networkservicemesh/sdk/pull/227/checks?check_run_id=645773960

Failure logs

##[error]    leaks.go:78: found unexpected goroutines:
        [Goroutine 62 in state chan send, with github.com/networkservicemesh/sdk/pkg/networkservice/common/refresh_test.TestNewClient_StopRefreshAtClose.func1 on top of the stack:
        goroutine 62 [chan send]:
        github.com/networkservicemesh/sdk/pkg/networkservice/common/refresh_test.TestNewClient_StopRefreshAtClose.func1(0x18d8e20, 0xc000154120, 0xc000180280, 0x0, 0x0, 0x0, 0x1180c0b, 0xc000154140, 0xc000154120)
        	/Users/runner/runners/2.169.1/work/sdk/sdk/pkg/networkservice/common/refresh/client_test.go:97 +0x78
        github.com/networkservicemesh/sdk/pkg/networkservice/common/refresh_test.(*testRefresh).Request(0xc000010280, 0x18d8e20, 0xc000154120, 0xc000180280, 0x0, 0x0, 0x0, 0xc000154120, 0x18d21a0, 0xc000108b70)
        	/Users/runner/runners/2.169.1/work/sdk/sdk/pkg/networkservice/common/refresh/client_test.go:67 +0x96
        github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Request(0xc000108b70, 0x18d8f60, 0xc000152100, 0xc000180280, 0x0, 0x0, 0x0, 0x106989c, 0xc000152100, 0xc000048c00)
        	/Users/runner/runners/2.169.1/work/sdk/sdk/pkg/networkservice/core/next/client.go:70 +0x5fb
        github.com/networkservicemesh/sdk/pkg/networkservice/common/refresh.(*refreshClient).Request(0xc00000ee20, 0x18d8f60, 0xc000152100, 0xc000180280, 0x0, 0x0, 0x0, 0xc0001c8218, 0x1092790, 0xc0001c81c0)
        	/Users/runner/runners/2.169.1/work/sdk/sdk/pkg/networkservice/common/refresh/client.go:53 +0xaa
        github.com/networkservicemesh/sdk/pkg/networkservice/common/refresh.(*refreshClient).createTimer.func1()
        	/Users/runner/runners/2.169.1/work/sdk/sdk/pkg/networkservice/common/refresh/client.go:96 +0x183
        created by time.goFunc
        	/Users/runner/hostedtoolcache/go/1.13.4/x64/src/time/sleep.go:168 +0x52
        ]


Create DNSContext NetworkServiceClient chain element

Description

Previously we had added DNSContext server chain element: #74

We need also to create in pkg/networkservice/connectioncontext/dnscontext/ a NetworkServiceClient chain element appropriate for getting a DNSContext for clients.

This part was blocked by #48

Registry: add resources cleanup chain element

Motivation

With the new registry model, we need to add a chain element to manage NSM resources(NSs,NSEs). This component should do next things:

  1. Deleting NS if the registry has not NSE entries that provide this NS.
  2. Deleting NSE if achieved expiration time.

Default Policy examples

We need default OPA Policies based upon the update in input found in #200

Among the examples we'd want:

  1. Tokens valid - checks the validity of some or all of the tokens in the path.
  2. No Tokens in path expired - none of the tokens in the chain are expired.
  3. Last Token matches TLSInfo - checks to make sure that the Last Token (JWT) is signed by the same cert as found in TLSInfo.
  4. Token.Aud for token n in path matches Token.Sub for n+1 token in chain

Create Cross connect chain elements

We need a cross connect chain element to perform call from NSmgr to cross connect and handle requests from cross connect and and forward connection to endpoint or next nsmgr.

image

Add OPA policies for NSM registries

Motivation

Probably we need to add authorization policies for NSM registries to cover scenarios such as

  1. NSE/NSMgr/xconnNSE should be able to unregister only itself. NSE/NSMgr/xconn NSE should not be able to unregister another NSE/NSMgr/xconn NSE.
  2. Only NSMgr/vl3 NSE should be able to search NSE in the registry.
  3. Only NSMgr and other registries can use Bulk API.

Problem of implementation

We need to somehow pass Path data or other authorization data to registries.

Potential solution

We can use pkg grpc/metadata for passing authorization data for registries.

import "google.golang.org/grpc/metadata"
...  
ctx = metadata.NewContext( 
    ctx, 
    metadata.Pairs("path-data", "data"), 
) 

Add tools/xconnectnse to help register/find/unregister xconnectnses

Motivation

We need to add possible to register xconnect nses in the registry.

Solution

Add tools/xconnectnse pkg and add a function that expects URL to registry and URL to xconnect nse.

package xconnectnse

Register(client, registry.NetworkServiceRegistryClient, name string,  xconnectnseURL *url.URL, ) error {
//TODO implement function here
}

Unregister(client, registry.NetworkServiceRegistryClient, name string,  xconnectnseURL *url.URL, ) error {
//TODO implement function here
}

Find(client registry.NetworkServiceRegistryClient) []registry.NetworkServiceEdnpoint {
}

OR

Add registry/xconnnse client chain element that will simply fill needed fields and pass it to next client (real registry client)

Define and implement example/test OPA use cases.

Initial OPA implementation is currently in the repo with a simple use case.

  1. Define example use cases that we want to cover with OPA
  2. For each use case, attempt to implement the policy. Document the results and gaps.
  3. For each use case where a gap, expand OPA support.

Flaky test TestNewClient_MissingConnectionsInInit in pkg/networkservice/common/heal

Sometimes PASS, sometimes FAIL. @alex-yust reproduced it locally too
attach test log:

=== Failed
=== FAIL: pkg/networkservice/common/heal TestNewClient_MissingConnectionsInInit (0.03s)
time="2020-02-21T08:21:46Z" level=info msg="Creating new eventReceiver"
time="2020-02-21T08:21:46Z" level=info msg="==--> *healClient.Request() span:{}"
time="2020-02-21T08:21:46Z" level=info msg=">><<-- request={\"connection\":{\"id\":\"conn-1\",\"network_service\":\"ns-1\"}} span={}"
time="2020-02-21T08:21:46Z" level=info msg=">><<-- response={\"id\":\"conn-1\",\"network_service\":\"ns-1\"} span={}"
time="2020-02-21T08:21:46Z" level=info msg="==--> *healClient.Request() span:{}"
time="2020-02-21T08:21:46Z" level=info msg=">><<-- request={\"connection\":{\"id\":\"conn-2\",\"network_service\":\"ns-2\"}} span={}"
time="2020-02-21T08:21:46Z" level=info msg=">><<-- response={\"id\":\"conn-2\",\"network_service\":\"ns-2\"} span={}"
    client_test.go:238: 
        	Error Trace:	client_test.go:238
        	Error:      	Should be true
        	Test:       	TestNewClient_MissingConnectionsInInit

Add registry memory chain components

Motivation

The main idea to create chain components to be able to build analogies registries like nsmd-k8s via SDK and be not dependent on Kubernetes staff.

Memory registries could be useful for the next goals:

  1. Testing cmd application which depends on nsmd-k8s. For example cmd-nsmgr.
  2. Building nsm registries application which not depend on Kubernetes.

Create authorization registry chain elements.

This is a followup for after #45.

We will also need authorization chain elements for connection.MonitorNetworkServiceServer and connection.MonitorNetworkServiceClient.

Please put them in the pkg/registry/common/ subdir

Registry: Add cache chain elements

Description

We need to migrate our caches components from monorepo to SDK. Should be created caches components for next registry models:

  • registry.NetworkServiceEndpoint
  • registry.NetworkService

NOTE: these components should not depend on k8s.

Use case

  1. The user calls method Find on his client with the query.
  2. If the cache has querying entry then it returns entry as a response.

Registry caches should be based on LRU caches to minimalize resource usage on the client-side.

Create monitor core chain elements

Create in pkg/connection/core/ the analog: next, chain, adapters and trace chain elements for MonitorConnection{Server,Client}.

See pkg/*/core for examples for other APIs.

Interdomain: add registry chain element to proxying registration/find/unregistration to next registry

Context

#235

Description

We need to add possible to registries proxy all incoming registrations/unregistratiom/find to the next registry.

Use-case:

  1. The registry receives registration with a special symbol in the name "@" or special label in labels.
  2. The registry just proxying this traffic to the next registry.

Questions:

Do we want to use special symbol "@" in ns/nse name to mark it as interdomain? As an alternative variant, we can add special labels for nse. For example:

nse:
  name:
  labels:
   icmp-responder:
     k:v
   interdomain:
     k:v

Create authorization monitor chain elements

This is a followup for after #45.

We will also need authorization chain elements for connection.MonitorNetworkServiceServer and connection.MonitorNetworkServiceClient.

Please put them in the pkg/connection/common subdir (as they are part of the connection API).

Registry: add join chain element

Description

Registry join chain element will add a possible to aggregate a few registry clients to one. It will be useful for cmd-nsmgr. For example, we can join memory registry and real registry client.

Expand OPA into several pieces

The current authorization chain element provides only policy handling but not building. We need to expand the OPA mechanism into several pieces:

  1. Builder mechanism which builds the provided policy (e.g. from yaml config file or string)
  2. Handler mechanism which handles the building policies.

For example in pseudocode it might look like:

b := NewBuilder(configFile, elseOption...)
handler := b.Validate() //building the provided policy
ok := handler.eval(opaInputObj) //get the policy decision 

Add benchmark testing on CI

We need to add benchmark testing on CI. We already have benchmark tests but they not run on CI: pkg/tools/serialize/serialize_test.go

Improve performance of chain of adapters + next

Description

Chain of next + adapters elements can produce extra adapters per each of the chain elements.

For example:
If we have a chain of

server->adapted client->server->server

then it can be represented on call Request/Register/Close:

server->adapted client->adapted server->adapted server

We need to investigate and fix extra adaptation.

Interdomain: add registry connect chain element

Context

#235

Description

Proxy registry should be able to connect to the registry from another domain by the domain name.

Solution

Add analog of chain element connect for registries.

Example of usage:

  1. Proxy registry receives query with network service name = [email protected].
  2. Proxy registry resolves domain my.domain to IP.
  3. Proxy registry connects to the next registry by IP from step2.

Stabilize heal tests

Problem statement

After the latest merges, we faced new unstable heal tests:

TestHealClient_Request
TestNewClient_MissingConnectionsInInit

Logs

=== Failed
=== FAIL: pkg/networkservice/common/heal TestHealClient_Request (0.07s)
    client_test.go:116: 
        	Error Trace:	client_test.go:116
        	Error:      	Condition never satisfied
        	Test:       	TestHealClient_Request

=== FAIL: pkg/networkservice/common/heal TestNewClient_MissingConnectionsInInit (0.12s)
    client_test.go:217: 
        	Error Trace:	client_test.go:217
        	Error:      	Condition never satisfied
        	Test:       	TestNewClient_MissingConnectionsInInit

Link to CI job

https://github.com/networkservicemesh/sdk/runs/854630760?check_suite_focus=true

pkg/core/adapters can not be used with pkg/next

Actual behavior

pkg/core/adapters can adapt the server to client or vice versa, but if a server uses pkg/next then the adapters will not correctly adapt the server to client and it will panic on called Request/Close

Expected behavior

pkg/core/adapters can be used with pkg/next.

Steps to reproduce

  1. Adapt server which uses next.Server(...) to client or vice versa
  2. Try to call client.Request() or client.Close()`

Code example:
server.go

type configServer struct{}

// NewServer - inserts a vppagent *configurator.Config into the GRPC call context.Context
func NewServer() networkservice.NetworkServiceServer {
	return &configServer{}
}

func (c *configServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*connection.Connection, error) {
	return next.Server(ctx).Request(ctx, request)
}

func (c *configServer) Close(ctx context.Context, conn *connection.Connection) (*empty.Empty, error) {
	return next.Server(ctx).Close(ctx, conn)
}

client_test.go

func TestClientBasic(t *testing.T) {
	next.NewNetworkServiceClient(NewServerToClient(&configServer{})).Close(nil, nil, nil)
}

Example from sdk-vppagent:
https://github.com/networkservicemesh/sdk-vppagent/blob/master/pkg/networkservice/vppagent/client.go

Stacktrace

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x9c1110]

goroutine 6 [running]:
testing.tRunner.func1(0xc000140100)
	/usr/local/go/src/testing/testing.go:874 +0x60f
panic(0xa48b00, 0xeba540)
	/usr/local/go/src/runtime/panic.go:679 +0x1e0
github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters.testServer.Close(0xb81160, 0xc0001344b0, 0x0, 0x0, 0x0, 0x0)
	/home/user/go/src/github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters/client_test.go:21 +0x80
github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters.(*serverToClient).Close(0xc00007b910, 0xb81160, 0xc0001344b0, 0x0, 0xc00007b930, 0x1, 0x1, 0x0, 0x0, 0x0)
	/home/user/go/src/github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters/server_to_client.go:44 +0x8a
github.com/networkservicemesh/sdk/pkg/networkservice/core/next.(*nextClient).Close(0xc00000eb20, 0x0, 0x0, 0x0, 0xc00007b930, 0x1, 0x1, 0x0, 0x0, 0x0)
	/home/user/go/src/github.com/networkservicemesh/sdk/pkg/networkservice/core/next/client.go:67 +0x369
github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters.TestClientBasic(0xc000140100)
	/home/user/go/src/github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters/client_test.go:25 +0x1c0
testing.tRunner(0xc000140100, 0xb054d8)
	/usr/local/go/src/testing/testing.go:909 +0x13c
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:960 +0x64f

next::Client doesn't work with chained elements

Motivation

When we pass the chained client element into next.NewNetworkServiceClient(), unexpected behaviour may occur in next.Request -- it will be impossible to make request through all the clients in the chain.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.