Skip to content

Commit

Permalink
fix: Allow Bearer token in server mode (#4735)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Behar <simbeh7@gmail.com>
  • Loading branch information
simster7 committed Dec 14, 2020
1 parent 1f421df commit ed853eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/auth/gatekeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (s gatekeeper) getClients(ctx context.Context) (versioned.Interface, kubern
authorization := getAuthHeader(md)
mode, valid := s.Modes.GetMode(authorization)
if !valid {
return nil, nil, nil, status.Error(codes.Unauthenticated, "token not valid for requested mode")
return nil, nil, nil, status.Error(codes.Unauthenticated, "token not valid for running mode")
}
switch mode {
case Client:
Expand Down
13 changes: 8 additions & 5 deletions server/auth/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ func (m Modes) Add(value string) error {
}

func (m Modes) GetMode(authorisation string) (Mode, bool) {
if strings.HasPrefix(authorisation, sso.Prefix) {
return SSO, m[SSO]
if m[SSO] && strings.HasPrefix(authorisation, sso.Prefix) {
return SSO, true
}
if strings.HasPrefix(authorisation, "Bearer ") || strings.HasPrefix(authorisation, "Basic ") {
return Client, m[Client]
if m[Client] && strings.HasPrefix(authorisation, "Bearer ") || strings.HasPrefix(authorisation, "Basic ") {
return Client, true
}
return Server, m[Server]
if m[Server] {
return Server, true
}
return "", false
}
12 changes: 12 additions & 0 deletions server/auth/mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ func TestModes_GetMode(t *testing.T) {
assert.Equal(t, SSO, mode)
}
})

m = Modes{
Client: false,
SSO: false,
Server: true,
}
t.Run("Server and Auth", func(t *testing.T) {
mode, valid := m.GetMode("Bearer ")
if assert.True(t, valid) {
assert.Equal(t, Server, mode)
}
})
}

0 comments on commit ed853eb

Please sign in to comment.