Skip to content

Commit 6cb74fb

Browse files
authored
chore(cas): allow listing services (#1016)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 43f2b44 commit 6cb74fb

File tree

1 file changed

+13
-1
lines changed
  • app/artifact-cas/internal/server

1 file changed

+13
-1
lines changed

app/artifact-cas/internal/server/grpc.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ import (
4141
"github.com/go-kratos/kratos/v2/middleware/recovery"
4242
"github.com/go-kratos/kratos/v2/transport/grpc"
4343
grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
44+
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors"
4445
protovalidateMiddleware "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/protovalidate"
46+
grpcselector "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/selector"
47+
4548
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
4649
)
4750

@@ -86,7 +89,10 @@ func NewGRPCServer(c *conf.Server, authConf *conf.Auth, byteService *service.Byt
8689

8790
// Streaming interceptors
8891
grpc.StreamInterceptor(
89-
grpc_auth.StreamServerInterceptor(jwtAuthFunc(loadPublicKey(rawKey), casJWT.SigningMethod)),
92+
grpcselector.StreamServerInterceptor(
93+
grpc_auth.StreamServerInterceptor(jwtAuthFunc(loadPublicKey(rawKey), casJWT.SigningMethod)),
94+
grpcselector.MatchFunc(allButReflectionAPI),
95+
),
9096
// grpc prometheus metrics
9197
grpc_prometheus.StreamServerInterceptor,
9298
),
@@ -146,6 +152,12 @@ func requireAuthentication() selector.MatchFunc {
146152
}
147153
}
148154

155+
// Reflection API is called by clients like grpcurl to list services
156+
// and without this selector check it would require authentication
157+
func allButReflectionAPI(_ context.Context, callMeta interceptors.CallMeta) bool {
158+
return callMeta.Service != "grpc.reflection.v1alpha.ServerReflection"
159+
}
160+
149161
// load key for verification
150162
func loadPublicKey(rawKey []byte) jwt.Keyfunc {
151163
return func(token *jwt.Token) (interface{}, error) {

0 commit comments

Comments
 (0)