@@ -52,7 +52,16 @@ import (
5252 kcpinformers "github.com/kcp-dev/kcp/sdk/client/informers/externalversions"
5353)
5454
55- const VirtualWorkspaceName string = "apiexport"
55+ const (
56+ // VirtualWorkspaceName is the name of the virtual workspace.
57+ VirtualWorkspaceName string = "apiexport"
58+ // OriginalUserAnnotationKey is the key used in a user's "extra" to
59+ // specify the original user of the authenticating request.
60+ OriginalUserAnnotationKey = "experimental.authorization.kcp.io/original-username"
61+ // OriginalGroupsAnnotationKey is the key used in a user's "extra" to
62+ // specify the original groups of the authenticating request.
63+ OriginalGroupsAnnotationKey = "experimental.authorization.kcp.io/original-groups"
64+ )
5665
5766func BuildVirtualWorkspace (
5867 rootPathPrefix string ,
@@ -113,6 +122,15 @@ func BuildVirtualWorkspace(
113122 serviceaccount .ClusterNameKey : {cluster .Name .Path ().String ()},
114123 },
115124 }
125+
126+ if user , ok := genericapirequest .UserFrom (ctx ); ok {
127+ // We pass the original user and groups as extra fields to
128+ // the impersonation config so that the receiver can make
129+ // decisions based on the original user/groups.
130+ impersonationConfig .Impersonate .Extra [OriginalUserAnnotationKey ] = []string {user .GetName ()}
131+ impersonationConfig .Impersonate .Extra [OriginalGroupsAnnotationKey ] = user .GetGroups ()
132+ }
133+
116134 impersonatedClient , err := kcpdynamic .NewForConfig (impersonationConfig )
117135 if err != nil {
118136 return nil , fmt .Errorf ("error generating dynamic client: %w" , err )
0 commit comments