Skip to content

Agent Mesh

time bound jwt check

Antonio Ojea0f2b9e1fb7b7
diff --git a/cmd/sam-hub/main.go b/cmd/sam-hub/main.go
index 06a6058d..74aff294 100644
--- a/cmd/sam-hub/main.go
+++ b/cmd/sam-hub/main.go
@@ -64,6 +64,9 @@ const (
HighWaterMark = 400
ConnGracePeriod = 1 * time.Minute
+ // Timeouts
+ JWTVerificationTimeout = 10 * time.Second
+
// Defaults
DefaultOIDCIssuer = "https://accounts.google.com"
DefaultMeshName = "public-mesh"
@@ -247,7 +250,9 @@ func (h *Hub) handleEnroll(s network.Stream) {
return
}
- claims, token, err := h.parseAndVerifyJWT(context.Background(), req.Jwt, remotePeer)
+ ctx, cancel := context.WithTimeout(context.Background(), JWTVerificationTimeout)
+ defer cancel()
+ claims, token, err := h.parseAndVerifyJWT(ctx, req.Jwt, remotePeer)
if err != nil {
logger.Errorw("JWT verification failed", "peer_id", remotePeer, "error", err)
samHubEnrollmentTotal.WithLabelValues("failed").Inc()