From 81d19156e9cbe1750a20804302534fcfee557f8a Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 18 Nov 2021 23:47:02 -0800 Subject: [PATCH] allow in-memory persistence for gateway (#13694) NAS gateway would persist however with or without etcd as before. --- cmd/iam-dummy-store.go | 46 ++++++++++++++++++++++++++++++++++++++++++ cmd/iam.go | 8 +++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/cmd/iam-dummy-store.go b/cmd/iam-dummy-store.go index f4ebbd1fc..3a4b1c644 100644 --- a/cmd/iam-dummy-store.go +++ b/cmd/iam-dummy-store.go @@ -65,34 +65,80 @@ func (ids *iamDummyStore) migrateBackendFormat(context.Context) error { } func (ids *iamDummyStore) loadPolicyDoc(ctx context.Context, policy string, m map[string]iampolicy.Policy) error { + v, ok := ids.iamPolicyDocsMap[policy] + if !ok { + return errNoSuchPolicy + } + m[policy] = v return nil } func (ids *iamDummyStore) loadPolicyDocs(ctx context.Context, m map[string]iampolicy.Policy) error { + for k, v := range ids.iamPolicyDocsMap { + m[k] = v + } return nil } func (ids *iamDummyStore) loadUser(ctx context.Context, user string, userType IAMUserType, m map[string]auth.Credentials) error { + u, ok := ids.iamUsersMap[user] + if !ok { + return errNoSuchUser + } + ids.iamUsersMap[user] = u return nil } func (ids *iamDummyStore) loadUsers(ctx context.Context, userType IAMUserType, m map[string]auth.Credentials) error { + for k, v := range ids.iamUsersMap { + m[k] = v + } return nil } func (ids *iamDummyStore) loadGroup(ctx context.Context, group string, m map[string]GroupInfo) error { + g, ok := ids.iamGroupsMap[group] + if !ok { + return errNoSuchGroup + } + m[group] = g return nil } func (ids *iamDummyStore) loadGroups(ctx context.Context, m map[string]GroupInfo) error { + for k, v := range ids.iamGroupsMap { + m[k] = v + } return nil } func (ids *iamDummyStore) loadMappedPolicy(ctx context.Context, name string, userType IAMUserType, isGroup bool, m map[string]MappedPolicy) error { + if isGroup { + g, ok := ids.iamGroupPolicyMap[name] + if !ok { + return errNoSuchPolicy + } + m[name] = g + } else { + u, ok := ids.iamUserPolicyMap[name] + if !ok { + return errNoSuchPolicy + } + m[name] = u + } return nil } func (ids *iamDummyStore) loadMappedPolicies(ctx context.Context, userType IAMUserType, isGroup bool, m map[string]MappedPolicy) error { + if !isGroup { + for k, v := range ids.iamUserPolicyMap { + m[k] = v + } + } else { + for k, v := range ids.iamGroupPolicyMap { + m[k] = v + } + } return nil } diff --git a/cmd/iam.go b/cmd/iam.go index 72e2b3dff..b2a575db7 100644 --- a/cmd/iam.go +++ b/cmd/iam.go @@ -151,7 +151,13 @@ func (sys *IAMSys) initStore(objAPI ObjectLayer, etcdClient *etcd.Client) { if etcdClient == nil { if globalIsGateway { - sys.store = &IAMStoreSys{newIAMDummyStore(sys.usersSysType)} + if globalGatewayName == NASBackendGateway { + sys.store = &IAMStoreSys{newIAMObjectStore(objAPI, sys.usersSysType)} + } else { + sys.store = &IAMStoreSys{newIAMDummyStore(sys.usersSysType)} + logger.Info("WARNING: %s gateway is running in-memory IAM store, for persistence please configure etcd", + globalGatewayName) + } } else { sys.store = &IAMStoreSys{newIAMObjectStore(objAPI, sys.usersSysType)} }