Skip to content

Commit 34bcd25

Browse files
authored
Disable Users and Groups Menu options when LDAP is enabled on MinIO (#614)
1 parent 7853aa6 commit 34bcd25

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

pkg/acl/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ import (
2626
func GetOperatorMode() bool {
2727
return strings.ToLower(env.Get(consoleOperatorMode, "off")) == "on"
2828
}
29+
30+
func GetLDAPEnabled() bool {
31+
return strings.ToLower(env.Get(ConsoleLDAPEnabled, "off")) == "on"
32+
}

pkg/acl/const.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ package acl
1818

1919
const (
2020
consoleOperatorMode = "CONSOLE_OPERATOR_MODE"
21+
// const for ldap configuration
22+
ConsoleLDAPEnabled = "CONSOLE_LDAP_ENABLED"
2123
)

pkg/acl/endpoints.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,17 @@ var healthInfoActionSet = ConfigurationActionSet{
243243
),
244244
}
245245

246+
var displayRules = map[string]func() bool{
247+
// disable users page if LDAP is enabled
248+
users: func() bool {
249+
return !GetLDAPEnabled()
250+
},
251+
// disable groups page if LDAP is enabled
252+
groups: func() bool {
253+
return !GetLDAPEnabled()
254+
},
255+
}
256+
246257
// endpointRules contains the mapping between endpoints and ActionSets, additional rules can be added here
247258
var endpointRules = map[string]ConfigurationActionSet{
248259
configuration: configurationActionSet,
@@ -337,6 +348,15 @@ func GetAuthorizedEndpoints(actions []string) []string {
337348
userAllowedAction := actionsStringToActionSet(actions)
338349
var allowedEndpoints []string
339350
for endpoint, rules := range rangeTake {
351+
352+
// check if display rule exists for this endpoint, this will control
353+
// what user sees on the console UI
354+
if rule, ok := displayRules[endpoint]; ok {
355+
if rule != nil && !rule() {
356+
continue
357+
}
358+
}
359+
340360
// check if user policy matches s3:* or admin:* typesIntersection
341361
endpointActionTypes := rules.actionTypes
342362
typesIntersection := endpointActionTypes.Intersection(userAllowedAction)

restapi/user_service_accounts.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ func registerServiceAccountsHandlers(api *operations.ConsoleAPI) {
5858

5959
// createServiceAccount adds a service account to the userClient and assigns a policy to him if defined.
6060
func createServiceAccount(ctx context.Context, userClient MinioAdmin, policy string) (*models.ServiceAccountCreds, error) {
61-
iamPolicy := &iampolicy.Policy{}
61+
// By default a nil policy will be used so the service account inherit the parent account policy, otherwise
62+
// we override with the user provided iam policy
63+
var iamPolicy *iampolicy.Policy
6264
if strings.TrimSpace(policy) != "" {
6365
iamp, err := iampolicy.ParseConfig(bytes.NewReader([]byte(policy)))
6466
if err != nil {

0 commit comments

Comments
 (0)