Skip to content

Commit 643cf11

Browse files
Update resource summaries only if user has permission. (#301)
Signed-off-by: Rokibul Hasan <[email protected]> Signed-off-by: Tamal Saha <[email protected]> Co-authored-by: Tamal Saha <[email protected]>
1 parent 0492e26 commit 643cf11

File tree

7 files changed

+20
-12
lines changed

7 files changed

+20
-12
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ require (
4343
k8s.io/kube-openapi v0.0.0-20240430033511-f0e62f92d13f
4444
k8s.io/kube-state-metrics/v2 v2.7.0
4545
kmodules.xyz/apiversion v0.2.0
46-
kmodules.xyz/authorizer v0.29.0
46+
kmodules.xyz/authorizer v0.29.1
4747
kmodules.xyz/client-go v0.30.0
4848
kmodules.xyz/custom-resources v0.29.1
4949
kmodules.xyz/go-containerregistry v0.0.12

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,8 @@ k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCI
907907
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
908908
kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
909909
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
910-
kmodules.xyz/authorizer v0.29.0 h1:ND8YGeyzExdZ8Bq5Z6UdFO794I6+oPuXbUMWyjlsYgM=
911-
kmodules.xyz/authorizer v0.29.0/go.mod h1:UQmE3sNXeliebUqjEeD9QYiY+Na27/C5Bg/ekVRfQ3U=
910+
kmodules.xyz/authorizer v0.29.1 h1:uByGGoryKbZcfiEAhjcK/Y345I9mygNQP7DVpkMbNQQ=
911+
kmodules.xyz/authorizer v0.29.1/go.mod h1:kZRhclL8twzyt2bQuJQJbpYww2sc+qFr8I5PPoq/sWY=
912912
kmodules.xyz/client-go v0.30.0 h1:sEGX5DRXQwJiMxcN2DkDtXz9WsSA6fs9ye86RgbAxeo=
913913
kmodules.xyz/client-go v0.30.0/go.mod h1:ekDSUC0UFLI0Jq3A62myW7VG8TYLBqCwMjqWJM1SrqU=
914914
kmodules.xyz/crd-schema-fuzz v0.29.1 h1:zJTlWYOrT5dsVVHW8HGcnR/vaWfxQfNh11QwTtkYpcs=

pkg/registry/core/genericresource/storage.go

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ func (r *Storage) List(ctx context.Context, options *internalversion.ListOptions
149149
if !ok {
150150
return nil, apierrors.NewBadRequest("missing namespace")
151151
}
152-
153152
selector := shared.NewGroupKindSelector(options.LabelSelector)
154153

155154
user, ok := apirequest.UserFrom(ctx)

pkg/registry/core/resourcesummary/storage.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ func (r *Storage) List(ctx context.Context, options *internalversion.ListOptions
157157
if err := r.kc.List(ctx, &list, client.InNamespace(ns)); err != nil {
158158
return nil, err
159159
}
160+
161+
// hasPermission to check if the user has permission to list the resources
162+
hasPermission := false
160163
for _, item := range list.Items {
161164
attrs.Name = item.GetName()
162165
attrs.Namespace = item.GetNamespace()
@@ -168,6 +171,7 @@ func (r *Storage) List(ctx context.Context, options *internalversion.ListOptions
168171
continue
169172
}
170173

174+
hasPermission = true
171175
content := item.UnstructuredContent()
172176
{
173177
rv, err := resourcemetrics.TotalResourceRequests(content)
@@ -199,7 +203,9 @@ func (r *Storage) List(ctx context.Context, options *internalversion.ListOptions
199203
}
200204
}
201205

202-
summary.Spec.Count = len(list.Items)
206+
if hasPermission {
207+
summary.Spec.Count = len(list.Items)
208+
}
203209
items = append(items, summary)
204210
}
205211
sort.Slice(items, func(i, j int) bool {

vendor/kmodules.xyz/authorizer/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ BIN_PLATFORMS := $(DOCKER_PLATFORMS)
5555
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
5656
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
5757

58-
BASEIMAGE_PROD ?= gcr.io/distroless/static-debian11
59-
BASEIMAGE_DBG ?= debian:bullseye
58+
BASEIMAGE_PROD ?= gcr.io/distroless/static-debian12
59+
BASEIMAGE_DBG ?= debian:bookworm
6060

61-
GO_VERSION ?= 1.21
61+
GO_VERSION ?= 1.22
6262
BUILD_IMAGE ?= ghcr.io/appscode/golang-dev:$(GO_VERSION)
6363

6464
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
@@ -225,7 +225,7 @@ test: $(BUILD_DIRS)
225225
./hack/test.sh $(SRC_PKGS) \
226226
"
227227

228-
ADDTL_LINTERS := goconst,gofmt,goimports,unparam
228+
ADDTL_LINTERS := gofmt,goimports,unparam
229229

230230
.PHONY: lint
231231
lint: $(BUILD_DIRS)

vendor/kmodules.xyz/authorizer/apiserver/authorizer.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,8 @@ func (a APIAuthorizer) Authorize(ctx context.Context, attrs authorizer.Attribute
7575
if sar.Status.Denied {
7676
return authorizer.DecisionDeny, sar.Status.Reason, nil
7777
}
78-
return authorizer.DecisionNoOpinion, sar.Status.Reason, errors.New(sar.Status.EvaluationError)
78+
if sar.Status.EvaluationError != "" {
79+
return authorizer.DecisionNoOpinion, sar.Status.Reason, errors.New(sar.Status.EvaluationError)
80+
}
81+
return authorizer.DecisionNoOpinion, sar.Status.Reason, nil
7982
}

vendor/modules.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1913,8 +1913,8 @@ k8s.io/utils/trace
19131913
# kmodules.xyz/apiversion v0.2.0
19141914
## explicit; go 1.14
19151915
kmodules.xyz/apiversion
1916-
# kmodules.xyz/authorizer v0.29.0
1917-
## explicit; go 1.21.5
1916+
# kmodules.xyz/authorizer v0.29.1
1917+
## explicit; go 1.22.0
19181918
kmodules.xyz/authorizer
19191919
kmodules.xyz/authorizer/apiserver
19201920
kmodules.xyz/authorizer/rbac

0 commit comments

Comments
 (0)