Skip to content

Commit ca795a7

Browse files
chore(artifact-cas): precompile auth selector regexes in gRPC server
Signed-off-by: Matías Insaurralde <matias@chainloop.dev>
1 parent c266e07 commit ca795a7

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

  • app/artifact-cas/internal/server

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024 The Chainloop Authors.
2+
// Copyright 2024-2026 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -142,22 +142,22 @@ func NewGRPCServer(c *conf.Server, authConf *conf.Auth, byteService *service.Byt
142142
return srv, nil
143143
}
144144

145+
var (
146+
statusServiceOperationRegexp = regexp.MustCompile("(cas.v1.StatusService/.*)")
147+
reflectionServiceRegexp = regexp.MustCompile("(grpc.reflection.*)")
148+
)
149+
145150
func requireAuthentication() selector.MatchFunc {
146151
// Skip authentication on the status grpc service
147-
const skipRegexp = "(cas.v1.StatusService/.*)"
148-
149152
return func(ctx context.Context, operation string) bool {
150-
r := regexp.MustCompile(skipRegexp)
151-
return !r.MatchString(operation)
153+
return !statusServiceOperationRegexp.MatchString(operation)
152154
}
153155
}
154156

155157
// Reflection API is called by clients like grpcurl to list services
156158
// and without this selector check it would require authentication
157159
func allButReflectionAPI(_ context.Context, callMeta interceptors.CallMeta) bool {
158-
const skipRegexp = "(grpc.reflection.*)"
159-
r := regexp.MustCompile(skipRegexp)
160-
return !r.MatchString(callMeta.Service)
160+
return !reflectionServiceRegexp.MatchString(callMeta.Service)
161161
}
162162

163163
// load key for verification

0 commit comments

Comments
 (0)