]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: policy: fix NotPricipal, NotResource does not take effect 23625/head
authorxiangxiang <xiangxiang@xsky.com>
Fri, 17 Aug 2018 09:59:06 +0000 (17:59 +0800)
committerxiangxiang <xiangxiang@xsky.com>
Fri, 14 Sep 2018 09:23:10 +0000 (17:23 +0800)
Signed-off-by: xiangxiang <xiangxiang@xsky.com>
src/rgw/rgw_iam_policy.cc

index 8641d110917469fa103bba1f5223104d2007f198..d45bc952dced94bf7be566adf22fc96d545e4523 100644 (file)
@@ -1280,20 +1280,28 @@ ostream& operator <<(ostream& m, const Condition& c) {
 Effect Statement::eval(const Environment& e,
                       boost::optional<const rgw::auth::Identity&> ida,
                       uint64_t act, const ARN& res) const {
-  if (ida && (!ida->is_identity(princ) || ida->is_identity(noprinc))) {
-    return Effect::Pass;
+  if (ida) {
+    if (!princ.empty() && !ida->is_identity(princ)) {
+      return Effect::Pass;
+    } else if (!noprinc.empty() && ida->is_identity(noprinc)) {
+      return Effect::Pass;
+    }
   }
 
-
-  if (!std::any_of(resource.begin(), resource.end(),
-                  [&res](const ARN& pattern) {
-                    return pattern.match(res);
-                  }) ||
-      (std::any_of(notresource.begin(), notresource.end(),
-                  [&res](const ARN& pattern) {
-                    return pattern.match(res);
-                  }))) {
-    return Effect::Pass;
+  if (!resource.empty()) {
+    if (!std::any_of(resource.begin(), resource.end(),
+          [&res](const ARN& pattern) {
+            return pattern.match(res);
+          })) {
+      return Effect::Pass;
+    }
+  } else if (!notresource.empty()) {
+    if (std::any_of(notresource.begin(), notresource.end(),
+          [&res](const ARN& pattern) {
+            return pattern.match(res);
+          })) {
+      return Effect::Pass;
+    }
   }
 
   if (!(action[act] == 1) || (notaction[act] == 1)) {