Unverified Commit 2abc4742 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #55456 from hzxuzhonghu/token

Automatic merge from submit-queue (batch tested with PRs 55682, 55444, 55456, 55717, 55131). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. verify token auth file **What this PR does / why we need it**: verify token auth file and to prevent empty token. https://kubernetes.io/docs/admin/kubelet-tls-bootstrapping/#token-authentication-file https://kubernetes.io/docs/admin/authentication/#static-token-file **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #55434 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
parents d73157ba 62c170fc
...@@ -62,11 +62,17 @@ func NewCSV(path string) (*TokenAuthenticator, error) { ...@@ -62,11 +62,17 @@ func NewCSV(path string) (*TokenAuthenticator, error) {
if len(record) < 3 { if len(record) < 3 {
return nil, fmt.Errorf("token file '%s' must have at least 3 columns (token, user name, user uid), found %d", path, len(record)) return nil, fmt.Errorf("token file '%s' must have at least 3 columns (token, user name, user uid), found %d", path, len(record))
} }
recordNum++
if record[0] == "" {
glog.Warningf("empty token has been found in token file '%s', record number '%d'", path, recordNum)
continue
}
obj := &user.DefaultInfo{ obj := &user.DefaultInfo{
Name: record[1], Name: record[1],
UID: record[2], UID: record[2],
} }
recordNum++
if _, exist := tokens[record[0]]; exist { if _, exist := tokens[record[0]]; exist {
glog.Warningf("duplicate token has been found in token file '%s', record number '%d'", path, recordNum) glog.Warningf("duplicate token has been found in token file '%s', record number '%d'", path, recordNum)
} }
......
...@@ -125,6 +125,16 @@ func TestInsufficientColumnsTokenFile(t *testing.T) { ...@@ -125,6 +125,16 @@ func TestInsufficientColumnsTokenFile(t *testing.T) {
} }
} }
func TestEmptyTokenTokenFile(t *testing.T) {
auth, err := newWithContents(t, ",user5,uid5\n")
if err != nil {
t.Fatalf("unexpected error %v", err)
}
if len(auth.tokens) != 0 {
t.Fatalf("empty token should not be recorded")
}
}
func newWithContents(t *testing.T, contents string) (auth *TokenAuthenticator, err error) { func newWithContents(t *testing.T, contents string) (auth *TokenAuthenticator, err error) {
f, err := ioutil.TempFile("", "tokenfile_test") f, err := ioutil.TempFile("", "tokenfile_test")
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment