fix: bootstrap msgs should only be sent at startup (#19985)

This commit is contained in:
Aditya Manthramurthy 2024-06-24 19:30:28 -07:00 committed by GitHub
parent 55ff598b23
commit 7dccd1f589
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 17 deletions

View File

@ -440,12 +440,18 @@ func (iamOS *IAMObjectStore) listAllIAMConfigItems(ctx context.Context) (res map
} }
// Assumes cache is locked by caller. // Assumes cache is locked by caller.
func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iamCache) error { func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iamCache, firstTime bool) error {
bootstrapTraceMsgFirstTime := func(s string) {
if firstTime {
bootstrapTraceMsg(s)
}
}
if iamOS.objAPI == nil { if iamOS.objAPI == nil {
return errServerNotInitialized return errServerNotInitialized
} }
bootstrapTraceMsg("loading all IAM items") bootstrapTraceMsgFirstTime("loading all IAM items")
listedConfigItems, err := iamOS.listAllIAMConfigItems(ctx) listedConfigItems, err := iamOS.listAllIAMConfigItems(ctx)
if err != nil { if err != nil {
@ -454,7 +460,7 @@ func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iam
// Loads things in the same order as `LoadIAMCache()` // Loads things in the same order as `LoadIAMCache()`
bootstrapTraceMsg("loading policy documents") bootstrapTraceMsgFirstTime("loading policy documents")
policiesList := listedConfigItems[policiesListKey] policiesList := listedConfigItems[policiesListKey]
for _, item := range policiesList { for _, item := range policiesList {
@ -466,7 +472,7 @@ func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iam
setDefaultCannedPolicies(cache.iamPolicyDocsMap) setDefaultCannedPolicies(cache.iamPolicyDocsMap)
if iamOS.usersSysType == MinIOUsersSysType { if iamOS.usersSysType == MinIOUsersSysType {
bootstrapTraceMsg("loading regular IAM users") bootstrapTraceMsgFirstTime("loading regular IAM users")
regUsersList := listedConfigItems[usersListKey] regUsersList := listedConfigItems[usersListKey]
for _, item := range regUsersList { for _, item := range regUsersList {
userName := path.Dir(item) userName := path.Dir(item)
@ -475,7 +481,7 @@ func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iam
} }
} }
bootstrapTraceMsg("loading regular IAM groups") bootstrapTraceMsgFirstTime("loading regular IAM groups")
groupsList := listedConfigItems[groupsListKey] groupsList := listedConfigItems[groupsListKey]
for _, item := range groupsList { for _, item := range groupsList {
group := path.Dir(item) group := path.Dir(item)
@ -485,7 +491,7 @@ func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iam
} }
} }
bootstrapTraceMsg("loading user policy mapping") bootstrapTraceMsgFirstTime("loading user policy mapping")
userPolicyMappingsList := listedConfigItems[policyDBUsersListKey] userPolicyMappingsList := listedConfigItems[policyDBUsersListKey]
for _, item := range userPolicyMappingsList { for _, item := range userPolicyMappingsList {
userName := strings.TrimSuffix(item, ".json") userName := strings.TrimSuffix(item, ".json")
@ -494,7 +500,7 @@ func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iam
} }
} }
bootstrapTraceMsg("loading group policy mapping") bootstrapTraceMsgFirstTime("loading group policy mapping")
groupPolicyMappingsList := listedConfigItems[policyDBGroupsListKey] groupPolicyMappingsList := listedConfigItems[policyDBGroupsListKey]
for _, item := range groupPolicyMappingsList { for _, item := range groupPolicyMappingsList {
groupName := strings.TrimSuffix(item, ".json") groupName := strings.TrimSuffix(item, ".json")
@ -503,7 +509,7 @@ func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iam
} }
} }
bootstrapTraceMsg("loading service accounts") bootstrapTraceMsgFirstTime("loading service accounts")
svcAccList := listedConfigItems[svcAccListKey] svcAccList := listedConfigItems[svcAccListKey]
svcUsersMap := make(map[string]UserIdentity, len(svcAccList)) svcUsersMap := make(map[string]UserIdentity, len(svcAccList))
for _, item := range svcAccList { for _, item := range svcAccList {

View File

@ -537,25 +537,25 @@ func setDefaultCannedPolicies(policies map[string]PolicyDoc) {
// LoadIAMCache reads all IAM items and populates a new iamCache object and // LoadIAMCache reads all IAM items and populates a new iamCache object and
// replaces the in-memory cache object. // replaces the in-memory cache object.
func (store *IAMStoreSys) LoadIAMCache(ctx context.Context, firstTime bool) error { func (store *IAMStoreSys) LoadIAMCache(ctx context.Context, firstTime bool) error {
bootstrapTraceMsg := func(s string) { bootstrapTraceMsgFirstTime := func(s string) {
if firstTime { if firstTime {
bootstrapTraceMsg(s) bootstrapTraceMsg(s)
} }
} }
bootstrapTraceMsg("loading IAM data") bootstrapTraceMsgFirstTime("loading IAM data")
newCache := newIamCache() newCache := newIamCache()
loadedAt := time.Now() loadedAt := time.Now()
if iamOS, ok := store.IAMStorageAPI.(*IAMObjectStore); ok { if iamOS, ok := store.IAMStorageAPI.(*IAMObjectStore); ok {
err := iamOS.loadAllFromObjStore(ctx, newCache) err := iamOS.loadAllFromObjStore(ctx, newCache, firstTime)
if err != nil { if err != nil {
return err return err
} }
} else { } else {
bootstrapTraceMsg("loading policy documents") bootstrapTraceMsgFirstTime("loading policy documents")
if err := store.loadPolicyDocs(ctx, newCache.iamPolicyDocsMap); err != nil { if err := store.loadPolicyDocs(ctx, newCache.iamPolicyDocsMap); err != nil {
return err return err
} }
@ -564,29 +564,29 @@ func (store *IAMStoreSys) LoadIAMCache(ctx context.Context, firstTime bool) erro
setDefaultCannedPolicies(newCache.iamPolicyDocsMap) setDefaultCannedPolicies(newCache.iamPolicyDocsMap)
if store.getUsersSysType() == MinIOUsersSysType { if store.getUsersSysType() == MinIOUsersSysType {
bootstrapTraceMsg("loading regular users") bootstrapTraceMsgFirstTime("loading regular users")
if err := store.loadUsers(ctx, regUser, newCache.iamUsersMap); err != nil { if err := store.loadUsers(ctx, regUser, newCache.iamUsersMap); err != nil {
return err return err
} }
bootstrapTraceMsg("loading regular groups") bootstrapTraceMsgFirstTime("loading regular groups")
if err := store.loadGroups(ctx, newCache.iamGroupsMap); err != nil { if err := store.loadGroups(ctx, newCache.iamGroupsMap); err != nil {
return err return err
} }
} }
bootstrapTraceMsg("loading user policy mapping") bootstrapTraceMsgFirstTime("loading user policy mapping")
// load polices mapped to users // load polices mapped to users
if err := store.loadMappedPolicies(ctx, regUser, false, newCache.iamUserPolicyMap); err != nil { if err := store.loadMappedPolicies(ctx, regUser, false, newCache.iamUserPolicyMap); err != nil {
return err return err
} }
bootstrapTraceMsg("loading group policy mapping") bootstrapTraceMsgFirstTime("loading group policy mapping")
// load policies mapped to groups // load policies mapped to groups
if err := store.loadMappedPolicies(ctx, regUser, true, newCache.iamGroupPolicyMap); err != nil { if err := store.loadMappedPolicies(ctx, regUser, true, newCache.iamGroupPolicyMap); err != nil {
return err return err
} }
bootstrapTraceMsg("loading service accounts") bootstrapTraceMsgFirstTime("loading service accounts")
// load service accounts // load service accounts
if err := store.loadUsers(ctx, svcUser, newCache.iamUsersMap); err != nil { if err := store.loadUsers(ctx, svcUser, newCache.iamUsersMap); err != nil {
return err return err