Skip to content

Commit f76e404

Browse files
stlazk8s-publishing-bot
authored andcommitted
featuregate UID in RequestHeader authenticator
Kubernetes-commit: a051b067cdffc92fbe40bcc5a8e8f1bf974348c4
1 parent b3c0cb6 commit f76e404

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

pkg/features/kube_features.go

+11
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ const (
149149
// to a chunking list request.
150150
RemainingItemCount featuregate.Feature = "RemainingItemCount"
151151

152+
// owner: @stlaz
153+
//
154+
// Enable kube-apiserver to accept UIDs via request header authentication.
155+
// This will also make the kube-apiserver's API aggregator add UIDs via standard
156+
// headers when forwarding requests to the servers serving the aggregated API.
157+
RemoteRequestHeaderUID featuregate.Feature = "RemoteRequestHeaderUID"
158+
152159
// owner: @wojtek-t
153160
//
154161
// Enables resilient watchcache initialization to avoid controlplane
@@ -359,6 +366,10 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate
359366
{Version: version.MustParse("1.29"), Default: true, PreRelease: featuregate.GA, LockToDefault: true},
360367
},
361368

369+
RemoteRequestHeaderUID: {
370+
{Version: version.MustParse("1.32"), Default: false, PreRelease: featuregate.Alpha},
371+
},
372+
362373
ResilientWatchCacheInitialization: {
363374
{Version: version.MustParse("1.31"), Default: true, PreRelease: featuregate.Beta},
364375
},

pkg/server/options/authentication.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import (
2929
"k8s.io/apiserver/pkg/apis/apiserver"
3030
"k8s.io/apiserver/pkg/authentication/authenticatorfactory"
3131
"k8s.io/apiserver/pkg/authentication/request/headerrequest"
32+
"k8s.io/apiserver/pkg/features"
3233
"k8s.io/apiserver/pkg/server"
3334
"k8s.io/apiserver/pkg/server/dynamiccertificates"
35+
utilfeature "k8s.io/apiserver/pkg/util/feature"
3436
"k8s.io/client-go/kubernetes"
3537
"k8s.io/client-go/rest"
3638
"k8s.io/client-go/tools/clientcmd"
@@ -68,9 +70,6 @@ func (s *RequestHeaderAuthenticationOptions) Validate() []error {
6870
if err := checkForWhiteSpaceOnly("requestheader-username-headers", s.UsernameHeaders...); err != nil {
6971
allErrors = append(allErrors, err)
7072
}
71-
if err := checkForWhiteSpaceOnly("requestheader-uid-headers", s.UIDHeaders...); err != nil {
72-
allErrors = append(allErrors, err)
73-
}
7473
if err := checkForWhiteSpaceOnly("requestheader-group-headers", s.GroupHeaders...); err != nil {
7574
allErrors = append(allErrors, err)
7675
}
@@ -84,17 +83,27 @@ func (s *RequestHeaderAuthenticationOptions) Validate() []error {
8483
if len(s.UsernameHeaders) > 0 && !caseInsensitiveHas(s.UsernameHeaders, "X-Remote-User") {
8584
klog.Warningf("--requestheader-username-headers is set without specifying the standard X-Remote-User header - API aggregation will not work")
8685
}
87-
if len(s.UIDHeaders) > 0 && !caseInsensitiveHas(s.UIDHeaders, "X-Remote-Uid") {
88-
// this was added later and so we are able to error out
89-
allErrors = append(allErrors, fmt.Errorf("--requestheader-uid-headers is set without specifying the standard X-Remote-Uid header - API aggregation will not work"))
90-
}
9186
if len(s.GroupHeaders) > 0 && !caseInsensitiveHas(s.GroupHeaders, "X-Remote-Group") {
9287
klog.Warningf("--requestheader-group-headers is set without specifying the standard X-Remote-Group header - API aggregation will not work")
9388
}
9489
if len(s.ExtraHeaderPrefixes) > 0 && !caseInsensitiveHas(s.ExtraHeaderPrefixes, "X-Remote-Extra-") {
9590
klog.Warningf("--requestheader-extra-headers-prefix is set without specifying the standard X-Remote-Extra- header prefix - API aggregation will not work")
9691
}
9792

93+
if !utilfeature.DefaultFeatureGate.Enabled(features.RemoteRequestHeaderUID) {
94+
if len(s.UIDHeaders) > 0 {
95+
allErrors = append(allErrors, fmt.Errorf("--requestheader-uid-headers requires the %q feature to be enabled", features.RemoteRequestHeaderUID))
96+
}
97+
} else {
98+
if err := checkForWhiteSpaceOnly("requestheader-uid-headers", s.UIDHeaders...); err != nil {
99+
allErrors = append(allErrors, err)
100+
}
101+
if len(s.UIDHeaders) > 0 && !caseInsensitiveHas(s.UIDHeaders, "X-Remote-Uid") {
102+
// this was added later and so we are able to error out
103+
allErrors = append(allErrors, fmt.Errorf("--requestheader-uid-headers is set without specifying the standard X-Remote-Uid header - API aggregation will not work"))
104+
}
105+
}
106+
98107
return allErrors
99108
}
100109

@@ -126,7 +135,7 @@ func (s *RequestHeaderAuthenticationOptions) AddFlags(fs *pflag.FlagSet) {
126135
"List of request headers to inspect for usernames. X-Remote-User is common.")
127136

128137
fs.StringSliceVar(&s.UIDHeaders, "requestheader-uid-headers", s.UIDHeaders, ""+
129-
"List of request headers to inspect for UIDs. X-Remote-Uid is suggested.")
138+
"List of request headers to inspect for UIDs. X-Remote-Uid is suggested. Requires the RemoteRequestHeaderUID feature to be enabled.")
130139

131140
fs.StringSliceVar(&s.GroupHeaders, "requestheader-group-headers", s.GroupHeaders, ""+
132141
"List of request headers to inspect for groups. X-Remote-Group is suggested.")

0 commit comments

Comments
 (0)