@@ -14,6 +14,7 @@ import (
14
14
"k8s.io/apimachinery/pkg/util/wait"
15
15
"k8s.io/client-go/rest"
16
16
"k8s.io/kubernetes/pkg/api"
17
+ "k8s.io/kubernetes/pkg/apis/policy"
17
18
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
18
19
19
20
"github.com/openshift/origin/pkg/cmd/server/admin"
@@ -22,6 +23,8 @@ import (
22
23
testserver "github.com/openshift/origin/test/util/server"
23
24
)
24
25
26
+ // If this test fails make sure to update it with contents from
27
+ // vendor/k8s.io/kubernetes/test/integration/auth/node_test.go#TestNodeAuthorizer
25
28
func TestNodeAuthorizer (t * testing.T ) {
26
29
masterConfig , err := testserver .DefaultMasterOptions ()
27
30
if err != nil {
@@ -188,6 +191,30 @@ func TestNodeAuthorizer(t *testing.T) {
188
191
deleteNode2 := func (client clientset.Interface ) error {
189
192
return client .Core ().Nodes ().Delete ("node2" , nil )
190
193
}
194
+ createNode2NormalPodEviction := func (client clientset.Interface ) error {
195
+ return client .Policy ().Evictions ("ns" ).Evict (& policy.Eviction {
196
+ TypeMeta : metav1.TypeMeta {
197
+ APIVersion : "policy/v1beta1" ,
198
+ Kind : "Eviction" ,
199
+ },
200
+ ObjectMeta : metav1.ObjectMeta {
201
+ Name : "node2normalpod" ,
202
+ Namespace : "ns" ,
203
+ },
204
+ })
205
+ }
206
+ createNode2MirrorPodEviction := func (client clientset.Interface ) error {
207
+ return client .Policy ().Evictions ("ns" ).Evict (& policy.Eviction {
208
+ TypeMeta : metav1.TypeMeta {
209
+ APIVersion : "policy/v1beta1" ,
210
+ Kind : "Eviction" ,
211
+ },
212
+ ObjectMeta : metav1.ObjectMeta {
213
+ Name : "node2mirrorpod" ,
214
+ Namespace : "ns" ,
215
+ },
216
+ })
217
+ }
191
218
192
219
// nodeanonClient := clientsetForToken(tokenNodeUnknown, clientConfig)
193
220
// node1Client := clientsetForToken(tokenNode1, clientConfig)
@@ -201,7 +228,9 @@ func TestNodeAuthorizer(t *testing.T) {
201
228
expectForbidden (t , getPV (nodeanonClient ))
202
229
expectForbidden (t , createNode2NormalPod (nodeanonClient ))
203
230
expectForbidden (t , createNode2MirrorPod (nodeanonClient ))
231
+ expectForbidden (t , deleteNode2NormalPod (nodeanonClient ))
204
232
expectForbidden (t , deleteNode2MirrorPod (nodeanonClient ))
233
+ expectForbidden (t , createNode2MirrorPodEviction (nodeanonClient ))
205
234
expectForbidden (t , createNode2 (nodeanonClient ))
206
235
expectForbidden (t , updateNode2Status (nodeanonClient ))
207
236
expectForbidden (t , deleteNode2 (nodeanonClient ))
@@ -213,7 +242,8 @@ func TestNodeAuthorizer(t *testing.T) {
213
242
expectForbidden (t , getPV (node1Client ))
214
243
expectForbidden (t , createNode2NormalPod (nodeanonClient ))
215
244
expectForbidden (t , createNode2MirrorPod (node1Client ))
216
- expectForbidden (t , deleteNode2MirrorPod (node1Client ))
245
+ expectNotFound (t , deleteNode2MirrorPod (node1Client ))
246
+ expectNotFound (t , createNode2MirrorPodEviction (node1Client ))
217
247
expectForbidden (t , createNode2 (node1Client ))
218
248
expectForbidden (t , updateNode2Status (node1Client ))
219
249
expectForbidden (t , deleteNode2 (node1Client ))
@@ -228,6 +258,8 @@ func TestNodeAuthorizer(t *testing.T) {
228
258
// mirror pod and self node lifecycle is allowed
229
259
expectAllowed (t , createNode2MirrorPod (node2Client ))
230
260
expectAllowed (t , deleteNode2MirrorPod (node2Client ))
261
+ expectAllowed (t , createNode2MirrorPod (node2Client ))
262
+ expectAllowed (t , createNode2MirrorPodEviction (node2Client ))
231
263
expectAllowed (t , createNode2 (node2Client ))
232
264
expectAllowed (t , updateNode2Status (node2Client ))
233
265
expectAllowed (t , deleteNode2 (node2Client ))
@@ -244,8 +276,10 @@ func TestNodeAuthorizer(t *testing.T) {
244
276
expectForbidden (t , createNode2NormalPod (nodeanonClient ))
245
277
expectForbidden (t , updateNode2NormalPodStatus (nodeanonClient ))
246
278
expectForbidden (t , deleteNode2NormalPod (nodeanonClient ))
279
+ expectForbidden (t , createNode2NormalPodEviction (nodeanonClient ))
247
280
expectForbidden (t , createNode2MirrorPod (nodeanonClient ))
248
281
expectForbidden (t , deleteNode2MirrorPod (nodeanonClient ))
282
+ expectForbidden (t , createNode2MirrorPodEviction (nodeanonClient ))
249
283
250
284
expectForbidden (t , getSecret (node1Client ))
251
285
expectForbidden (t , getPVSecret (node1Client ))
@@ -255,8 +289,10 @@ func TestNodeAuthorizer(t *testing.T) {
255
289
expectForbidden (t , createNode2NormalPod (node1Client ))
256
290
expectForbidden (t , updateNode2NormalPodStatus (node1Client ))
257
291
expectForbidden (t , deleteNode2NormalPod (node1Client ))
292
+ expectForbidden (t , createNode2NormalPodEviction (node1Client ))
258
293
expectForbidden (t , createNode2MirrorPod (node1Client ))
259
- expectForbidden (t , deleteNode2MirrorPod (node1Client ))
294
+ expectNotFound (t , deleteNode2MirrorPod (node1Client ))
295
+ expectNotFound (t , createNode2MirrorPodEviction (node1Client ))
260
296
261
297
// node2 can get referenced objects now
262
298
expectAllowed (t , getSecret (node2Client ))
@@ -269,6 +305,11 @@ func TestNodeAuthorizer(t *testing.T) {
269
305
expectAllowed (t , deleteNode2NormalPod (node2Client ))
270
306
expectAllowed (t , createNode2MirrorPod (node2Client ))
271
307
expectAllowed (t , deleteNode2MirrorPod (node2Client ))
308
+ // recreate as an admin to test eviction
309
+ expectAllowed (t , createNode2NormalPod (superuserClient ))
310
+ expectAllowed (t , createNode2MirrorPod (superuserClient ))
311
+ expectAllowed (t , createNode2NormalPodEviction (node2Client ))
312
+ expectAllowed (t , createNode2MirrorPodEviction (node2Client ))
272
313
}
273
314
274
315
func makeNodeClientset (t * testing.T , signer * admin.SignerCertOptions , certDir string , username string , anonymousConfig * rest.Config ) clientset.Interface {
0 commit comments