mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-25 03:49:12 +00:00
* WIP * WIP * WIP * WIP * Update App.tsx and Header.tsx * Update createResources.go, provider.go, and 2 more files... * WIP * fix eof newlines * Fix ts imports, add readiness probe to kratos to prevent mizu being used while kratos isnt ready * cleaned code * fix install create namespace * Update package-lock.json * Update provider.go * Update provider.go * Update provider.go * Update install_controller.go * Update kratos.yml * Update start.sh * Update provider.go * Update provider.go * Update main.go, socket_routes.go, and 8 more files... * Update App.tsx * Update installRunner.go * Update App.tsx
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package middlewares
|
|
|
|
import (
|
|
"mizuserver/pkg/config"
|
|
"mizuserver/pkg/providers"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/patrickmn/go-cache"
|
|
"github.com/up9inc/mizu/shared/logger"
|
|
)
|
|
|
|
const cachedValidTokensRetainmentTime = time.Minute * 1
|
|
|
|
var cachedValidTokens = cache.New(cachedValidTokensRetainmentTime, cachedValidTokensRetainmentTime)
|
|
|
|
func RequiresAuth() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
// auth is irrelevant for ephermeral mizu
|
|
if !config.Config.StandaloneMode {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
token := c.GetHeader("x-session-token")
|
|
if token == "" {
|
|
c.AbortWithStatusJSON(401, gin.H{"error": "token header is empty"})
|
|
return
|
|
}
|
|
|
|
if _, isTokenCached := cachedValidTokens.Get(token); isTokenCached {
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
if isTokenValid, err := providers.VerifyToken(token, c.Request.Context()); err != nil {
|
|
logger.Log.Errorf("error verifying token %s", err)
|
|
c.AbortWithStatusJSON(401, gin.H{"error": "unknown auth error occured"})
|
|
return
|
|
} else if !isTokenValid {
|
|
c.AbortWithStatusJSON(401, gin.H{"error": "invalid token"})
|
|
return
|
|
}
|
|
|
|
cachedValidTokens.Set(token, true, cachedValidTokensRetainmentTime)
|
|
|
|
c.Next()
|
|
}
|
|
}
|