2018-10-09 17:00:01 -04:00
|
|
|
/*
|
2019-08-08 18:10:04 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2018-2019 MinIO, Inc.
|
2018-10-09 17:00:01 -04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2019-06-20 18:28:33 -04:00
|
|
|
"bytes"
|
2018-10-09 17:00:01 -04:00
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2018-10-12 14:32:18 -04:00
|
|
|
"strings"
|
2018-10-09 17:00:01 -04:00
|
|
|
"sync"
|
|
|
|
|
2019-05-29 19:35:12 -04:00
|
|
|
"github.com/minio/minio-go/v6/pkg/set"
|
2019-11-13 20:38:05 -05:00
|
|
|
"github.com/minio/minio/cmd/config"
|
2018-10-09 17:00:01 -04:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
|
|
|
"github.com/minio/minio/pkg/auth"
|
2019-02-27 20:46:55 -05:00
|
|
|
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
2018-10-09 17:00:01 -04:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
|
|
|
)
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
// UsersSysType - defines the type of users and groups system that is
|
|
|
|
// active on the server.
|
|
|
|
type UsersSysType string
|
|
|
|
|
|
|
|
// Types of users configured in the server.
|
|
|
|
const (
|
|
|
|
// This mode uses the internal users system in MinIO.
|
|
|
|
MinIOUsersSysType UsersSysType = "MinIOUsersSys"
|
|
|
|
|
|
|
|
// This mode uses users and groups from a configured LDAP
|
|
|
|
// server.
|
|
|
|
LDAPUsersSysType UsersSysType = "LDAPUsersSys"
|
|
|
|
)
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
const (
|
|
|
|
// IAM configuration directory.
|
|
|
|
iamConfigPrefix = minioConfigPrefix + "/iam"
|
|
|
|
|
|
|
|
// IAM users directory.
|
|
|
|
iamConfigUsersPrefix = iamConfigPrefix + "/users/"
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// IAM groups directory.
|
|
|
|
iamConfigGroupsPrefix = iamConfigPrefix + "/groups/"
|
|
|
|
|
2018-10-16 15:48:19 -04:00
|
|
|
// IAM policies directory.
|
|
|
|
iamConfigPoliciesPrefix = iamConfigPrefix + "/policies/"
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
// IAM sts directory.
|
|
|
|
iamConfigSTSPrefix = iamConfigPrefix + "/sts/"
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
// IAM Policy DB prefixes.
|
|
|
|
iamConfigPolicyDBPrefix = iamConfigPrefix + "/policydb/"
|
|
|
|
iamConfigPolicyDBUsersPrefix = iamConfigPolicyDBPrefix + "users/"
|
|
|
|
iamConfigPolicyDBSTSUsersPrefix = iamConfigPolicyDBPrefix + "sts-users/"
|
2019-08-02 17:25:00 -04:00
|
|
|
iamConfigPolicyDBGroupsPrefix = iamConfigPolicyDBPrefix + "groups/"
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
// IAM identity file which captures identity credentials.
|
|
|
|
iamIdentityFile = "identity.json"
|
|
|
|
|
|
|
|
// IAM policy file which provides policies for each users.
|
|
|
|
iamPolicyFile = "policy.json"
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// IAM group members file
|
|
|
|
iamGroupMembersFile = "members.json"
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
// IAM format file
|
|
|
|
iamFormatFile = "format.json"
|
|
|
|
|
|
|
|
iamFormatVersion1 = 1
|
2018-10-09 17:00:01 -04:00
|
|
|
)
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
const (
|
|
|
|
statusEnabled = "enabled"
|
|
|
|
statusDisabled = "disabled"
|
|
|
|
)
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
type iamFormat struct {
|
|
|
|
Version int `json:"version"`
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
func newIAMFormatVersion1() iamFormat {
|
2019-07-24 20:34:23 -04:00
|
|
|
return iamFormat{Version: iamFormatVersion1}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getIAMFormatFilePath() string {
|
2019-08-06 15:08:58 -04:00
|
|
|
return iamConfigPrefix + SlashSeparator + iamFormatFile
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func getUserIdentityPath(user string, isSTS bool) string {
|
|
|
|
basePath := iamConfigUsersPrefix
|
|
|
|
if isSTS {
|
|
|
|
basePath = iamConfigSTSPrefix
|
|
|
|
}
|
|
|
|
return pathJoin(basePath, user, iamIdentityFile)
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
func getGroupInfoPath(group string) string {
|
|
|
|
return pathJoin(iamConfigGroupsPrefix, group, iamGroupMembersFile)
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
func getPolicyDocPath(name string) string {
|
|
|
|
return pathJoin(iamConfigPoliciesPrefix, name, iamPolicyFile)
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
func getMappedPolicyPath(name string, isSTS, isGroup bool) string {
|
|
|
|
switch {
|
|
|
|
case isSTS:
|
2019-07-24 20:34:23 -04:00
|
|
|
return pathJoin(iamConfigPolicyDBSTSUsersPrefix, name+".json")
|
2019-08-02 17:25:00 -04:00
|
|
|
case isGroup:
|
|
|
|
return pathJoin(iamConfigPolicyDBGroupsPrefix, name+".json")
|
|
|
|
default:
|
|
|
|
return pathJoin(iamConfigPolicyDBUsersPrefix, name+".json")
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserIdentity represents a user's secret key and their status
|
|
|
|
type UserIdentity struct {
|
|
|
|
Version int `json:"version"`
|
|
|
|
Credentials auth.Credentials `json:"credentials"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func newUserIdentity(creds auth.Credentials) UserIdentity {
|
|
|
|
return UserIdentity{Version: 1, Credentials: creds}
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// GroupInfo contains info about a group
|
|
|
|
type GroupInfo struct {
|
|
|
|
Version int `json:"version"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
Members []string `json:"members"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func newGroupInfo(members []string) GroupInfo {
|
|
|
|
return GroupInfo{Version: 1, Status: statusEnabled, Members: members}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MappedPolicy represents a policy name mapped to a user or group
|
|
|
|
type MappedPolicy struct {
|
|
|
|
Version int `json:"version"`
|
|
|
|
Policy string `json:"policy"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMappedPolicy(policy string) MappedPolicy {
|
|
|
|
return MappedPolicy{Version: 1, Policy: policy}
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
// IAMSys - config system.
|
|
|
|
type IAMSys struct {
|
|
|
|
sync.RWMutex
|
2019-09-09 19:12:29 -04:00
|
|
|
|
|
|
|
usersSysType UsersSysType
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
// map of policy names to policy definitions
|
|
|
|
iamPolicyDocsMap map[string]iampolicy.Policy
|
2019-08-02 17:25:00 -04:00
|
|
|
// map of usernames to credentials
|
|
|
|
iamUsersMap map[string]auth.Credentials
|
|
|
|
// map of group names to group info
|
|
|
|
iamGroupsMap map[string]GroupInfo
|
|
|
|
// map of user names to groups they are a member of
|
|
|
|
iamUserGroupMemberships map[string]set.StringSet
|
2019-07-24 20:34:23 -04:00
|
|
|
// map of usernames/temporary access keys to policy names
|
|
|
|
iamUserPolicyMap map[string]MappedPolicy
|
2019-08-02 17:25:00 -04:00
|
|
|
// map of group names to policy names
|
|
|
|
iamGroupPolicyMap map[string]MappedPolicy
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
// Persistence layer for IAM subsystem
|
|
|
|
store IAMStorageAPI
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
// IAMStorageAPI defines an interface for the IAM persistence layer
|
|
|
|
type IAMStorageAPI interface {
|
|
|
|
migrateBackendFormat(ObjectLayer) error
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
loadPolicyDoc(policy string, m map[string]iampolicy.Policy) error
|
|
|
|
loadPolicyDocs(m map[string]iampolicy.Policy) error
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
loadUser(user string, isSTS bool, m map[string]auth.Credentials) error
|
|
|
|
loadUsers(isSTS bool, m map[string]auth.Credentials) error
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
loadGroup(group string, m map[string]GroupInfo) error
|
|
|
|
loadGroups(m map[string]GroupInfo) error
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
loadMappedPolicy(name string, isSTS, isGroup bool, m map[string]MappedPolicy) error
|
|
|
|
loadMappedPolicies(isSTS, isGroup bool, m map[string]MappedPolicy) error
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
loadAll(*IAMSys, ObjectLayer) error
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
saveIAMConfig(item interface{}, path string) error
|
|
|
|
loadIAMConfig(item interface{}, path string) error
|
|
|
|
deleteIAMConfig(path string) error
|
2019-08-02 17:25:00 -04:00
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
savePolicyDoc(policyName string, p iampolicy.Policy) error
|
|
|
|
saveMappedPolicy(name string, isSTS, isGroup bool, mp MappedPolicy) error
|
|
|
|
saveUserIdentity(name string, isSTS bool, u UserIdentity) error
|
|
|
|
saveGroupInfo(group string, gi GroupInfo) error
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
deletePolicyDoc(policyName string) error
|
|
|
|
deleteMappedPolicy(name string, isSTS, isGroup bool) error
|
|
|
|
deleteUserIdentity(name string, isSTS bool) error
|
|
|
|
deleteGroupInfo(name string) error
|
2019-07-24 20:34:23 -04:00
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
watch(*IAMSys)
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// LoadGroup - loads a specific group from storage, and updates the
|
|
|
|
// memberships cache. If the specified group does not exist in
|
|
|
|
// storage, it is removed from in-memory maps as well - this
|
|
|
|
// simplifies the implementation for group removal. This is called
|
|
|
|
// only via IAM notifications.
|
|
|
|
func (sys *IAMSys) LoadGroup(objAPI ObjectLayer, group string) error {
|
|
|
|
if objAPI == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
if globalEtcdClient != nil {
|
|
|
|
// Watch APIs cover this case, so nothing to do.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
err := sys.store.loadGroup(group, sys.iamGroupsMap)
|
2019-08-02 17:25:00 -04:00
|
|
|
if err != nil && err != errConfigNotFound {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err == errConfigNotFound {
|
|
|
|
// group does not exist - so remove from memory.
|
|
|
|
sys.removeGroupFromMembershipsMap(group)
|
|
|
|
delete(sys.iamGroupsMap, group)
|
|
|
|
delete(sys.iamGroupPolicyMap, group)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
gi := sys.iamGroupsMap[group]
|
|
|
|
|
|
|
|
// Updating the group memberships cache happens in two steps:
|
|
|
|
//
|
|
|
|
// 1. Remove the group from each user's list of memberships.
|
|
|
|
// 2. Add the group to each member's list of memberships.
|
|
|
|
//
|
|
|
|
// This ensures that regardless of members being added or
|
|
|
|
// removed, the cache stays current.
|
|
|
|
sys.removeGroupFromMembershipsMap(group)
|
|
|
|
sys.updateGroupMembershipsMap(group, &gi)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-06 20:46:22 -04:00
|
|
|
// LoadPolicy - reloads a specific canned policy from backend disks or etcd.
|
|
|
|
func (sys *IAMSys) LoadPolicy(objAPI ObjectLayer, policyName string) error {
|
|
|
|
if objAPI == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
if globalEtcdClient == nil {
|
2019-08-08 18:10:04 -04:00
|
|
|
return sys.store.loadPolicyDoc(policyName, sys.iamPolicyDocsMap)
|
2019-06-06 20:46:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// When etcd is set, we use watch APIs so this code is not needed.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
// LoadPolicyMapping - loads the mapped policy for a user or group
|
|
|
|
// from storage into server memory.
|
|
|
|
func (sys *IAMSys) LoadPolicyMapping(objAPI ObjectLayer, userOrGroup string, isGroup bool) error {
|
|
|
|
if objAPI == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
if globalEtcdClient == nil {
|
|
|
|
var err error
|
|
|
|
if isGroup {
|
|
|
|
err = sys.store.loadMappedPolicy(userOrGroup, false, isGroup, sys.iamGroupPolicyMap)
|
|
|
|
} else {
|
|
|
|
err = sys.store.loadMappedPolicy(userOrGroup, false, isGroup, sys.iamUserPolicyMap)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore policy not mapped error
|
|
|
|
if err != nil && err != errConfigNotFound {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// When etcd is set, we use watch APIs so this code is not needed.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-06 20:46:22 -04:00
|
|
|
// LoadUser - reloads a specific user from backend disks or etcd.
|
2019-07-24 20:34:23 -04:00
|
|
|
func (sys *IAMSys) LoadUser(objAPI ObjectLayer, accessKey string, isSTS bool) error {
|
2019-06-06 20:46:22 -04:00
|
|
|
if objAPI == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
if globalEtcdClient == nil {
|
2019-08-08 18:10:04 -04:00
|
|
|
err := sys.store.loadUser(accessKey, isSTS, sys.iamUsersMap)
|
2019-07-24 20:34:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-08-08 18:10:04 -04:00
|
|
|
err = sys.store.loadMappedPolicy(accessKey, isSTS, false, sys.iamUserPolicyMap)
|
|
|
|
// Ignore policy not mapped error
|
|
|
|
if err != nil && err != errConfigNotFound {
|
2019-07-24 20:34:23 -04:00
|
|
|
return err
|
|
|
|
}
|
2019-06-06 20:46:22 -04:00
|
|
|
}
|
|
|
|
// When etcd is set, we use watch APIs so this code is not needed.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-12-18 17:39:21 -05:00
|
|
|
// Load - loads iam subsystem
|
2019-08-08 18:10:04 -04:00
|
|
|
func (sys *IAMSys) Load() error {
|
|
|
|
// Pass nil objectlayer here - it will be loaded internally
|
|
|
|
// from the IAMStorageAPI.
|
|
|
|
return sys.store.loadAll(sys, nil)
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Perform IAM configuration migration.
|
2019-08-08 18:10:04 -04:00
|
|
|
func (sys *IAMSys) doIAMConfigMigration(objAPI ObjectLayer) error {
|
2019-07-24 20:34:23 -04:00
|
|
|
// Take IAM configuration migration lock
|
|
|
|
lockPath := iamConfigPrefix + "/migration.lock"
|
2019-11-13 15:17:45 -05:00
|
|
|
objLock := objAPI.NewNSLock(context.Background(), minioMetaBucket, lockPath)
|
2019-07-24 20:34:23 -04:00
|
|
|
if err := objLock.GetLock(globalOperationTimeout); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer objLock.Unlock()
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
return sys.store.migrateBackendFormat(objAPI)
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
// Init - initializes config system from iam.json
|
|
|
|
func (sys *IAMSys) Init(objAPI ObjectLayer) error {
|
|
|
|
if objAPI == nil {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
if globalEtcdClient == nil {
|
|
|
|
sys.store = newIAMObjectStore()
|
|
|
|
} else {
|
|
|
|
sys.store = newIAMEtcdStore()
|
|
|
|
}
|
|
|
|
|
2019-08-05 14:45:30 -04:00
|
|
|
doneCh := make(chan struct{})
|
|
|
|
defer close(doneCh)
|
|
|
|
|
|
|
|
// Migrating IAM needs a retry mechanism for
|
|
|
|
// the following reasons:
|
|
|
|
// - Read quorum is lost just after the initialization
|
|
|
|
// of the object layer.
|
|
|
|
for range newRetryTimerSimple(doneCh) {
|
|
|
|
// Migrate IAM configuration
|
2019-08-08 18:10:04 -04:00
|
|
|
if err := sys.doIAMConfigMigration(objAPI); err != nil {
|
2019-08-05 14:45:30 -04:00
|
|
|
if err == errDiskNotFound ||
|
|
|
|
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
|
|
|
|
strings.Contains(err.Error(), InsufficientWriteQuorum{}.Error()) {
|
|
|
|
logger.Info("Waiting for IAM subsystem to be initialized..")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
break
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
sys.store.watch(sys)
|
2018-10-09 17:00:01 -04:00
|
|
|
|
2018-10-12 14:32:18 -04:00
|
|
|
// Initializing IAM needs a retry mechanism for
|
|
|
|
// the following reasons:
|
|
|
|
// - Read quorum is lost just after the initialization
|
|
|
|
// of the object layer.
|
2019-02-13 07:59:36 -05:00
|
|
|
for range newRetryTimerSimple(doneCh) {
|
2019-08-08 18:10:04 -04:00
|
|
|
// Load IAMSys once during boot. Need to pass in
|
|
|
|
// objAPI as server has not yet initialized.
|
|
|
|
if err := sys.store.loadAll(sys, objAPI); err != nil {
|
2019-02-13 07:59:36 -05:00
|
|
|
if err == errDiskNotFound ||
|
|
|
|
strings.Contains(err.Error(), InsufficientReadQuorum{}.Error()) ||
|
|
|
|
strings.Contains(err.Error(), InsufficientWriteQuorum{}.Error()) {
|
|
|
|
logger.Info("Waiting for IAM subsystem to be initialized..")
|
|
|
|
continue
|
2018-10-12 14:32:18 -04:00
|
|
|
}
|
2019-02-13 07:59:36 -05:00
|
|
|
return err
|
2018-10-12 14:32:18 -04:00
|
|
|
}
|
2019-02-13 07:59:36 -05:00
|
|
|
break
|
2018-10-12 14:32:18 -04:00
|
|
|
}
|
2019-08-01 15:31:04 -04:00
|
|
|
|
2019-02-13 07:59:36 -05:00
|
|
|
return nil
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
|
|
|
|
2019-06-06 20:46:22 -04:00
|
|
|
// DeletePolicy - deletes a canned policy from backend or etcd.
|
|
|
|
func (sys *IAMSys) DeletePolicy(policyName string) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-10-09 17:00:01 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
2018-10-16 15:48:19 -04:00
|
|
|
if policyName == "" {
|
|
|
|
return errInvalidArgument
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
err := sys.store.deletePolicyDoc(policyName)
|
2019-06-06 20:46:22 -04:00
|
|
|
switch err.(type) {
|
|
|
|
case ObjectNotFound:
|
|
|
|
// Ignore error if policy is already deleted.
|
|
|
|
err = nil
|
2018-10-12 14:32:18 -04:00
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
delete(sys.iamPolicyDocsMap, policyName)
|
2018-10-16 15:48:19 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-09-26 14:23:13 -04:00
|
|
|
// InfoPolicy - expands the canned policy into its JSON structure.
|
|
|
|
func (sys *IAMSys) InfoPolicy(policyName string) ([]byte, error) {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2019-09-26 14:23:13 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return nil, errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
|
|
|
v, ok := sys.iamPolicyDocsMap[policyName]
|
|
|
|
if !ok {
|
|
|
|
return nil, errNoSuchPolicy
|
|
|
|
}
|
|
|
|
return json.Marshal(v)
|
|
|
|
}
|
|
|
|
|
2019-06-06 20:46:22 -04:00
|
|
|
// ListPolicies - lists all canned policies.
|
|
|
|
func (sys *IAMSys) ListPolicies() (map[string][]byte, error) {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-10-16 15:48:19 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return nil, errServerNotInitialized
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
var policyDocsMap = make(map[string][]byte)
|
2018-10-16 15:48:19 -04:00
|
|
|
|
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
for k, v := range sys.iamPolicyDocsMap {
|
2018-10-16 15:48:19 -04:00
|
|
|
data, err := json.Marshal(v)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-07-24 20:34:23 -04:00
|
|
|
policyDocsMap[k] = data
|
2018-10-16 15:48:19 -04:00
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
return policyDocsMap, nil
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
// SetPolicy - sets a new name policy.
|
2019-06-06 20:46:22 -04:00
|
|
|
func (sys *IAMSys) SetPolicy(policyName string, p iampolicy.Policy) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-10-09 17:00:01 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
2018-10-16 15:48:19 -04:00
|
|
|
if p.IsEmpty() || policyName == "" {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
if err := sys.store.savePolicyDoc(policyName, p); err != nil {
|
2018-10-16 15:48:19 -04:00
|
|
|
return err
|
2018-10-12 14:32:18 -04:00
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
2019-07-24 20:34:23 -04:00
|
|
|
sys.iamPolicyDocsMap[policyName] = p
|
2018-10-09 17:00:01 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
// DeleteUser - delete user (only for long-term users not STS users).
|
2018-10-09 17:00:01 -04:00
|
|
|
func (sys *IAMSys) DeleteUser(accessKey string) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-10-09 17:00:01 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return errIAMActionNotAllowed
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
// It is ok to ignore deletion error on the mapped policy
|
|
|
|
sys.store.deleteMappedPolicy(accessKey, false, false)
|
|
|
|
err := sys.store.deleteUserIdentity(accessKey, false)
|
2018-10-16 15:48:19 -04:00
|
|
|
switch err.(type) {
|
|
|
|
case ObjectNotFound:
|
2019-06-06 20:46:22 -04:00
|
|
|
// ignore if user is already deleted.
|
|
|
|
err = nil
|
2018-10-12 14:32:18 -04:00
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
delete(sys.iamUsersMap, accessKey)
|
2019-07-24 20:34:23 -04:00
|
|
|
delete(sys.iamUserPolicyMap, accessKey)
|
2018-10-16 15:48:19 -04:00
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTempUser - set temporary user credentials, these credentials have an expiry.
|
2018-10-29 14:08:59 -04:00
|
|
|
func (sys *IAMSys) SetTempUser(accessKey string, cred auth.Credentials, policyName string) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-10-09 17:00:01 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
2018-10-29 14:08:59 -04:00
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
|
|
|
// If OPA is not set we honor any policy claims for this
|
|
|
|
// temporary user which match with pre-configured canned
|
|
|
|
// policies for this server.
|
|
|
|
if globalPolicyOPA == nil && policyName != "" {
|
2019-07-24 20:34:23 -04:00
|
|
|
p, ok := sys.iamPolicyDocsMap[policyName]
|
2018-10-29 14:08:59 -04:00
|
|
|
if !ok {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
if p.IsEmpty() {
|
2019-07-24 20:34:23 -04:00
|
|
|
delete(sys.iamUserPolicyMap, accessKey)
|
2018-10-29 14:08:59 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
mp := newMappedPolicy(policyName)
|
2019-08-08 18:10:04 -04:00
|
|
|
if err := sys.store.saveMappedPolicy(accessKey, true, false, mp); err != nil {
|
2018-10-29 14:08:59 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
sys.iamUserPolicyMap[accessKey] = mp
|
2018-10-29 14:08:59 -04:00
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
u := newUserIdentity(cred)
|
2019-08-08 18:10:04 -04:00
|
|
|
if err := sys.store.saveUserIdentity(accessKey, true, u); err != nil {
|
2018-10-16 15:48:19 -04:00
|
|
|
return err
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sys.iamUsersMap[accessKey] = cred
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-10-13 03:18:43 -04:00
|
|
|
// ListUsers - list all users.
|
|
|
|
func (sys *IAMSys) ListUsers() (map[string]madmin.UserInfo, error) {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-10-13 03:18:43 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return nil, errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
var users = make(map[string]madmin.UserInfo)
|
|
|
|
|
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return nil, errIAMActionNotAllowed
|
|
|
|
}
|
|
|
|
|
2018-10-13 03:18:43 -04:00
|
|
|
for k, v := range sys.iamUsersMap {
|
|
|
|
users[k] = madmin.UserInfo{
|
2019-07-24 20:34:23 -04:00
|
|
|
PolicyName: sys.iamUserPolicyMap[k].Policy,
|
2019-11-12 06:16:25 -05:00
|
|
|
Status: func() madmin.AccountStatus {
|
|
|
|
if v.IsValid() {
|
|
|
|
return madmin.AccountEnabled
|
|
|
|
}
|
|
|
|
return madmin.AccountDisabled
|
|
|
|
}(),
|
2018-10-13 03:18:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return users, nil
|
|
|
|
}
|
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
// GetUserInfo - get info on a user.
|
|
|
|
func (sys *IAMSys) GetUserInfo(name string) (u madmin.UserInfo, err error) {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2019-08-13 16:41:06 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return u, errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return madmin.UserInfo{
|
|
|
|
PolicyName: sys.iamUserPolicyMap[name].Policy,
|
2019-09-26 14:23:13 -04:00
|
|
|
MemberOf: sys.iamUserGroupMemberships[name].ToSlice(),
|
2019-09-09 19:12:29 -04:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
creds, found := sys.iamUsersMap[name]
|
|
|
|
if !found {
|
|
|
|
return u, errNoSuchUser
|
|
|
|
}
|
|
|
|
|
|
|
|
u = madmin.UserInfo{
|
|
|
|
PolicyName: sys.iamUserPolicyMap[name].Policy,
|
2019-11-12 06:16:25 -05:00
|
|
|
Status: func() madmin.AccountStatus {
|
|
|
|
if creds.IsValid() {
|
|
|
|
return madmin.AccountEnabled
|
|
|
|
}
|
|
|
|
return madmin.AccountDisabled
|
|
|
|
}(),
|
|
|
|
MemberOf: sys.iamUserGroupMemberships[name].ToSlice(),
|
2019-08-13 16:41:06 -04:00
|
|
|
}
|
|
|
|
return u, nil
|
|
|
|
}
|
|
|
|
|
2018-10-16 17:55:23 -04:00
|
|
|
// SetUserStatus - sets current user status, supports disabled or enabled.
|
|
|
|
func (sys *IAMSys) SetUserStatus(accessKey string, status madmin.AccountStatus) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-10-16 17:55:23 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
if status != madmin.AccountEnabled && status != madmin.AccountDisabled {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return errIAMActionNotAllowed
|
|
|
|
}
|
|
|
|
|
2018-10-16 17:55:23 -04:00
|
|
|
cred, ok := sys.iamUsersMap[accessKey]
|
|
|
|
if !ok {
|
|
|
|
return errNoSuchUser
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
uinfo := newUserIdentity(auth.Credentials{
|
|
|
|
AccessKey: accessKey,
|
2018-10-16 17:55:23 -04:00
|
|
|
SecretKey: cred.SecretKey,
|
2019-11-13 20:38:05 -05:00
|
|
|
Status: func() string {
|
|
|
|
if status == madmin.AccountEnabled {
|
2019-12-04 18:32:37 -05:00
|
|
|
return config.EnableOn
|
2019-11-13 20:38:05 -05:00
|
|
|
}
|
2019-12-04 18:32:37 -05:00
|
|
|
return config.EnableOff
|
2019-11-13 20:38:05 -05:00
|
|
|
}(),
|
2019-07-24 20:34:23 -04:00
|
|
|
})
|
2019-08-08 18:10:04 -04:00
|
|
|
if err := sys.store.saveUserIdentity(accessKey, false, uinfo); err != nil {
|
2018-10-16 17:55:23 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
sys.iamUsersMap[accessKey] = uinfo.Credentials
|
2018-10-16 17:55:23 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
// SetUser - set user credentials and policy.
|
2018-10-09 17:00:01 -04:00
|
|
|
func (sys *IAMSys) SetUser(accessKey string, uinfo madmin.UserInfo) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2018-10-09 17:00:01 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
u := newUserIdentity(auth.Credentials{
|
|
|
|
AccessKey: accessKey,
|
|
|
|
SecretKey: uinfo.SecretKey,
|
|
|
|
Status: string(uinfo.Status),
|
|
|
|
})
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
2018-10-09 17:00:01 -04:00
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return errIAMActionNotAllowed
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
if err := sys.store.saveUserIdentity(accessKey, false, u); err != nil {
|
2018-10-16 15:48:19 -04:00
|
|
|
return err
|
2018-10-12 14:32:18 -04:00
|
|
|
}
|
2019-07-24 20:34:23 -04:00
|
|
|
sys.iamUsersMap[accessKey] = u.Credentials
|
2018-10-12 14:32:18 -04:00
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
// Set policy if specified.
|
|
|
|
if uinfo.PolicyName != "" {
|
2019-10-15 21:35:41 -04:00
|
|
|
return sys.policyDBSet(accessKey, uinfo.PolicyName, false, false)
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-29 16:18:46 -04:00
|
|
|
// SetUserSecretKey - sets user secret key
|
|
|
|
func (sys *IAMSys) SetUserSecretKey(accessKey string, secretKey string) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2019-05-29 16:18:46 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return errIAMActionNotAllowed
|
|
|
|
}
|
|
|
|
|
2019-05-29 16:18:46 -04:00
|
|
|
cred, ok := sys.iamUsersMap[accessKey]
|
|
|
|
if !ok {
|
|
|
|
return errNoSuchUser
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
cred.SecretKey = secretKey
|
|
|
|
u := newUserIdentity(cred)
|
2019-08-08 18:10:04 -04:00
|
|
|
if err := sys.store.saveUserIdentity(accessKey, false, u); err != nil {
|
2019-05-29 16:18:46 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
sys.iamUsersMap[accessKey] = cred
|
2019-05-29 16:18:46 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
// GetUser - get user credentials
|
|
|
|
func (sys *IAMSys) GetUser(accessKey string) (cred auth.Credentials, ok bool) {
|
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
|
|
|
cred, ok = sys.iamUsersMap[accessKey]
|
|
|
|
return cred, ok && cred.IsValid()
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// AddUsersToGroup - adds users to a group, creating the group if
|
|
|
|
// needed. No error if user(s) already are in the group.
|
|
|
|
func (sys *IAMSys) AddUsersToGroup(group string, members []string) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2019-08-02 17:25:00 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
if group == "" {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return errIAMActionNotAllowed
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// Validate that all members exist.
|
|
|
|
for _, member := range members {
|
|
|
|
_, ok := sys.iamUsersMap[member]
|
|
|
|
if !ok {
|
|
|
|
return errNoSuchUser
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gi, ok := sys.iamGroupsMap[group]
|
|
|
|
if !ok {
|
|
|
|
// Set group as enabled by default when it doesn't
|
|
|
|
// exist.
|
|
|
|
gi = newGroupInfo(members)
|
|
|
|
} else {
|
|
|
|
mergedMembers := append(gi.Members, members...)
|
|
|
|
uniqMembers := set.CreateStringSet(mergedMembers...).ToSlice()
|
|
|
|
gi.Members = uniqMembers
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
if err := sys.store.saveGroupInfo(group, gi); err != nil {
|
2019-08-02 17:25:00 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.iamGroupsMap[group] = gi
|
|
|
|
|
|
|
|
// update user-group membership map
|
|
|
|
for _, member := range members {
|
|
|
|
gset := sys.iamUserGroupMemberships[member]
|
|
|
|
if gset == nil {
|
|
|
|
gset = set.CreateStringSet(group)
|
|
|
|
} else {
|
|
|
|
gset.Add(group)
|
|
|
|
}
|
|
|
|
sys.iamUserGroupMemberships[member] = gset
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveUsersFromGroup - remove users from group. If no users are
|
|
|
|
// given, and the group is empty, deletes the group as well.
|
|
|
|
func (sys *IAMSys) RemoveUsersFromGroup(group string, members []string) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2019-08-02 17:25:00 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
if group == "" {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return errIAMActionNotAllowed
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// Validate that all members exist.
|
|
|
|
for _, member := range members {
|
|
|
|
_, ok := sys.iamUsersMap[member]
|
|
|
|
if !ok {
|
|
|
|
return errNoSuchUser
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gi, ok := sys.iamGroupsMap[group]
|
|
|
|
if !ok {
|
|
|
|
return errNoSuchGroup
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if attempting to delete a non-empty group.
|
|
|
|
if len(members) == 0 && len(gi.Members) != 0 {
|
|
|
|
return errGroupNotEmpty
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(members) == 0 {
|
|
|
|
// len(gi.Members) == 0 here.
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
// Remove the group from storage. First delete the
|
|
|
|
// mapped policy.
|
|
|
|
err := sys.store.deleteMappedPolicy(group, false, true)
|
|
|
|
// No-mapped-policy case is ignored.
|
|
|
|
if err != nil && err != errConfigNotFound {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = sys.store.deleteGroupInfo(group)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2019-08-02 17:25:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete from server memory
|
|
|
|
delete(sys.iamGroupsMap, group)
|
|
|
|
delete(sys.iamGroupPolicyMap, group)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only removing members.
|
|
|
|
s := set.CreateStringSet(gi.Members...)
|
|
|
|
d := set.CreateStringSet(members...)
|
|
|
|
gi.Members = s.Difference(d).ToSlice()
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
err := sys.store.saveGroupInfo(group, gi)
|
2019-08-02 17:25:00 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
sys.iamGroupsMap[group] = gi
|
|
|
|
|
|
|
|
// update user-group membership map
|
|
|
|
for _, member := range members {
|
|
|
|
gset := sys.iamUserGroupMemberships[member]
|
|
|
|
if gset == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
gset.Remove(group)
|
|
|
|
sys.iamUserGroupMemberships[member] = gset
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGroupStatus - enable/disabled a group
|
|
|
|
func (sys *IAMSys) SetGroupStatus(group string, enabled bool) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2019-08-02 17:25:00 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return errIAMActionNotAllowed
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
if group == "" {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
|
|
|
|
|
|
|
gi, ok := sys.iamGroupsMap[group]
|
|
|
|
if !ok {
|
|
|
|
return errNoSuchGroup
|
|
|
|
}
|
|
|
|
|
|
|
|
if enabled {
|
|
|
|
gi.Status = statusEnabled
|
|
|
|
} else {
|
|
|
|
gi.Status = statusDisabled
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:10:04 -04:00
|
|
|
if err := sys.store.saveGroupInfo(group, gi); err != nil {
|
2019-08-02 17:25:00 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
sys.iamGroupsMap[group] = gi
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetGroupDescription - builds up group description
|
|
|
|
func (sys *IAMSys) GetGroupDescription(group string) (gd madmin.GroupDesc, err error) {
|
2019-08-13 16:41:06 -04:00
|
|
|
ps, err := sys.PolicyDBGet(group, true)
|
|
|
|
if err != nil {
|
|
|
|
return gd, err
|
|
|
|
}
|
2019-09-09 19:12:29 -04:00
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
// A group may be mapped to at most one policy.
|
|
|
|
policy := ""
|
|
|
|
if len(ps) > 0 {
|
|
|
|
policy = ps[0]
|
|
|
|
}
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return madmin.GroupDesc{
|
|
|
|
Name: group,
|
|
|
|
Policy: policy,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2019-09-26 14:23:13 -04:00
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
gi, ok := sys.iamGroupsMap[group]
|
|
|
|
if !ok {
|
|
|
|
return gd, errNoSuchGroup
|
|
|
|
}
|
|
|
|
|
|
|
|
return madmin.GroupDesc{
|
|
|
|
Name: group,
|
|
|
|
Status: gi.Status,
|
|
|
|
Members: gi.Members,
|
|
|
|
Policy: policy,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
// ListGroups - lists groups.
|
|
|
|
func (sys *IAMSys) ListGroups() (r []string, err error) {
|
2019-08-02 17:25:00 -04:00
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
2019-09-09 19:12:29 -04:00
|
|
|
if sys.usersSysType != MinIOUsersSysType {
|
|
|
|
return nil, errIAMActionNotAllowed
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
for k := range sys.iamGroupsMap {
|
|
|
|
r = append(r, k)
|
|
|
|
}
|
2019-09-09 19:12:29 -04:00
|
|
|
return r, nil
|
2019-08-02 17:25:00 -04:00
|
|
|
}
|
|
|
|
|
2019-07-24 20:34:23 -04:00
|
|
|
// PolicyDBSet - sets a policy for a user or group in the
|
|
|
|
// PolicyDB. This function applies only long-term users. For STS
|
|
|
|
// users, policy is set directly by called sys.policyDBSet().
|
2019-08-02 17:25:00 -04:00
|
|
|
func (sys *IAMSys) PolicyDBSet(name, policy string, isGroup bool) error {
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2019-07-24 20:34:23 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return errServerNotInitialized
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.Lock()
|
|
|
|
defer sys.Unlock()
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// isSTS is always false when called via PolicyDBSet as policy
|
|
|
|
// is never set by an external API call for STS users.
|
2019-10-15 21:35:41 -04:00
|
|
|
return sys.policyDBSet(name, policy, false, isGroup)
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// policyDBSet - sets a policy for user in the policy db. Assumes that
|
|
|
|
// caller has sys.Lock().
|
2019-10-15 21:35:41 -04:00
|
|
|
func (sys *IAMSys) policyDBSet(name, policy string, isSTS, isGroup bool) error {
|
2019-07-24 20:34:23 -04:00
|
|
|
if name == "" || policy == "" {
|
|
|
|
return errInvalidArgument
|
|
|
|
}
|
2019-08-08 18:10:04 -04:00
|
|
|
if _, ok := sys.iamPolicyDocsMap[policy]; !ok {
|
2019-07-24 20:34:23 -04:00
|
|
|
return errNoSuchPolicy
|
|
|
|
}
|
2019-09-09 19:12:29 -04:00
|
|
|
|
|
|
|
if sys.usersSysType == MinIOUsersSysType {
|
|
|
|
if !isGroup {
|
|
|
|
if _, ok := sys.iamUsersMap[name]; !ok {
|
|
|
|
return errNoSuchUser
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if _, ok := sys.iamGroupsMap[name]; !ok {
|
|
|
|
return errNoSuchGroup
|
|
|
|
}
|
2019-08-13 16:41:06 -04:00
|
|
|
}
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
2019-08-08 18:10:04 -04:00
|
|
|
|
|
|
|
mp := newMappedPolicy(policy)
|
|
|
|
if err := sys.store.saveMappedPolicy(name, isSTS, isGroup, mp); err != nil {
|
2019-07-24 20:34:23 -04:00
|
|
|
return err
|
|
|
|
}
|
2019-08-13 16:41:06 -04:00
|
|
|
if !isGroup {
|
|
|
|
sys.iamUserPolicyMap[name] = mp
|
|
|
|
} else {
|
|
|
|
sys.iamGroupPolicyMap[name] = mp
|
|
|
|
}
|
2019-07-24 20:34:23 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// PolicyDBGet - gets policy set on a user or group. Since a user may
|
|
|
|
// be a member of multiple groups, this function returns an array of
|
|
|
|
// applicable policies (each group is mapped to at most one policy).
|
|
|
|
func (sys *IAMSys) PolicyDBGet(name string, isGroup bool) ([]string, error) {
|
2019-07-24 20:34:23 -04:00
|
|
|
if name == "" {
|
2019-08-02 17:25:00 -04:00
|
|
|
return nil, errInvalidArgument
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
|
2019-11-09 12:27:23 -05:00
|
|
|
objectAPI := newObjectLayerWithoutSafeModeFn()
|
2019-07-24 20:34:23 -04:00
|
|
|
if objectAPI == nil {
|
2019-08-02 17:25:00 -04:00
|
|
|
return nil, errServerNotInitialized
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
return sys.policyDBGet(name, isGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
// This call assumes that caller has the sys.RLock()
|
|
|
|
func (sys *IAMSys) policyDBGet(name string, isGroup bool) ([]string, error) {
|
|
|
|
if isGroup {
|
|
|
|
if _, ok := sys.iamGroupsMap[name]; !ok {
|
|
|
|
return nil, errNoSuchGroup
|
|
|
|
}
|
|
|
|
|
|
|
|
policy := sys.iamGroupPolicyMap[name]
|
|
|
|
// returned policy could be empty
|
|
|
|
if policy.Policy == "" {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return []string{policy.Policy}, nil
|
|
|
|
}
|
|
|
|
|
2019-08-14 19:59:16 -04:00
|
|
|
// When looking for a user's policies, we also check if the
|
|
|
|
// user and the groups they are member of are enabled.
|
|
|
|
if u, ok := sys.iamUsersMap[name]; !ok {
|
2019-08-02 17:25:00 -04:00
|
|
|
return nil, errNoSuchUser
|
2019-08-14 19:59:16 -04:00
|
|
|
} else if u.Status == statusDisabled {
|
|
|
|
// User is disabled, so we return no policy - this
|
|
|
|
// ensures the request is denied.
|
|
|
|
return nil, nil
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
result := []string{}
|
2019-07-24 20:34:23 -04:00
|
|
|
policy := sys.iamUserPolicyMap[name]
|
|
|
|
// returned policy could be empty
|
2019-08-02 17:25:00 -04:00
|
|
|
if policy.Policy != "" {
|
|
|
|
result = append(result, policy.Policy)
|
|
|
|
}
|
|
|
|
for _, group := range sys.iamUserGroupMemberships[name].ToSlice() {
|
2019-08-14 19:59:16 -04:00
|
|
|
// Skip missing or disabled groups
|
|
|
|
gi, ok := sys.iamGroupsMap[group]
|
|
|
|
if !ok || gi.Status == statusDisabled {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
p, ok := sys.iamGroupPolicyMap[group]
|
|
|
|
if ok && p.Policy != "" {
|
|
|
|
result = append(result, p.Policy)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
2019-07-24 20:34:23 -04:00
|
|
|
}
|
|
|
|
|
2019-06-20 18:28:33 -04:00
|
|
|
// IsAllowedSTS is meant for STS based temporary credentials,
|
|
|
|
// which implements claims validation and verification other than
|
|
|
|
// applying policies.
|
|
|
|
func (sys *IAMSys) IsAllowedSTS(args iampolicy.Args) bool {
|
2019-09-09 19:12:29 -04:00
|
|
|
// If it is an LDAP request, check that user and group
|
|
|
|
// policies allow the request.
|
|
|
|
if userIface, ok := args.Claims[ldapUser]; ok {
|
|
|
|
var user string
|
|
|
|
if u, ok := userIface.(string); ok {
|
|
|
|
user = u
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
var groups []string
|
|
|
|
groupsVal := args.Claims[ldapGroups]
|
|
|
|
if g, ok := groupsVal.([]interface{}); ok {
|
|
|
|
for _, eachG := range g {
|
|
|
|
if eachGStr, ok := eachG.(string); ok {
|
|
|
|
groups = append(groups, eachGStr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
|
|
|
// We look up the policy mapping directly to bypass
|
|
|
|
// users exists, group exists validations that do not
|
|
|
|
// apply here.
|
|
|
|
var policies []iampolicy.Policy
|
|
|
|
if policy, ok := sys.iamUserPolicyMap[user]; ok {
|
|
|
|
p, found := sys.iamPolicyDocsMap[policy.Policy]
|
|
|
|
if found {
|
|
|
|
policies = append(policies, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, group := range groups {
|
|
|
|
policy, ok := sys.iamGroupPolicyMap[group]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
p, found := sys.iamPolicyDocsMap[policy.Policy]
|
|
|
|
if found {
|
|
|
|
policies = append(policies, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(policies) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
combinedPolicy := policies[0]
|
|
|
|
for i := 1; i < len(policies); i++ {
|
|
|
|
combinedPolicy.Statements =
|
|
|
|
append(combinedPolicy.Statements,
|
|
|
|
policies[i].Statements...)
|
|
|
|
}
|
|
|
|
return combinedPolicy.IsAllowed(args)
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
pname, ok := args.Claims[iamPolicyName()]
|
2019-06-20 18:28:33 -04:00
|
|
|
if !ok {
|
|
|
|
// When claims are set, it should have a "policy" field.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
pnameStr, ok := pname.(string)
|
|
|
|
if !ok {
|
|
|
|
// When claims has "policy" field, it should be string.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
2019-06-20 18:28:33 -04:00
|
|
|
// If policy is available for given user, check the policy.
|
2019-07-24 20:34:23 -04:00
|
|
|
mp, ok := sys.iamUserPolicyMap[args.AccountName]
|
2019-06-20 18:28:33 -04:00
|
|
|
if !ok {
|
|
|
|
// No policy available reject.
|
|
|
|
return false
|
|
|
|
}
|
2019-07-24 20:34:23 -04:00
|
|
|
name := mp.Policy
|
2019-06-20 18:28:33 -04:00
|
|
|
|
|
|
|
if pnameStr != name {
|
|
|
|
// When claims has a policy, it should match the
|
|
|
|
// policy of args.AccountName which server remembers.
|
|
|
|
// if not reject such requests.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check if we have a sessionPolicy.
|
|
|
|
spolicy, ok := args.Claims[iampolicy.SessionPolicyName]
|
|
|
|
if !ok {
|
|
|
|
// Sub policy not set, this is most common since subPolicy
|
|
|
|
// is optional, use the top level policy only.
|
2019-07-24 20:34:23 -04:00
|
|
|
p, ok := sys.iamPolicyDocsMap[pnameStr]
|
2019-06-20 18:28:33 -04:00
|
|
|
return ok && p.IsAllowed(args)
|
|
|
|
}
|
|
|
|
|
|
|
|
spolicyStr, ok := spolicy.(string)
|
|
|
|
if !ok {
|
|
|
|
// Sub policy if set, should be a string reject
|
|
|
|
// malformed/malicious requests.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if policy is parseable.
|
|
|
|
subPolicy, err := iampolicy.ParseConfig(bytes.NewReader([]byte(spolicyStr)))
|
|
|
|
if err != nil {
|
|
|
|
// Log any error in input session policy config.
|
|
|
|
logger.LogIf(context.Background(), err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Policy without Version string value reject it.
|
|
|
|
if subPolicy.Version == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sub policy is set and valid.
|
2019-07-24 20:34:23 -04:00
|
|
|
p, ok := sys.iamPolicyDocsMap[pnameStr]
|
2019-06-20 18:28:33 -04:00
|
|
|
return ok && p.IsAllowed(args) && subPolicy.IsAllowed(args)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsAllowed - checks given policy args is allowed to continue the Rest API.
|
|
|
|
func (sys *IAMSys) IsAllowed(args iampolicy.Args) bool {
|
2018-10-15 15:44:03 -04:00
|
|
|
// If opa is configured, use OPA always.
|
|
|
|
if globalPolicyOPA != nil {
|
2019-07-27 23:03:25 -04:00
|
|
|
ok, err := globalPolicyOPA.IsAllowed(args)
|
|
|
|
if err != nil {
|
|
|
|
logger.LogIf(context.Background(), err)
|
|
|
|
}
|
|
|
|
return ok
|
2018-10-15 15:44:03 -04:00
|
|
|
}
|
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
// Policies don't apply to the owner.
|
|
|
|
if args.IsOwner {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
// With claims set, we should do STS related checks and validation.
|
|
|
|
if _, ok := args.Claims["aud"]; ok {
|
|
|
|
return sys.IsAllowedSTS(args)
|
|
|
|
}
|
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
policies, err := sys.PolicyDBGet(args.AccountName, false)
|
|
|
|
if err != nil {
|
|
|
|
logger.LogIf(context.Background(), err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(policies) == 0 {
|
|
|
|
// No policy found.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Policies were found, evaluate all of them.
|
2019-06-20 18:28:33 -04:00
|
|
|
sys.RLock()
|
|
|
|
defer sys.RUnlock()
|
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
var availablePolicies []iampolicy.Policy
|
|
|
|
for _, pname := range policies {
|
|
|
|
p, found := sys.iamPolicyDocsMap[pname]
|
|
|
|
if found {
|
|
|
|
availablePolicies = append(availablePolicies, p)
|
|
|
|
}
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
2019-08-13 16:41:06 -04:00
|
|
|
if len(availablePolicies) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
combinedPolicy := availablePolicies[0]
|
|
|
|
for i := 1; i < len(availablePolicies); i++ {
|
|
|
|
combinedPolicy.Statements = append(combinedPolicy.Statements,
|
|
|
|
availablePolicies[i].Statements...)
|
|
|
|
}
|
|
|
|
return combinedPolicy.IsAllowed(args)
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
|
|
|
|
2018-10-24 20:14:27 -04:00
|
|
|
// Set default canned policies only if not already overridden by users.
|
|
|
|
func setDefaultCannedPolicies(policies map[string]iampolicy.Policy) {
|
|
|
|
_, ok := policies["writeonly"]
|
|
|
|
if !ok {
|
|
|
|
policies["writeonly"] = iampolicy.WriteOnly
|
|
|
|
}
|
|
|
|
_, ok = policies["readonly"]
|
|
|
|
if !ok {
|
|
|
|
policies["readonly"] = iampolicy.ReadOnly
|
|
|
|
}
|
|
|
|
_, ok = policies["readwrite"]
|
|
|
|
if !ok {
|
|
|
|
policies["readwrite"] = iampolicy.ReadWrite
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// buildUserGroupMemberships - builds the memberships map. IMPORTANT:
|
|
|
|
// Assumes that sys.Lock is held by caller.
|
|
|
|
func (sys *IAMSys) buildUserGroupMemberships() {
|
|
|
|
for group, gi := range sys.iamGroupsMap {
|
|
|
|
sys.updateGroupMembershipsMap(group, &gi)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// updateGroupMembershipsMap - updates the memberships map for a
|
|
|
|
// group. IMPORTANT: Assumes sys.Lock() is held by caller.
|
|
|
|
func (sys *IAMSys) updateGroupMembershipsMap(group string, gi *GroupInfo) {
|
|
|
|
if gi == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, member := range gi.Members {
|
|
|
|
v := sys.iamUserGroupMemberships[member]
|
|
|
|
if v == nil {
|
|
|
|
v = set.CreateStringSet(group)
|
|
|
|
} else {
|
|
|
|
v.Add(group)
|
|
|
|
}
|
|
|
|
sys.iamUserGroupMemberships[member] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// removeGroupFromMembershipsMap - removes the group from every member
|
|
|
|
// in the cache. IMPORTANT: Assumes sys.Lock() is held by caller.
|
|
|
|
func (sys *IAMSys) removeGroupFromMembershipsMap(group string) {
|
|
|
|
if _, ok := sys.iamUserGroupMemberships[group]; !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for member, groups := range sys.iamUserGroupMemberships {
|
|
|
|
if !groups.Contains(group) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
groups.Remove(group)
|
|
|
|
sys.iamUserGroupMemberships[member] = groups
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
// NewIAMSys - creates new config system object.
|
|
|
|
func NewIAMSys() *IAMSys {
|
2019-09-09 19:12:29 -04:00
|
|
|
// Check global server configuration to determine the type of
|
|
|
|
// users system configured.
|
|
|
|
|
|
|
|
// The default users system
|
|
|
|
var utype UsersSysType
|
|
|
|
switch {
|
2019-10-23 01:59:13 -04:00
|
|
|
case globalLDAPConfig.Enabled:
|
2019-09-09 19:12:29 -04:00
|
|
|
utype = LDAPUsersSysType
|
|
|
|
default:
|
|
|
|
utype = MinIOUsersSysType
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
return &IAMSys{
|
2019-09-09 19:12:29 -04:00
|
|
|
usersSysType: utype,
|
2019-08-02 17:25:00 -04:00
|
|
|
iamUsersMap: make(map[string]auth.Credentials),
|
|
|
|
iamPolicyDocsMap: make(map[string]iampolicy.Policy),
|
|
|
|
iamUserPolicyMap: make(map[string]MappedPolicy),
|
|
|
|
iamGroupsMap: make(map[string]GroupInfo),
|
|
|
|
iamUserGroupMemberships: make(map[string]set.StringSet),
|
2018-10-09 17:00:01 -04:00
|
|
|
}
|
|
|
|
}
|