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 registry authorization #235

Merged
merged 2 commits into from
Dec 5, 2022
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
26 changes: 15 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"
kernelmech "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
registryapi "github.com/networkservicemesh/api/pkg/api/registry"
"github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/token"
sriovtoken "github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/token"
"github.com/networkservicemesh/sdk-sriov/pkg/tools/tokens"
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize"
Expand All @@ -65,6 +65,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam"
registryclient "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
registryauthorize "github.com/networkservicemesh/sdk/pkg/registry/common/authorize"
registrysendfd "github.com/networkservicemesh/sdk/pkg/registry/common/sendfd"
"github.com/networkservicemesh/sdk/pkg/tools/debug"
"github.com/networkservicemesh/sdk/pkg/tools/dnsconfig"
Expand All @@ -73,6 +74,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger"
"github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
"github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
"github.com/networkservicemesh/sdk/pkg/tools/token"
"github.com/networkservicemesh/sdk/pkg/tools/tracing"

"github.com/networkservicemesh/cmd-nse-vlan-vpp/pkg/networkservice/ifconfig"
Expand Down Expand Up @@ -174,25 +176,26 @@ func registerGRPCServer(tlsServerConfig *tls.Config, responderEndpoint *endpoint
return server
}

func registerEndpoint(ctx context.Context, config *Config, tlsClientConfig *tls.Config, urlStr string) error {
func registerEndpoint(ctx context.Context, config *Config, source *workloadapi.X509Source, tlsClientConfig *tls.Config, urlStr string) error {
clientOptions := append(
tracing.WithTracingDial(),
grpc.WithBlock(),
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
grpc.WithDefaultCallOptions(
grpc.WaitForReady(true),
grpc.PerRPCCredentials(token.NewPerRPCCredentials(spiffejwt.TokenGeneratorFunc(source, config.MaxTokenLifetime)))),
grpc.WithTransportCredentials(
grpcfd.TransportCredentials(
credentials.NewTLS(
tlsClientConfig,
),
),
),
credentials.NewTLS(tlsClientConfig))),
grpcfd.WithChainStreamInterceptor(),
grpcfd.WithChainUnaryInterceptor(),
)

if config.RegisterService {
for _, serviceName := range config.ServiceNames {
nsRegistryClient := registryclient.NewNetworkServiceRegistryClient(ctx,
registryclient.WithClientURL(&config.ConnectTo),
registryclient.WithDialOptions(clientOptions...))
registryclient.WithDialOptions(clientOptions...),
registryclient.WithAuthorizeNSRegistryClient(registryauthorize.NewNetworkServiceRegistryClient()))
_, err := nsRegistryClient.Register(ctx, &registryapi.NetworkService{
Name: serviceName,
Payload: config.Payload,
Expand All @@ -211,6 +214,7 @@ func registerEndpoint(ctx context.Context, config *Config, tlsClientConfig *tls.
registryclient.WithNSEAdditionalFunctionality(
registrysendfd.NewNetworkServiceEndpointRegistryClient(),
),
registryclient.WithAuthorizeNSERegistryClient(registryauthorize.NewNetworkServiceEndpointRegistryClient()),
)
nse := &registryapi.NetworkServiceEndpoint{
Name: config.Name,
Expand Down Expand Up @@ -341,7 +345,7 @@ func main() {
// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 7: register nse with nsm")
// ********************************************************************************
err = registerEndpoint(ctx, config, tlsClientConfig, listenOn.String())
err = registerEndpoint(ctx, config, source, tlsClientConfig, listenOn.String())
if err != nil {
log.FromContext(ctx).Fatalf("failed to connect to registry: %+v", err)
}
Expand All @@ -362,7 +366,7 @@ func getSriovTokenVlanServerChainElement(tokenKey string) (tokenServer networkse
} else {
tokenServer = chain.NewNetworkServiceServer(
vlan.NewServer(),
token.NewServer(tokenKey))
sriovtoken.NewServer(tokenKey))
}
return
}
Expand Down