From bf66e9a529fed3d6c460bcdbbd0a60bc167866a4 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 24 Oct 2018 17:40:06 -0700 Subject: [PATCH] Reload etcd users and policies properly (#6694) Currently there was a bug in how we reload users and policies which leads to users/policies going missing due to wrong path construction. Fixes #6693 --- cmd/iam.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/iam.go b/cmd/iam.go index 5b887e234..6440490c1 100644 --- a/cmd/iam.go +++ b/cmd/iam.go @@ -458,7 +458,7 @@ func reloadEtcdUsers(prefix string, usersMap map[string]auth.Credentials, policy // prefix := "config/iam/users/" // v := trim(trim(key, prefix), base(key)) == "newuser" // - user := strings.TrimSuffix(strings.TrimSuffix(string(kv.Key), prefix), path.Base(string(kv.Key))) + user := path.Clean(strings.TrimSuffix(strings.TrimPrefix(string(kv.Key), prefix), path.Base(string(kv.Key)))) if !users.Contains(user) { users.Add(user) } @@ -497,7 +497,7 @@ func reloadEtcdUsers(prefix string, usersMap map[string]auth.Credentials, policy if err = json.Unmarshal(pdata, &policyName); err != nil { return err } - policyMap[path.Base(prefix)] = policyName + policyMap[user] = policyName } } return nil @@ -521,11 +521,11 @@ func reloadEtcdPolicies(prefix string, cannedPolicyMap map[string]iampolicy.Poli // then strip off the remaining basename to obtain the prefix // value, usually in the following form. // - // key := "config/iam/policys/newpolicy/identity.json" - // prefix := "config/iam/policys/" + // key := "config/iam/policies/newpolicy/identity.json" + // prefix := "config/iam/policies/" // v := trim(trim(key, prefix), base(key)) == "newpolicy" // - policyName := strings.TrimSuffix(strings.TrimSuffix(string(kv.Key), prefix), path.Base(string(kv.Key))) + policyName := path.Clean(strings.TrimSuffix(strings.TrimPrefix(string(kv.Key), prefix), path.Base(string(kv.Key)))) if !policies.Contains(policyName) { policies.Add(policyName) } @@ -542,7 +542,7 @@ func reloadEtcdPolicies(prefix string, cannedPolicyMap map[string]iampolicy.Poli if err = json.Unmarshal(pdata, &p); err != nil { return err } - cannedPolicyMap[path.Base(prefix)] = p + cannedPolicyMap[policyName] = p } return nil }