mirror of
https://github.com/labring/sealos.git
synced 2026-09-21 05:44:43 +08:00
fix: empty subnet (#5426)
This commit is contained in:
@@ -75,19 +75,21 @@ func TokenAuth(c *gin.Context) {
|
||||
|
||||
SetLogTokenFields(log.Data, token, useInternalToken)
|
||||
|
||||
if ok, err := network.IsIPInSubnets(c.ClientIP(), token.Subnets); err != nil {
|
||||
abortLogWithMessage(c, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
} else if !ok {
|
||||
abortLogWithMessage(c, http.StatusForbidden,
|
||||
fmt.Sprintf("token (%s[%d]) can only be used in the specified subnets: %v, current ip: %s",
|
||||
token.Name,
|
||||
token.ID,
|
||||
token.Subnets,
|
||||
c.ClientIP(),
|
||||
),
|
||||
)
|
||||
return
|
||||
if len(token.Subnets) > 0 {
|
||||
if ok, err := network.IsIPInSubnets(c.ClientIP(), token.Subnets); err != nil {
|
||||
abortLogWithMessage(c, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
} else if !ok {
|
||||
abortLogWithMessage(c, http.StatusForbidden,
|
||||
fmt.Sprintf("token (%s[%d]) can only be used in the specified subnets: %v, current ip: %s",
|
||||
token.Name,
|
||||
token.ID,
|
||||
token.Subnets,
|
||||
c.ClientIP(),
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var group *model.GroupCache
|
||||
|
||||
Reference in New Issue
Block a user