Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options with OPA policies to nsmgr-proxy #1355

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pkg/networkservice/chains/nsmgrproxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/interdomainbypass"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/swapip"
"github.com/networkservicemesh/sdk/pkg/registry"
registryauthorize "github.com/networkservicemesh/sdk/pkg/registry/common/authorize"
"github.com/networkservicemesh/sdk/pkg/registry/common/begin"
"github.com/networkservicemesh/sdk/pkg/registry/common/clientconn"
"github.com/networkservicemesh/sdk/pkg/registry/common/clienturl"
Expand Down Expand Up @@ -73,6 +74,8 @@ type serverOptions struct {
listenOn *url.URL
authorizeServer networkservice.NetworkServiceServer
authorizeMonitorConnectionServer networkservice.MonitorConnectionServer
authorizeNSRegistryServer registryapi.NetworkServiceRegistryServer
authorizeNSERegistryServer registryapi.NetworkServiceEndpointRegistryServer
dialOptions []grpc.DialOption
dialTimeout time.Duration
}
Expand Down Expand Up @@ -129,6 +132,26 @@ func WithAuthorizeMonitorConnectionServer(authorizeMonitorConnectionServer netwo
}
}

// WithAuthorizeNSRegistryServer sets authorization NetworkServiceRegistry chain element
func WithAuthorizeNSRegistryServer(authorizeNSRegistryServer registryapi.NetworkServiceRegistryServer) Option {
if authorizeNSRegistryServer == nil {
panic("authorizeNSRegistryServer cannot be nil")
}
return func(o *serverOptions) {
o.authorizeNSRegistryServer = authorizeNSRegistryServer
}
}

// WithAuthorizeNSERegistryServer sets authorization NetworkServiceEndpointRegistry chain element
func WithAuthorizeNSERegistryServer(authorizeNSERegistryServer registryapi.NetworkServiceEndpointRegistryServer) Option {
if authorizeNSERegistryServer == nil {
panic("authorizeNSERegistryServer cannot be nil")
}
return func(o *serverOptions) {
o.authorizeNSERegistryServer = authorizeNSERegistryServer
}
}

// WithListenOn sets current listenOn url
func WithListenOn(u *url.URL) Option {
return func(o *serverOptions) {
Expand Down Expand Up @@ -164,6 +187,8 @@ func NewServer(ctx context.Context, regURL, proxyURL *url.URL, tokenGenerator to
name: "nsmgr-proxy-" + uuid.New().String(),
authorizeServer: authorize.NewServer(authorize.Any()),
authorizeMonitorConnectionServer: authmonitor.NewMonitorConnectionServer(authmonitor.Any()),
authorizeNSRegistryServer: registryauthorize.NewNetworkServiceRegistryServer(registryauthorize.Any()),
authorizeNSERegistryServer: registryauthorize.NewNetworkServiceEndpointRegistryServer(registryauthorize.Any()),
listenOn: &url.URL{Scheme: "unix", Host: "listen.on"},
mapipFilePath: "map-ip.yaml",
}
Expand Down Expand Up @@ -230,8 +255,14 @@ func NewServer(ctx context.Context, regURL, proxyURL *url.URL, tokenGenerator to
),
)

nsServerChain = chain.NewNetworkServiceRegistryServer(
opts.authorizeNSRegistryServer,
nsServerChain,
)

var nseServerChain = chain.NewNetworkServiceEndpointRegistryServer(
begin.NewNetworkServiceEndpointRegistryServer(),
opts.authorizeNSERegistryServer,
clienturl.NewNetworkServiceEndpointRegistryServer(proxyURL),
interdomainBypassNSEServer,
registryswapip.NewNetworkServiceEndpointRegistryServer(opts.openMapIPChannel(ctx)),
Expand Down