bootstrap token auth: don't accept deleted tokens

This commit is contained in:
Eric Chiang 2017-07-17 15:21:56 -07:00
parent d20414e2b6
commit f719b2670c
2 changed files with 26 additions and 0 deletions

View File

@ -102,6 +102,11 @@ func (t *TokenAuthenticator) AuthenticateToken(token string) (user.Info, bool, e
return nil, false, err 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 { if string(secret.Type) != string(bootstrapapi.SecretTypeBootstrapToken) || secret.Data == nil {
tokenErrorf(secret, "has invalid type, expected %s.", bootstrapapi.SecretTypeBootstrapToken) tokenErrorf(secret, "has invalid type, expected %s.", bootstrapapi.SecretTypeBootstrapToken)
return nil, false, nil return nil, false, nil

View File

@ -52,6 +52,8 @@ const (
) )
func TestTokenAuthenticator(t *testing.T) { func TestTokenAuthenticator(t *testing.T) {
now := metav1.Now()
tests := []struct { tests := []struct {
name string name string
@ -135,6 +137,25 @@ func TestTokenAuthenticator(t *testing.T) {
token: "barfoo" + "." + tokenSecret, token: "barfoo" + "." + tokenSecret,
wantNotFound: true, 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", name: "expired token",
secrets: []*api.Secret{ secrets: []*api.Secret{