Skip to content

Commit df29274

Browse files
committed
Remove support for basic authentication
This change removes support for basic authn in v1.19 via the --basic-auth-file flag. This functionality was deprecated in v1.16 in response to ATR-K8S-002: Non-constant time password comparison. Similar functionality is available via the --token-auth-file flag for development purposes. Signed-off-by: Monis Khan <[email protected]>
1 parent c034a14 commit df29274

File tree

24 files changed

+5
-655
lines changed

24 files changed

+5
-655
lines changed

cluster/gce/gci/configure-kubeapiserver.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ function start-kube-apiserver {
101101
params+=" --service-account-key-file=${SERVICEACCOUNT_CERT_PATH}"
102102
fi
103103
params+=" --token-auth-file=/etc/srv/kubernetes/known_tokens.csv"
104-
if [[ -n "${KUBE_PASSWORD:-}" && -n "${KUBE_USER:-}" ]]; then
105-
params+=" --basic-auth-file=/etc/srv/kubernetes/basic_auth.csv"
106-
fi
107104

108105
if [[ -n "${KUBE_APISERVER_REQUEST_TIMEOUT_SEC:-}" ]]; then
109106
params+=" --request-timeout=${KUBE_APISERVER_REQUEST_TIMEOUT_SEC}s"

cmd/controller-manager/app/serve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
// BuildHandlerChain builds a handler chain with a base handler and CompletedConfig.
3838
func BuildHandlerChain(apiHandler http.Handler, authorizationInfo *apiserver.AuthorizationInfo, authenticationInfo *apiserver.AuthenticationInfo) http.Handler {
3939
requestInfoResolver := &apirequest.RequestInfoFactory{}
40-
failedHandler := genericapifilters.Unauthorized(legacyscheme.Codecs, false)
40+
failedHandler := genericapifilters.Unauthorized(legacyscheme.Codecs)
4141

4242
handler := apiHandler
4343
if authorizationInfo != nil {

cmd/kube-apiserver/app/options/options_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ func TestAddFlags(t *testing.T) {
276276
UsernameClaim: "sub",
277277
SigningAlgs: []string{"RS256"},
278278
},
279-
PasswordFile: &kubeoptions.PasswordFileAuthenticationOptions{},
280279
RequestHeader: &apiserveroptions.RequestHeaderAuthenticationOptions{},
281280
ServiceAccounts: &kubeoptions.ServiceAccountAuthenticationOptions{
282281
Lookup: true,

cmd/kube-scheduler/app/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func Run(ctx context.Context, cc schedulerserverconfig.CompletedConfig, outOfTre
262262
// buildHandlerChain wraps the given handler with the standard filters.
263263
func buildHandlerChain(handler http.Handler, authn authenticator.Request, authz authorizer.Authorizer) http.Handler {
264264
requestInfoResolver := &apirequest.RequestInfoFactory{}
265-
failedHandler := genericapifilters.Unauthorized(legacyscheme.Codecs, false)
265+
failedHandler := genericapifilters.Unauthorized(legacyscheme.Codecs)
266266

267267
handler = genericapifilters.WithAuthorization(handler, authz, legacyscheme.Codecs)
268268
handler = genericapifilters.WithAuthentication(handler, authn, failedHandler, nil)

pkg/kubeapiserver/authenticator/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ go_library(
2727
"//staging/src/k8s.io/apiserver/pkg/authentication/token/union:go_default_library",
2828
"//staging/src/k8s.io/apiserver/pkg/server/dynamiccertificates:go_default_library",
2929
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
30-
"//staging/src/k8s.io/apiserver/plugin/pkg/authenticator/password/passwordfile:go_default_library",
31-
"//staging/src/k8s.io/apiserver/plugin/pkg/authenticator/request/basicauth:go_default_library",
3230
"//staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/oidc:go_default_library",
3331
"//staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook:go_default_library",
3432
"//staging/src/k8s.io/client-go/plugin/pkg/client/auth:go_default_library",

pkg/kubeapiserver/authenticator/config.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ import (
3636
tokenunion "k8s.io/apiserver/pkg/authentication/token/union"
3737
"k8s.io/apiserver/pkg/server/dynamiccertificates"
3838
utilfeature "k8s.io/apiserver/pkg/util/feature"
39-
"k8s.io/apiserver/plugin/pkg/authenticator/password/passwordfile"
40-
"k8s.io/apiserver/plugin/pkg/authenticator/request/basicauth"
4139
"k8s.io/apiserver/plugin/pkg/authenticator/token/oidc"
4240
"k8s.io/apiserver/plugin/pkg/authenticator/token/webhook"
4341

@@ -51,7 +49,6 @@ import (
5149
// Config contains the data on how to authenticate a request to the Kube API Server
5250
type Config struct {
5351
Anonymous bool
54-
BasicAuthFile string
5552
BootstrapToken bool
5653

5754
TokenAuthFile string
@@ -109,22 +106,6 @@ func (config Config) New() (authenticator.Request, *spec.SecurityDefinitions, er
109106
authenticators = append(authenticators, authenticator.WrapAudienceAgnosticRequest(config.APIAudiences, requestHeaderAuthenticator))
110107
}
111108

112-
// basic auth
113-
if len(config.BasicAuthFile) > 0 {
114-
basicAuth, err := newAuthenticatorFromBasicAuthFile(config.BasicAuthFile)
115-
if err != nil {
116-
return nil, nil, err
117-
}
118-
authenticators = append(authenticators, authenticator.WrapAudienceAgnosticRequest(config.APIAudiences, basicAuth))
119-
120-
securityDefinitions["HTTPBasic"] = &spec.SecurityScheme{
121-
SecuritySchemeProps: spec.SecuritySchemeProps{
122-
Type: "basic",
123-
Description: "HTTP Basic authentication",
124-
},
125-
}
126-
}
127-
128109
// X509 methods
129110
if config.ClientCAContentProvider != nil {
130111
certAuth := x509.NewDynamic(config.ClientCAContentProvider.VerifyOptions, x509.CommonNameUserConversion)
@@ -235,16 +216,6 @@ func IsValidServiceAccountKeyFile(file string) bool {
235216
return err == nil
236217
}
237218

238-
// newAuthenticatorFromBasicAuthFile returns an authenticator.Request or an error
239-
func newAuthenticatorFromBasicAuthFile(basicAuthFile string) (authenticator.Request, error) {
240-
basicAuthenticator, err := passwordfile.NewCSV(basicAuthFile)
241-
if err != nil {
242-
return nil, err
243-
}
244-
245-
return basicauth.New(basicAuthenticator), nil
246-
}
247-
248219
// newAuthenticatorFromTokenFile returns an authenticator.Token or an error
249220
func newAuthenticatorFromTokenFile(tokenAuthFile string) (authenticator.Token, error) {
250221
tokenAuthenticator, err := tokenfile.NewCSV(tokenAuthFile)

pkg/kubeapiserver/options/authentication.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ type BuiltInAuthenticationOptions struct {
4343
BootstrapToken *BootstrapTokenAuthenticationOptions
4444
ClientCert *genericoptions.ClientCertAuthenticationOptions
4545
OIDC *OIDCAuthenticationOptions
46-
PasswordFile *PasswordFileAuthenticationOptions
4746
RequestHeader *genericoptions.RequestHeaderAuthenticationOptions
4847
ServiceAccounts *ServiceAccountAuthenticationOptions
4948
TokenFile *TokenFileAuthenticationOptions
@@ -73,10 +72,6 @@ type OIDCAuthenticationOptions struct {
7372
RequiredClaims map[string]string
7473
}
7574

76-
type PasswordFileAuthenticationOptions struct {
77-
BasicAuthFile string
78-
}
79-
8075
type ServiceAccountAuthenticationOptions struct {
8176
KeyFiles []string
8277
Lookup bool
@@ -108,7 +103,6 @@ func (s *BuiltInAuthenticationOptions) WithAll() *BuiltInAuthenticationOptions {
108103
WithBootstrapToken().
109104
WithClientCert().
110105
WithOIDC().
111-
WithPasswordFile().
112106
WithRequestHeader().
113107
WithServiceAccounts().
114108
WithTokenFile().
@@ -135,11 +129,6 @@ func (s *BuiltInAuthenticationOptions) WithOIDC() *BuiltInAuthenticationOptions
135129
return s
136130
}
137131

138-
func (s *BuiltInAuthenticationOptions) WithPasswordFile() *BuiltInAuthenticationOptions {
139-
s.PasswordFile = &PasswordFileAuthenticationOptions{}
140-
return s
141-
}
142-
143132
func (s *BuiltInAuthenticationOptions) WithRequestHeader() *BuiltInAuthenticationOptions {
144133
s.RequestHeader = &genericoptions.RequestHeaderAuthenticationOptions{}
145134
return s
@@ -274,13 +263,6 @@ func (s *BuiltInAuthenticationOptions) AddFlags(fs *pflag.FlagSet) {
274263
"Repeat this flag to specify multiple claims.")
275264
}
276265

277-
if s.PasswordFile != nil {
278-
fs.StringVar(&s.PasswordFile.BasicAuthFile, "basic-auth-file", s.PasswordFile.BasicAuthFile, ""+
279-
"If set, the file that will be used to admit requests to the secure port of the API server "+
280-
"via http basic authentication.")
281-
fs.MarkDeprecated("basic-auth-file", "Basic authentication mode is deprecated and will be removed in a future release. It is not recommended for production environments.")
282-
}
283-
284266
if s.RequestHeader != nil {
285267
s.RequestHeader.AddFlags(fs)
286268
}
@@ -377,10 +359,6 @@ func (s *BuiltInAuthenticationOptions) ToAuthenticationConfig() (kubeauthenticat
377359
ret.OIDCRequiredClaims = s.OIDC.RequiredClaims
378360
}
379361

380-
if s.PasswordFile != nil {
381-
ret.BasicAuthFile = s.PasswordFile.BasicAuthFile
382-
}
383-
384362
if s.RequestHeader != nil {
385363
var err error
386364
ret.RequestHeaderConfig, err = s.RequestHeader.ToAuthenticationRequestHeaderConfig()
@@ -447,8 +425,6 @@ func (o *BuiltInAuthenticationOptions) ApplyTo(c *genericapiserver.Config) error
447425
}
448426
}
449427

450-
c.Authentication.SupportsBasicAuth = o.PasswordFile != nil && len(o.PasswordFile.BasicAuthFile) > 0
451-
452428
c.Authentication.APIAudiences = o.APIAudiences
453429
if o.ServiceAccounts != nil && o.ServiceAccounts.Issuer != "" && len(o.APIAudiences) == 0 {
454430
c.Authentication.APIAudiences = authenticator.Audiences{o.ServiceAccounts.Issuer}

pkg/kubeapiserver/options/authentication_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ func TestToAuthenticationConfig(t *testing.T) {
120120
IssuerURL: "testIssuerURL",
121121
ClientID: "testClientID",
122122
},
123-
PasswordFile: &PasswordFileAuthenticationOptions{
124-
BasicAuthFile: "/testBasicAuthFile",
125-
},
126123
RequestHeader: &apiserveroptions.RequestHeaderAuthenticationOptions{
127124
UsernameHeaders: []string{"x-remote-user"},
128125
GroupHeaders: []string{"x-remote-group"},
@@ -144,7 +141,6 @@ func TestToAuthenticationConfig(t *testing.T) {
144141
expectConfig := kubeauthenticator.Config{
145142
APIAudiences: authenticator.Audiences{"http://foo.bar.com"},
146143
Anonymous: false,
147-
BasicAuthFile: "/testBasicAuthFile",
148144
BootstrapToken: false,
149145
ClientCAContentProvider: nil, // this is nil because you can't compare functions
150146
TokenAuthFile: "/testTokenFile",

staging/src/k8s.io/apiserver/pkg/authentication/authenticator/interfaces.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ type Request interface {
3535
AuthenticateRequest(req *http.Request) (*Response, bool, error)
3636
}
3737

38-
// Password checks a username and password against a backing authentication
39-
// store and returns a Response or an error if the password could not be
40-
// checked.
41-
type Password interface {
42-
AuthenticatePassword(ctx context.Context, user, password string) (*Response, bool, error)
43-
}
44-
4538
// TokenFunc is a function that implements the Token interface.
4639
type TokenFunc func(ctx context.Context, token string) (*Response, bool, error)
4740

@@ -58,14 +51,6 @@ func (f RequestFunc) AuthenticateRequest(req *http.Request) (*Response, bool, er
5851
return f(req)
5952
}
6053

61-
// PasswordFunc is a function that implements the Password interface.
62-
type PasswordFunc func(ctx context.Context, user, password string) (*Response, bool, error)
63-
64-
// AuthenticatePassword implements authenticator.Password.
65-
func (f PasswordFunc) AuthenticatePassword(ctx context.Context, user, password string) (*Response, bool, error) {
66-
return f(ctx, user, password)
67-
}
68-
6954
// Response is the struct returned by authenticator interfaces upon successful
7055
// authentication. It contains information about whether the authenticator
7156
// authenticated the request, information about the context of the

staging/src/k8s.io/apiserver/pkg/endpoints/filters/authentication.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ func WithAuthentication(handler http.Handler, auth authenticator.Request, failed
7171
})
7272
}
7373

74-
func Unauthorized(s runtime.NegotiatedSerializer, supportsBasicAuth bool) http.Handler {
74+
func Unauthorized(s runtime.NegotiatedSerializer) http.Handler {
7575
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
76-
if supportsBasicAuth {
77-
w.Header().Set("WWW-Authenticate", `Basic realm="kubernetes-master"`)
78-
}
7976
ctx := req.Context()
8077
requestInfo, found := genericapirequest.RequestInfoFrom(ctx)
8178
if !found {

0 commit comments

Comments
 (0)