@@ -567,3 +567,76 @@ func TestAcceptableWorkspaceAuthenticationConfigurations(t *testing.T) {
567567 })
568568 }
569569}
570+
571+ func TestWorkspaceOIDCTokenReview (t * testing.T ) {
572+ framework .Suite (t , "control-plane" )
573+
574+ ctx := context .Background ()
575+
576+ // start kcp and setup clients
577+ server := kcptesting .SharedKcpServer (t )
578+
579+ if len (server .ShardNames ()) > 1 {
580+ t .Skip ("This feature currently does not support multi shards because AuthConfigs are not replicated yet." )
581+ }
582+
583+ baseWsPath , _ := kcptesting .NewWorkspaceFixture (t , server , logicalcluster .NewPath ("root" ), kcptesting .WithNamePrefix ("workspace-auth-token-review" ))
584+
585+ kcpConfig := server .BaseConfig (t )
586+ kubeClusterClient , err := kcpkubernetesclientset .NewForConfig (kcpConfig )
587+ require .NoError (t , err )
588+ kcpClusterClient , err := kcpclientset .NewForConfig (kcpConfig )
589+ require .NoError (t , err )
590+
591+ mock , ca := authfixtures .StartMockOIDC (t , server )
592+ authConfig := authfixtures .CreateWorkspaceOIDCAuthentication (t , ctx , kcpClusterClient , baseWsPath , mock , ca , nil )
593+ wsType := authfixtures .CreateWorkspaceType (t , ctx , kcpClusterClient , baseWsPath , "with-oidc" , authConfig )
594+
595+ // create a new workspace with our new type
596+ t .Log ("Creating Workspaces..." )
597+ teamPath , _ := kcptesting .NewWorkspaceFixture (t , server , baseWsPath , kcptesting .WithName ("team-a" ), kcptesting .WithType (baseWsPath , tenancyv1alpha1 .WorkspaceTypeName (wsType )))
598+
599+ var (
600+ userName = "peter"
601+ 602+ userGroups = []string {"developers" , "admins" }
603+ expectedGroups = []string {"system:authenticated" }
604+ )
605+
606+ for _ , group := range userGroups {
607+ expectedGroups = append (expectedGroups , "oidc:" + group )
608+ }
609+
610+ authfixtures .GrantWorkspaceAccess (t , ctx , kubeClusterClient , teamPath , "grant-oidc-user" , "cluster-admin" , []rbacv1.Subject {{
611+ Kind : "User" ,
612+ Name : "oidc:" + userEmail ,
613+ }})
614+
615+ token := authfixtures .CreateOIDCToken (t , mock , userName , userEmail , userGroups )
616+
617+ t .Logf ("Creating TokenReview in %s" , teamPath )
618+
619+ const kcpDefaultAudience = "https://kcp.default.svc"
620+
621+ review := & authenticationv1.TokenReview {
622+ ObjectMeta : metav1.ObjectMeta {
623+ Name : "my-review" ,
624+ },
625+ Spec : authenticationv1.TokenReviewSpec {
626+ Token : token ,
627+ Audiences : []string {kcpDefaultAudience },
628+ },
629+ }
630+
631+ var response * authenticationv1.TokenReview
632+ require .Eventually (t , func () bool {
633+ var err error
634+
635+ response , err = kubeClusterClient .Cluster (teamPath ).AuthenticationV1 ().TokenReviews ().Create (ctx , review , metav1.CreateOptions {})
636+ require .NoError (t , err )
637+
638+ return response .Status .Authenticated
639+ }, wait .ForeverTestTimeout , 500 * time .Millisecond )
640+
641+ require .Contains (t , response .Status .Audiences , kcpDefaultAudience )
642+ }
0 commit comments