Skip to content

Commit

Permalink
only lock mutex while accessing auth map on runner server (#1274)
Browse files Browse the repository at this point in the history
* only lock mutex while accessing on runner server

* move auth token check into separate func with defer mutex unlock
  • Loading branch information
James-Pickett authored Aug 1, 2023
1 parent bb28ad8 commit 55dd7bf
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions ee/desktop/runner/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,25 @@ func (ms *RunnerServer) authMiddleware(next http.Handler) http.Handler {
return
}

ms.mutex.Lock()
defer ms.mutex.Unlock()

key := ""
for k, v := range ms.desktopProcAuthTokens {
if v == authHeader[1] {
key = k
break
}
}

if key == "" {
level.Debug(ms.logger).Log("msg", "no key found for desktop auth token")
if !ms.isAuthTokenValid(authHeader[1]) {
level.Debug(ms.logger).Log("msg", "invalid desktop auth token")
w.WriteHeader(http.StatusUnauthorized)
return
}

next.ServeHTTP(w, r)
})
}

func (ms *RunnerServer) isAuthTokenValid(authToken string) bool {
ms.mutex.Lock()
defer ms.mutex.Unlock()

for _, v := range ms.desktopProcAuthTokens {
if v == authToken {
return true
}
}

return false
}

0 comments on commit 55dd7bf

Please sign in to comment.