Skip to content

Commit a4bc929

Browse files
committed
Fix Session validation for MCS Operator Mode
1 parent 8a74b79 commit a4bc929

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

pkg/acl/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"github.com/minio/minio/pkg/env"
2323
)
2424

25-
// GetOperatorOnly gets MCS mkube admin mode status set on env variable
25+
// GetOperatorMode gets MCS mkube admin mode status set on env variable
2626
// or default one
27-
func GetOperatorOnly() bool {
28-
return strings.ToLower(env.Get(McsmKubeAdminOnly, "off")) == "on"
27+
func GetOperatorMode() bool {
28+
return strings.ToLower(env.Get(mcsOperatorMode, "off")) == "on"
2929
}

pkg/acl/const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
package acl
1818

1919
const (
20-
McsmKubeAdminOnly = "MCS_MKUBE_ADMIN_ONLY"
20+
mcsOperatorMode = "MCS_OPERATOR_MODE"
2121
)

pkg/acl/endpoints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ var operatorRules = map[string]ConfigurationActionSet{
233233
}
234234

235235
// operatorOnly ENV variable
236-
var operatorOnly = GetOperatorOnly()
236+
var operatorOnly = GetOperatorMode()
237237

238238
// GetActionsStringFromPolicy extract the admin/s3 actions from a given policy and return them in []string format
239239
//

restapi/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func newMcsCredentials(accessKey, secretKey, location string) (*credentials.Cred
168168
// Future authentication methods can be added under this switch statement
169169
switch {
170170
// MKUBE authentication for MCS
171-
case acl.GetOperatorOnly():
171+
case acl.GetOperatorMode():
172172
{
173173
if MkubeEndpoint == "" {
174174
return nil, errors.New("endpoint cannot be empty for Mkube")

restapi/configure_mcs.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"net/http"
2525
"strings"
2626

27+
"github.com/minio/mcs/pkg/acl"
28+
2729
"github.com/minio/mcs/models"
2830
"github.com/minio/mcs/pkg"
2931
"github.com/minio/mcs/pkg/auth"
@@ -60,9 +62,18 @@ func configureAPI(api *operations.McsAPI) http.Handler {
6062
// Applies when the "x-token" header is set
6163

6264
api.KeyAuth = func(token string, scopes []string) (*models.Principal, error) {
63-
if auth.IsJWTValid(token) {
64-
prin := models.Principal(token)
65-
return &prin, nil
65+
if acl.GetOperatorMode() {
66+
// here we just check the token is present on the request, authentication will be done
67+
// by kubernetes api server
68+
if token != "" {
69+
prin := models.Principal(token)
70+
return &prin, nil
71+
}
72+
} else {
73+
if auth.IsJWTValid(token) {
74+
prin := models.Principal(token)
75+
return &prin, nil
76+
}
6677
}
6778
log.Printf("Access attempt with incorrect api key auth: %s", token)
6879
return nil, errors.New(401, "incorrect api key auth")

restapi/user_login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func getLoginDetailsResponse() (*models.LoginDetails, error) {
155155
ctx := context.Background()
156156
loginStrategy := models.LoginDetailsLoginStrategyForm
157157
redirectURL := ""
158-
if acl.GetOperatorOnly() {
158+
if acl.GetOperatorMode() {
159159
loginStrategy = models.LoginDetailsLoginStrategyServiceAccount
160160
} else if oauth2.IsIdpEnabled() {
161161
loginStrategy = models.LoginDetailsLoginStrategyRedirect

0 commit comments

Comments
 (0)