@@ -34,11 +34,11 @@ import (
34
34
35
35
func TestAuthorizationModes (t * testing.T ) {
36
36
framework .Suite (t , "control-plane" )
37
-
37
+ webhookPort := "8081"
38
38
ctx , cancelFunc := context .WithCancel (context .Background ())
39
39
t .Cleanup (cancelFunc )
40
40
// start a webhook that allows kcp to boot up
41
- webhookStop := RunWebhook (ctx , t , "8081" , "kubernetes:authz:allow" )
41
+ webhookStop := RunWebhook (ctx , t , webhookPort , "kubernetes:authz:allow" )
42
42
t .Cleanup (webhookStop )
43
43
44
44
server := framework .PrivateKcpServer (t , framework .WithCustomArguments (
@@ -68,35 +68,33 @@ func TestAuthorizationModes(t *testing.T) {
68
68
restClient , err := rest .UnversionedRESTClientFor (rootShardCfg )
69
69
require .NoError (t , err )
70
70
71
- t .Log ("Verify that you are allowed to access AllowAllPaths endpoints." )
72
- for _ , endpoint := range []string {"/livez" , "/readyz" } {
73
- req := rest .NewRequest (restClient ).RequestURI (endpoint )
74
- t .Logf ("%s should not be accessible." , req .URL ().String ())
75
- _ , err := req .Do (ctx ).Raw ()
76
- require .NoError (t , err )
77
- }
71
+ t .Log ("Verify that you are allowed to access one of AllowAllPaths endpoints." )
72
+ req := rest .NewRequest (restClient ).RequestURI ("/livez" )
73
+ t .Logf ("%s should not be accessible." , req .URL ().String ())
74
+ _ , err = req .Do (ctx ).Raw ()
75
+ require .NoError (t , err )
78
76
79
77
t .Log ("Admin should be allowed now to list Workspaces." )
80
78
_ , err = kcpClusterClient .Cluster (logicalcluster .NewPath ("root" )).TenancyV1alpha1 ().Workspaces ().List (ctx , metav1.ListOptions {})
81
79
require .NoError (t , err )
82
80
81
+ webhookStop ()
83
82
// run the webhook with deny policy
84
- webhookStop = RunWebhook (ctx , t , "8081" , "kubernetes:authz:deny" )
83
+ webhookStop = RunWebhook (ctx , t , webhookPort , "kubernetes:authz:deny" )
85
84
t .Cleanup (webhookStop )
86
85
87
- t .Log ("Admin should not be allowed now to list Workspaces ." )
88
- _ , err = kcpClusterClient .Cluster (logicalcluster .NewPath ("root" )).TenancyV1alpha1 ().Workspaces ().List (ctx , metav1.ListOptions {})
86
+ t .Log ("Admin should not be allowed now to list Logical clusters ." )
87
+ _ , err = kcpClusterClient .Cluster (logicalcluster .NewPath ("root" )).CoreV1alpha1 ().LogicalClusters ().List (ctx , metav1.ListOptions {})
89
88
require .Error (t , err )
90
89
91
- t .Log ("Admin should not be allowed to list ConfigMaps ." )
92
- _ , err = kubeClusterClient .Cluster (logicalcluster .NewPath ("root" )).CoreV1 ().ConfigMaps ("default" ).List (ctx , metav1.ListOptions {})
90
+ t .Log ("Admin should not be allowed to list Services ." )
91
+ _ , err = kubeClusterClient .Cluster (logicalcluster .NewPath ("root" )).CoreV1 ().Services ("default" ).List (ctx , metav1.ListOptions {})
93
92
require .Error (t , err )
94
93
95
94
t .Log ("Verify that it is not allowed to access AllowAllPaths endpoints." )
96
- for _ , endpoint := range []string {"/livez" , "/readyz" } {
97
- req := rest .NewRequest (restClient ).RequestURI (endpoint )
98
- t .Logf ("%s should not be accessible." , req .URL ().String ())
99
- _ , err := req .Do (ctx ).Raw ()
100
- require .Error (t , err )
101
- }
95
+ req = rest .NewRequest (restClient ).RequestURI ("/healthz" )
96
+ t .Logf ("%s should not be accessible." , req .URL ().String ())
97
+ _ , err = req .Do (ctx ).Raw ()
98
+ require .Error (t , err )
99
+
102
100
}
0 commit comments