Skip to content

Commit

Permalink
[qfix] fix empty path panic in Registry Authorize chain elements (#1403)
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Dec 19, 2022
1 parent 465077a commit beec79b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
13 changes: 13 additions & 0 deletions pkg/registry/common/authorize/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,16 @@ func getSpiffeIDFromPath(ctx context.Context, path *grpcmetadata.Path) spiffeid.
}
return id
}

func getLeftSideOfPath(path *grpcmetadata.Path) *grpcmetadata.Path {
if len(path.PathSegments) == 0 {
return &grpcmetadata.Path{
Index: 0,
PathSegments: []*grpcmetadata.PathSegment{},
}
}
return &grpcmetadata.Path{
Index: path.Index,
PathSegments: path.PathSegments[:path.Index+1],
}
}
14 changes: 2 additions & 12 deletions pkg/registry/common/authorize/ns_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ func (s *authorizeNSServer) Register(ctx context.Context, ns *registry.NetworkSe

path := grpcmetadata.PathFromContext(ctx)
spiffeID := getSpiffeIDFromPath(ctx, path)

index := path.Index
var leftSide = &grpcmetadata.Path{
Index: index,
PathSegments: path.PathSegments[:index+1],
}
leftSide := getLeftSideOfPath(path)

rawMap := getRawMap(s.nsPathIdsMap)
input := RegistryOpaInput{
Expand Down Expand Up @@ -91,12 +86,7 @@ func (s *authorizeNSServer) Unregister(ctx context.Context, ns *registry.Network

path := grpcmetadata.PathFromContext(ctx)
spiffeID := getSpiffeIDFromPath(ctx, path)

index := path.Index
var leftSide = &grpcmetadata.Path{
Index: index,
PathSegments: path.PathSegments[:index+1],
}
leftSide := getLeftSideOfPath(path)

rawMap := getRawMap(s.nsPathIdsMap)
input := RegistryOpaInput{
Expand Down
14 changes: 2 additions & 12 deletions pkg/registry/common/authorize/nse_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ func (s *authorizeNSEServer) Register(ctx context.Context, nse *registry.Network

path := grpcmetadata.PathFromContext(ctx)
spiffeID := getSpiffeIDFromPath(ctx, path)

index := path.Index
var leftSide = &grpcmetadata.Path{
Index: index,
PathSegments: path.PathSegments[:index+1],
}
leftSide := getLeftSideOfPath(path)

rawMap := getRawMap(s.nsePathIdsMap)
input := RegistryOpaInput{
Expand Down Expand Up @@ -92,12 +87,7 @@ func (s *authorizeNSEServer) Unregister(ctx context.Context, nse *registry.Netwo

path := grpcmetadata.PathFromContext(ctx)
spiffeID := getSpiffeIDFromPath(ctx, path)

index := path.Index
var leftSide = &grpcmetadata.Path{
Index: index,
PathSegments: path.PathSegments[:index+1],
}
leftSide := getLeftSideOfPath(path)

rawMap := getRawMap(s.nsePathIdsMap)
input := RegistryOpaInput{
Expand Down

0 comments on commit beec79b

Please sign in to comment.