Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion service/websocketserver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ func (wss *WebSocketServer) handleWebSocket(w http.ResponseWriter, r *http.Reque
return
}

serviceName := strings.TrimPrefix(spiffeID.Path(), "/")
pathParts := strings.Split(spiffeID.Path(), "/")
serviceName := pathParts[len(pathParts)-1]
Comment on lines +113 to +114
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pathParts := strings.Split(spiffeID.Path(), "/")
serviceName := pathParts[len(pathParts)-1]
var serviceName string
if spiffeID.String() == wss.TokenetesSpiffeId.String() {
serviceName = common.TOKENETES_SERVICE_NAME
} else {
serviceName = extractServiceNameFromSPIFFEPath(spiffeID.Path())
}

And the function extractServiceNameFromSPIFFEPath can be:

  // extractServiceNameFromSPIFFEPath extracts the service name from a SPIFFE ID path.
  // For Kubernetes SPIFFE IDs, it looks for /sa/ pattern and extracts the service account name.
  // Falls back to the last path component if /sa/ pattern is not found.
  func extractServiceNameFromSPIFFEPath(path string) string {
      if saIndex := strings.Index(path, "/sa/"); saIndex != -1 {
          // Found /sa/ pattern, extract the service account name
          saStart := saIndex + 4 // skip "/sa/"
          pathAfterSA := path[saStart:]
          if nextSlash := strings.Index(pathAfterSA, "/"); nextSlash != -1 {
              return pathAfterSA[:nextSlash]
          }

          return pathAfterSA
      }

      // Fallback to last path component
      pathParts := strings.Split(path, "/")

      return pathParts[len(pathParts)-1]
  }


namespace := r.URL.Query().Get("namespace")
if namespace == "" {
Expand Down
Loading