Skip to content

Commit 5b4631b

Browse files
authored
chore: clean up managedFields from k8s objects from UI display (numaproj#3098)
Signed-off-by: Derek Wang <whynowy@gmail.com>
1 parent bc4fab6 commit 5b4631b

11 files changed

Lines changed: 1780 additions & 82 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ jobs:
188188
timeout-minutes: 20
189189
strategy:
190190
fail-fast: false
191+
max-parallel: 13
191192
matrix:
192193
driver: [jetstream]
193194
case:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ require (
3434
github.com/spf13/cobra v1.8.1
3535
github.com/spf13/viper v1.18.2
3636
github.com/stretchr/testify v1.11.1
37+
github.com/tidwall/gjson v1.18.0
3738
github.com/xdg-go/scram v1.1.2
3839
go.opentelemetry.io/contrib/bridges/prometheus v0.63.0
3940
go.opentelemetry.io/otel v1.38.0
@@ -173,7 +174,6 @@ require (
173174
github.com/spf13/pflag v1.0.5 // indirect
174175
github.com/stretchr/objx v0.5.2 // indirect
175176
github.com/subosito/gotenv v1.6.0 // indirect
176-
github.com/tidwall/gjson v1.14.4 // indirect
177177
github.com/tidwall/match v1.1.1 // indirect
178178
github.com/tidwall/pretty v1.2.0 // indirect
179179
github.com/toqueteos/webbrowser v1.2.0 // indirect

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,9 @@ github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD
579579
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
580580
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
581581
github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502/go.mod h1:p9lPsd+cx33L3H9nNoecRRxPssFKUwwI50I3pZ0yT+8=
582-
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
583582
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
583+
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
584+
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
584585
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
585586
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
586587
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=

server/routes/auth_middleware.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
Copyright 2022 The Numaproj Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package routes
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"net/http"
23+
24+
"github.com/gin-gonic/gin"
25+
"github.com/numaproj/numaflow/pkg/shared/logging"
26+
v1 "github.com/numaproj/numaflow/server/apis/v1"
27+
"github.com/numaproj/numaflow/server/authn"
28+
"github.com/numaproj/numaflow/server/authz"
29+
"github.com/numaproj/numaflow/server/common"
30+
)
31+
32+
// authMiddleware is the middleware for AuthN/AuthZ.
33+
// it ensures the user is authenticated and authorized
34+
// to execute the requested action before sending the request to the api handler.
35+
func authMiddleware(ctx context.Context, authorizer authz.Authorizer, dexAuthenticator authn.Authenticator, localUsersAuthenticator authn.Authenticator, authRouteMap authz.RouteMap) gin.HandlerFunc {
36+
37+
return func(c *gin.Context) {
38+
39+
log := logging.FromContext(ctx)
40+
var userInfo *authn.UserInfo
41+
42+
loginType, err := c.Cookie(common.LoginCookieName)
43+
if err != nil {
44+
errMsg := fmt.Sprintf("Failed to get login type: %v", err)
45+
c.JSON(http.StatusUnauthorized, v1.NewNumaflowAPIResponse(&errMsg, nil))
46+
c.Abort()
47+
return
48+
}
49+
50+
// Authenticate the user based on the login type.
51+
switch loginType {
52+
case "dex":
53+
userInfo, err = dexAuthenticator.Authenticate(c)
54+
case "local":
55+
userInfo, err = localUsersAuthenticator.Authenticate(c)
56+
default:
57+
errMsg := fmt.Sprintf("unidentified login type received: %v", loginType)
58+
c.JSON(http.StatusUnauthorized, v1.NewNumaflowAPIResponse(&errMsg, nil))
59+
c.Abort()
60+
return
61+
}
62+
if err != nil {
63+
errMsg := fmt.Sprintf("Failed to authenticate user: %v", err)
64+
c.JSON(http.StatusUnauthorized, v1.NewNumaflowAPIResponse(&errMsg, nil))
65+
c.Abort()
66+
return
67+
}
68+
// Check if the route requires authorization.
69+
if authRouteMap.GetRouteFromContext(c) != nil && authRouteMap.GetRouteFromContext(c).RequiresAuthZ {
70+
// Check if the user is authorized to execute the requested action.
71+
isAuthorized := authorizer.Authorize(c, userInfo)
72+
if isAuthorized {
73+
// If the user is authorized, continue the request.
74+
c.Next()
75+
} else {
76+
// If the user is not authorized, return an error.
77+
errMsg := "user is not authorized to execute the requested action"
78+
c.JSON(http.StatusForbidden, v1.NewNumaflowAPIResponse(&errMsg, nil))
79+
c.Abort()
80+
}
81+
} else if authRouteMap.GetRouteFromContext(c) != nil && !authRouteMap.GetRouteFromContext(c).RequiresAuthZ {
82+
// If the route does not require AuthZ, skip the AuthZ check.
83+
c.Next()
84+
} else {
85+
// If the route is not present in the route map, return an error.
86+
log.Errorw("route not present in routeMap", "route", authz.GetRouteMapKey(c))
87+
errMsg := "Invalid route"
88+
c.JSON(http.StatusForbidden, v1.NewNumaflowAPIResponse(&errMsg, nil))
89+
c.Abort()
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)