mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-30 21:30:16 +00:00 
			
		
		
		
	svcacct: pass pod information in user.Info.Extra() when available
Fixes https://github.com/kubernetes/kubernetes/issues/59670
This commit is contained in:
		| @@ -21,6 +21,7 @@ import ( | ||||
| 	"encoding/base64" | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
| 	"testing" | ||||
| 	"time" | ||||
| @@ -161,7 +162,10 @@ func TestServiceAccountTokenCreate(t *testing.T) { | ||||
| 		checkPayload(t, treq.Status.Token, `"myns"`, "kubernetes.io", "namespace") | ||||
| 		checkPayload(t, treq.Status.Token, `"test-svcacct"`, "kubernetes.io", "serviceaccount", "name") | ||||
|  | ||||
| 		doTokenReview(t, cs, treq, false) | ||||
| 		info := doTokenReview(t, cs, treq, false) | ||||
| 		if info.Extra != nil { | ||||
| 			t.Fatalf("expected Extra to be nil but got: %#v", info.Extra) | ||||
| 		} | ||||
| 		delSvcAcct() | ||||
| 		doTokenReview(t, cs, treq, true) | ||||
| 	}) | ||||
| @@ -214,7 +218,16 @@ func TestServiceAccountTokenCreate(t *testing.T) { | ||||
| 		checkPayload(t, treq.Status.Token, `"myns"`, "kubernetes.io", "namespace") | ||||
| 		checkPayload(t, treq.Status.Token, `"test-svcacct"`, "kubernetes.io", "serviceaccount", "name") | ||||
|  | ||||
| 		doTokenReview(t, cs, treq, false) | ||||
| 		info := doTokenReview(t, cs, treq, false) | ||||
| 		if len(info.Extra) != 2 { | ||||
| 			t.Fatalf("expected Extra have length of 2 but was length %d: %#v", len(info.Extra), info.Extra) | ||||
| 		} | ||||
| 		if expected := map[string]authenticationv1.ExtraValue{ | ||||
| 			"authentication.kubernetes.io/pod-name": {pod.ObjectMeta.Name}, | ||||
| 			"authentication.kubernetes.io/pod-uid":  {string(pod.ObjectMeta.UID)}, | ||||
| 		}; !reflect.DeepEqual(info.Extra, expected) { | ||||
| 			t.Fatalf("unexpected Extra:\ngot:\t%#v\nwant:\t%#v", info.Extra, expected) | ||||
| 		} | ||||
| 		delPod() | ||||
| 		doTokenReview(t, cs, treq, true) | ||||
| 	}) | ||||
| @@ -539,7 +552,7 @@ func TestServiceAccountTokenCreate(t *testing.T) { | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func doTokenReview(t *testing.T, cs clientset.Interface, treq *authenticationv1.TokenRequest, expectErr bool) { | ||||
| func doTokenReview(t *testing.T, cs clientset.Interface, treq *authenticationv1.TokenRequest, expectErr bool) authenticationv1.UserInfo { | ||||
| 	t.Helper() | ||||
| 	trev, err := cs.AuthenticationV1().TokenReviews().Create(&authenticationv1.TokenReview{ | ||||
| 		Spec: authenticationv1.TokenReviewSpec{ | ||||
| @@ -559,6 +572,7 @@ func doTokenReview(t *testing.T, cs clientset.Interface, treq *authenticationv1. | ||||
| 	if !trev.Status.Authenticated && !expectErr { | ||||
| 		t.Fatal("expected token to be authenticated but it wasn't") | ||||
| 	} | ||||
| 	return trev.Status.User | ||||
| } | ||||
|  | ||||
| func checkPayload(t *testing.T, tok string, want string, parts ...string) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user