Skip to content

Commit

Permalink
Merge pull request #407 from NikitaSkrynnik/authorize
Browse files Browse the repository at this point in the history
Add registry authorization
  • Loading branch information
denis-tingaikin authored Dec 5, 2022
2 parents 4701a2f + 569ba06 commit 2fa0a01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions internal/imports/imports_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
_ "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/authorize"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/begin"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/clientinfo"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/expire"
Expand All @@ -34,6 +35,7 @@ import (
_ "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
_ "github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"
_ "github.com/networkservicemesh/sdk/pkg/tools/spire"
_ "github.com/networkservicemesh/sdk/pkg/tools/token"
_ "github.com/networkservicemesh/sdk/pkg/tools/tracing"
_ "github.com/pkg/errors"
_ "github.com/sirupsen/logrus"
Expand Down
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
registryclient "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
registryauthorize "github.com/networkservicemesh/sdk/pkg/registry/common/authorize"
"github.com/networkservicemesh/sdk/pkg/registry/common/clientinfo"
"github.com/networkservicemesh/sdk/pkg/registry/common/sendfd"
"github.com/networkservicemesh/sdk/pkg/tools/debug"
Expand All @@ -54,6 +55,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-vfio/internal/config"
Expand Down Expand Up @@ -192,17 +194,24 @@ func main() {
clientOptions := append(
tracing.WithTracingDial(),
grpc.WithBlock(),
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
grpc.WithDefaultCallOptions(
grpc.WaitForReady(true),
grpc.PerRPCCredentials(token.NewPerRPCCredentials(spiffejwt.TokenGeneratorFunc(source, cfg.MaxTokenLifetime)))),
grpc.WithTransportCredentials(
grpcfd.TransportCredentials(
credentials.NewTLS(
tlsClientConfig,
),
),
),
grpcfd.WithChainStreamInterceptor(),
grpcfd.WithChainUnaryInterceptor(),
)

nsRegistryClient := registryclient.NewNetworkServiceRegistryClient(ctx, registryclient.WithClientURL(&cfg.ConnectTo), registryclient.WithDialOptions(clientOptions...))
nsRegistryClient := registryclient.NewNetworkServiceRegistryClient(ctx,
registryclient.WithClientURL(&cfg.ConnectTo),
registryclient.WithDialOptions(clientOptions...),
registryclient.WithAuthorizeNSRegistryClient(registryauthorize.NewNetworkServiceRegistryClient()))
for i := range cfg.Services {
nsName := cfg.Services[i].Name
nsPayload := cfg.Services[i].Payload
Expand All @@ -222,6 +231,7 @@ func main() {
clientinfo.NewNetworkServiceEndpointRegistryClient(),
sendfd.NewNetworkServiceEndpointRegistryClient(),
),
registryclient.WithAuthorizeNSERegistryClient(registryauthorize.NewNetworkServiceEndpointRegistryClient()),
)
nse, err := nseRegistryClient.Register(ctx, registryEndpoint(listenOn, cfg))
if err != nil {
Expand Down

0 comments on commit 2fa0a01

Please sign in to comment.