Skip to content

Commit

Permalink
[tokenfile]
Browse files Browse the repository at this point in the history
- the groups field has been changed to a single column option as requested in kubernetes#15704

[docs]
- updated the docs related the the tokefile along with an example
  • Loading branch information
gambol99 committed Oct 21, 2015
1 parent c8dd120 commit ee691aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
6 changes: 5 additions & 1 deletion docs/admin/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ be changed without restarting apiserver.

The token file format is implemented in `plugin/pkg/auth/authenticator/token/tokenfile/...`
and is a csv file with a minimum of 3 columns: token, user name, user uid, followed by
optional group names.
optional group names. Note, if you have more than one group the column must be double quoted e.g.

```csv
token,user,uid,"group1,group2,group3"
```

When using token authentication from an http client the apiserver expects an `Authorization`
header with a value of `Bearer SOMETOKEN`.
Expand Down
5 changes: 3 additions & 2 deletions plugin/pkg/auth/authenticator/token/tokenfile/tokenfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"os"
"strings"

"k8s.io/kubernetes/pkg/auth/user"
)
Expand Down Expand Up @@ -58,8 +59,8 @@ func NewCSV(path string) (*TokenAuthenticator, error) {
}
tokens[record[0]] = obj

if len(record) > 3 {
obj.Groups = record[3:]
if len(record) >= 4 {
obj.Groups = strings.Split(record[3], ",")
}
}

Expand Down
19 changes: 17 additions & 2 deletions plugin/pkg/auth/authenticator/token/tokenfile/tokenfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ func TestTokenFile(t *testing.T) {
auth, err := newWithContents(t, `
token1,user1,uid1
token2,user2,uid2
token3,user3,uid3,group1,group2
token4,user4,uid4,group2
token3,user3,uid3,"group1,group2"
token4,user4,uid4,"group2"
token5,user5,uid5,group5
token6,user6,uid6,group5,otherdata
token7,user7,uid7,"group1,group2",otherdata
`)
if err != nil {
t.Fatalf("unable to read tokenfile: %v", err)
Expand Down Expand Up @@ -64,9 +67,21 @@ token4,user4,uid4,group2
},
{
Token: "token5",
User: &user.DefaultInfo{Name: "user5", UID: "uid5", Groups: []string{"group5"}},
Ok: true,
},
{
Token: "token6",
User: &user.DefaultInfo{Name: "user6", UID: "uid6", Groups: []string{"group5"}},
Ok: true,
},
{
Token: "token7",
User: &user.DefaultInfo{Name: "user7", UID: "uid7", Groups: []string{"group1", "group2"}},
Ok: true,
},
{
Token: "token8",
},
}
for i, testCase := range testCases {
Expand Down

0 comments on commit ee691aa

Please sign in to comment.