@@ -2,6 +2,8 @@ package tests
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
6
+ "strings"
5
7
"time"
6
8
7
9
. "github.com/onsi/ginkgo/v2"
@@ -147,6 +149,34 @@ var _ = Describe("Aggregated role in-action tests", Serial, func() {
147
149
Entry ("[test_id:3949]can do everything with edit" , "edit" ),
148
150
)
149
151
152
+ DescribeTable ("check all user facing resources can be manipulated by non-cluster-admin" , func (user string ) {
153
+ var namespacedCDIAPIResourcesPlural []string
154
+ // Also retrieves API resources that are not served via CRDs
155
+ outputAPIResources , err := f .RunKubectlCommand ("api-resources" , "--namespaced" , "-o" , "name" )
156
+ Expect (err ).ToNot (HaveOccurred (), "ERR: %s, OUT: %s" , err , outputAPIResources )
157
+ for _ , apiResource := range strings .Split (strings .TrimSpace (outputAPIResources ), "\n " ) {
158
+ if strings .HasSuffix (apiResource , "cdi.kubevirt.io" ) {
159
+ plural := strings .Split (apiResource , "." )[0 ]
160
+ namespacedCDIAPIResourcesPlural = append (namespacedCDIAPIResourcesPlural , plural )
161
+ }
162
+ }
163
+ fmt .Fprintf (GinkgoWriter , "CDI namespaced API resources: %+v\n " , namespacedCDIAPIResourcesPlural )
164
+ Expect (len (namespacedCDIAPIResourcesPlural )).To (BeNumerically (">=" , 5 ))
165
+
166
+ createServiceAccount (f .K8sClient , f .Namespace .Name , user )
167
+ createRoleBinding (f .K8sClient , user , f .Namespace .Name , user )
168
+
169
+ for _ , resource := range namespacedCDIAPIResourcesPlural {
170
+ sa := fmt .Sprintf ("system:serviceaccount:%s:%s" , f .Namespace .Name , user )
171
+ result , err := f .RunKubectlCommand ("auth" , "can-i" , "--as" , sa , "*" , resource , "--namespace" , f .Namespace .Name )
172
+ Expect (err ).ToNot (HaveOccurred (), "no permission for %s, result: %s" , resource , result )
173
+ Expect (strings .TrimSpace (result )).To (Equal ("yes" ))
174
+ }
175
+ },
176
+ Entry ("[test_id:XXXX]for admin" , "admin" ),
177
+ Entry ("[test_id:XXXX]for edit" , "edit" ),
178
+ )
179
+
150
180
It ("[test_id:3950]view datavolume permission checks" , func () {
151
181
const user = "view"
152
182
var cdiClient cdiClientset.Interface
0 commit comments