From f719b2670c8d1d89666435dff306e8d37f2f544c Mon Sep 17 00:00:00 2001 From: Eric Chiang Date: Mon, 17 Jul 2017 15:21:56 -0700 Subject: [PATCH] bootstrap token auth: don't accept deleted tokens --- .../token/bootstrap/bootstrap.go | 5 +++++ .../token/bootstrap/bootstrap_test.go | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/plugin/pkg/auth/authenticator/token/bootstrap/bootstrap.go b/plugin/pkg/auth/authenticator/token/bootstrap/bootstrap.go index 77286b48138..62b3ad50d8c 100644 --- a/plugin/pkg/auth/authenticator/token/bootstrap/bootstrap.go +++ b/plugin/pkg/auth/authenticator/token/bootstrap/bootstrap.go @@ -102,6 +102,11 @@ func (t *TokenAuthenticator) AuthenticateToken(token string) (user.Info, bool, e return nil, false, err } + if secret.DeletionTimestamp != nil { + tokenErrorf(secret, "is deleted and awaiting removal") + return nil, false, nil + } + if string(secret.Type) != string(bootstrapapi.SecretTypeBootstrapToken) || secret.Data == nil { tokenErrorf(secret, "has invalid type, expected %s.", bootstrapapi.SecretTypeBootstrapToken) return nil, false, nil diff --git a/plugin/pkg/auth/authenticator/token/bootstrap/bootstrap_test.go b/plugin/pkg/auth/authenticator/token/bootstrap/bootstrap_test.go index 0061c92f1e9..e8586e9f1a4 100644 --- a/plugin/pkg/auth/authenticator/token/bootstrap/bootstrap_test.go +++ b/plugin/pkg/auth/authenticator/token/bootstrap/bootstrap_test.go @@ -52,6 +52,8 @@ const ( ) func TestTokenAuthenticator(t *testing.T) { + now := metav1.Now() + tests := []struct { name string @@ -135,6 +137,25 @@ func TestTokenAuthenticator(t *testing.T) { token: "barfoo" + "." + tokenSecret, wantNotFound: true, }, + { + name: "deleted token", + secrets: []*api.Secret{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: bootstrapapi.BootstrapTokenSecretPrefix + tokenID, + DeletionTimestamp: &now, + }, + Data: map[string][]byte{ + bootstrapapi.BootstrapTokenIDKey: []byte(tokenID), + bootstrapapi.BootstrapTokenSecretKey: []byte(tokenSecret), + bootstrapapi.BootstrapTokenUsageAuthentication: []byte("true"), + }, + Type: "bootstrap.kubernetes.io/token", + }, + }, + token: tokenID + "." + tokenSecret, + wantNotFound: true, + }, { name: "expired token", secrets: []*api.Secret{