From 7dccd1f58900169d0163d239f83e471a5b52910f Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Mon, 24 Jun 2024 19:30:28 -0700 Subject: [PATCH] fix: bootstrap msgs should only be sent at startup (#19985) --- cmd/iam-object-store.go | 22 ++++++++++++++-------- cmd/iam-store.go | 18 +++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/cmd/iam-object-store.go b/cmd/iam-object-store.go index 7ef1e406c..b8ba80d62 100644 --- a/cmd/iam-object-store.go +++ b/cmd/iam-object-store.go @@ -440,12 +440,18 @@ func (iamOS *IAMObjectStore) listAllIAMConfigItems(ctx context.Context) (res map } // 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 { return errServerNotInitialized } - bootstrapTraceMsg("loading all IAM items") + bootstrapTraceMsgFirstTime("loading all IAM items") listedConfigItems, err := iamOS.listAllIAMConfigItems(ctx) if err != nil { @@ -454,7 +460,7 @@ func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iam // Loads things in the same order as `LoadIAMCache()` - bootstrapTraceMsg("loading policy documents") + bootstrapTraceMsgFirstTime("loading policy documents") policiesList := listedConfigItems[policiesListKey] for _, item := range policiesList { @@ -466,7 +472,7 @@ func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iam setDefaultCannedPolicies(cache.iamPolicyDocsMap) if iamOS.usersSysType == MinIOUsersSysType { - bootstrapTraceMsg("loading regular IAM users") + bootstrapTraceMsgFirstTime("loading regular IAM users") regUsersList := listedConfigItems[usersListKey] for _, item := range regUsersList { 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] for _, item := range groupsList { 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] for _, item := range userPolicyMappingsList { 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] for _, item := range groupPolicyMappingsList { 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] svcUsersMap := make(map[string]UserIdentity, len(svcAccList)) for _, item := range svcAccList { diff --git a/cmd/iam-store.go b/cmd/iam-store.go index 5b00c499c..59b287ac8 100644 --- a/cmd/iam-store.go +++ b/cmd/iam-store.go @@ -537,25 +537,25 @@ func setDefaultCannedPolicies(policies map[string]PolicyDoc) { // LoadIAMCache reads all IAM items and populates a new iamCache object and // replaces the in-memory cache object. func (store *IAMStoreSys) LoadIAMCache(ctx context.Context, firstTime bool) error { - bootstrapTraceMsg := func(s string) { + bootstrapTraceMsgFirstTime := func(s string) { if firstTime { bootstrapTraceMsg(s) } } - bootstrapTraceMsg("loading IAM data") + bootstrapTraceMsgFirstTime("loading IAM data") newCache := newIamCache() loadedAt := time.Now() if iamOS, ok := store.IAMStorageAPI.(*IAMObjectStore); ok { - err := iamOS.loadAllFromObjStore(ctx, newCache) + err := iamOS.loadAllFromObjStore(ctx, newCache, firstTime) if err != nil { return err } } else { - bootstrapTraceMsg("loading policy documents") + bootstrapTraceMsgFirstTime("loading policy documents") if err := store.loadPolicyDocs(ctx, newCache.iamPolicyDocsMap); err != nil { return err } @@ -564,29 +564,29 @@ func (store *IAMStoreSys) LoadIAMCache(ctx context.Context, firstTime bool) erro setDefaultCannedPolicies(newCache.iamPolicyDocsMap) if store.getUsersSysType() == MinIOUsersSysType { - bootstrapTraceMsg("loading regular users") + bootstrapTraceMsgFirstTime("loading regular users") if err := store.loadUsers(ctx, regUser, newCache.iamUsersMap); err != nil { return err } - bootstrapTraceMsg("loading regular groups") + bootstrapTraceMsgFirstTime("loading regular groups") if err := store.loadGroups(ctx, newCache.iamGroupsMap); err != nil { return err } } - bootstrapTraceMsg("loading user policy mapping") + bootstrapTraceMsgFirstTime("loading user policy mapping") // load polices mapped to users if err := store.loadMappedPolicies(ctx, regUser, false, newCache.iamUserPolicyMap); err != nil { return err } - bootstrapTraceMsg("loading group policy mapping") + bootstrapTraceMsgFirstTime("loading group policy mapping") // load policies mapped to groups if err := store.loadMappedPolicies(ctx, regUser, true, newCache.iamGroupPolicyMap); err != nil { return err } - bootstrapTraceMsg("loading service accounts") + bootstrapTraceMsgFirstTime("loading service accounts") // load service accounts if err := store.loadUsers(ctx, svcUser, newCache.iamUsersMap); err != nil { return err