@@ -21,14 +21,15 @@ import (
21
21
"testing"
22
22
"time"
23
23
24
- kcpkubernetesclientset "github.com/kcp-dev/client-go/kubernetes"
25
24
"github.com/stretchr/testify/require"
26
25
26
+ authenticationv1 "k8s.io/api/authentication/v1"
27
27
apierrors "k8s.io/apimachinery/pkg/api/errors"
28
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
29
"k8s.io/apimachinery/pkg/util/wait"
30
30
"k8s.io/client-go/rest"
31
31
32
+ kcpkubernetesclientset "github.com/kcp-dev/client-go/kubernetes"
32
33
tenancyv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/tenancy/v1alpha1"
33
34
kcpclientset "github.com/kcp-dev/kcp/sdk/client/clientset/versioned/cluster"
34
35
"github.com/kcp-dev/kcp/test/e2e/framework"
@@ -81,3 +82,42 @@ func TestImpersonation(t *testing.T) {
81
82
return apierrors .IsForbidden (err )
82
83
}, wait .ForeverTestTimeout , time .Millisecond * 100 , "user-1 should NOT be able to edit its own workspace status with impersonation" )
83
84
}
85
+
86
+ func TestImpersonateScoping (t * testing.T ) {
87
+ t .Parallel ()
88
+ framework .Suite (t , "control-plane" )
89
+
90
+ ctx , cancelFn := context .WithCancel (context .Background ())
91
+ t .Cleanup (cancelFn )
92
+
93
+ server := framework .SharedKcpServer (t )
94
+ cfg := server .BaseConfig (t )
95
+
96
+ org , ws := framework .NewOrganizationFixture (t , server )
97
+
98
+ kubeClusterClient , err := kcpkubernetesclientset .NewForConfig (cfg )
99
+ require .NoError (t , err )
100
+
101
+ t .Log ("Make user-1 an admin of the org" )
102
+ framework .AdmitWorkspaceAccess (ctx , t , kubeClusterClient , org , []string {"user-1" }, []string {"cluster-admin" }, true )
103
+ user1Cfg := framework .StaticTokenUserConfig ("user-1" , cfg )
104
+
105
+ t .Logf ("Impersonate user-1 as some group" )
106
+ user1Cfg .Impersonate = rest.ImpersonationConfig {
107
+ UserName : "user-1" ,
108
+ Groups : []string {"elephant" },
109
+ }
110
+ user1Client , err := kcpkubernetesclientset .NewForConfig (user1Cfg )
111
+ require .NoError (t , err )
112
+
113
+ t .Logf ("Scoping should be added in SelfSubjectReview" )
114
+ require .Eventually (t , func () bool {
115
+ r , err := user1Client .AuthenticationV1 ().SelfSubjectReviews ().Cluster (org ).Create (ctx , & authenticationv1.SelfSubjectReview {}, metav1.CreateOptions {})
116
+ if err != nil {
117
+ return false
118
+ }
119
+
120
+ require .Contains (t , r .Status .UserInfo .Extra ["authentication.kcp.io/scopes" ], "cluster:" + ws .Spec .Cluster , "scoping to cluster:%s should be added in SelfSubjectReview" , ws .Spec .Cluster )
121
+ return true
122
+ }, wait .ForeverTestTimeout , time .Millisecond * 100 , "scoping should be added in SelfSubjectReview" )
123
+ }
0 commit comments