]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/sts: code for aws:TagKeys to be used as Condition
authorPritha Srivastava <prsrivas@redhat.com>
Thu, 8 Apr 2021 09:04:23 +0000 (14:34 +0530)
committerPritha Srivastava <prsrivas@redhat.com>
Thu, 18 Aug 2022 08:09:38 +0000 (13:39 +0530)
element of a role's trust and permission policy.

This also includes implementation of ForAnyValue and
ForAllValues to be used in conjunction with
StringLike, StringEquals and StringEqualsIgnoreCase
which are used alongwith aws:TagKeys.

Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
(cherry picked from commit ba19b3a03b9db690bd1423ffa3c0d80b8d38a00d)

src/rgw/rgw_auth.cc
src/rgw/rgw_iam_policy.cc
src/rgw/rgw_iam_policy.h
src/rgw/rgw_iam_policy_keywords.gperf
src/rgw/rgw_iam_policy_keywords.h

index e7c25cf8749290600ef63a1deca9b71c080aa2bd..29254cf15c226c0e01fb55b990be8163ba9f8b85 100644 (file)
@@ -470,6 +470,9 @@ void rgw::auth::WebIdentityApplier::modify_request_state(const DoutPrefixProvide
       s->env.emplace(e_key, val);
       ldpp_dout(dpp, 10) << "RGW Env Tag Key: " << e_key << " Value: " << val << dendl;
 
+      s->env.emplace("aws:TagKeys", key);
+        ldpp_dout(dpp, 10) << "aws:TagKeys: " << key << dendl;
+
       if (s->principal_tags.size() == 50) {
         ldpp_dout(dpp, 0) << "ERROR: Number of tag/value pairs exceeding 50, hence skipping the rest" << dendl;
         break;
@@ -876,6 +879,11 @@ void rgw::auth::RoleApplier::modify_request_state(const DoutPrefixProvider *dpp,
 
   for (auto& m : token_attrs.principal_tags) {
     s->env.emplace(m.first, m.second);
+    ldpp_dout(dpp, 10) << "Principal Tag Key: " << m.first << " Value: " << m.second << dendl;
+    std::size_t pos = m.first.find('/');
+    string key = m.first.substr(pos + 1);
+    s->env.emplace("aws:TagKeys", key);
+    ldpp_dout(dpp, 10) << "aws:TagKeys: " << key << dendl;
   }
 
   s->token_claims.emplace_back("sts");
index f373522d941d469e1d89d99de8a7a36056989aaf..2eb58eb157739e3cf7bb922dddb1f35982f165cc 100644 (file)
@@ -678,7 +678,13 @@ bool Condition::eval(const Environment& env) const {
   }
 
   if (i == env.end()) {
-    return ifexists;
+    if (op == TokenID::ForAllValuesStringEquals ||
+        op == TokenID::ForAllValuesStringEqualsIgnoreCase ||
+        op == TokenID::ForAllValuesStringLike) {
+      return true;
+    } else {
+      return ifexists;
+    }
   }
   const auto& s = i->second;
 
@@ -686,6 +692,7 @@ bool Condition::eval(const Environment& env) const {
 
   switch (op) {
     // String!
+  case TokenID::ForAnyValueStringEquals:
   case TokenID::StringEquals:
     return orrible(std::equal_to<std::string>(), itr, vals);
 
@@ -693,18 +700,29 @@ bool Condition::eval(const Environment& env) const {
     return orrible(std::not_fn(std::equal_to<std::string>()),
                   itr, vals);
 
+  case TokenID::ForAnyValueStringEqualsIgnoreCase:
   case TokenID::StringEqualsIgnoreCase:
     return orrible(ci_equal_to(), itr, vals);
 
   case TokenID::StringNotEqualsIgnoreCase:
     return orrible(std::not_fn(ci_equal_to()), itr, vals);
 
+  case TokenID::ForAnyValueStringLike:
   case TokenID::StringLike:
     return orrible(string_like(), itr, vals);
 
   case TokenID::StringNotLike:
     return orrible(std::not_fn(string_like()), itr, vals);
 
+  case TokenID::ForAllValuesStringEquals:
+    return andible(std::equal_to<std::string>(), itr, vals);
+
+  case TokenID::ForAllValuesStringLike:
+    return andible(string_like(), itr, vals);
+
+  case TokenID::ForAllValuesStringEqualsIgnoreCase:
+    return andible(ci_equal_to(), itr, vals);
+
     // Numeric
   case TokenID::NumericEquals:
     return shortible(std::equal_to<double>(), as_number, s, vals);
index 29e40486fcbe6d07f00e9ae0b82ffd9c53c108fb..7bec679ad7aca2b0802f8eaca61ed79da3f0954c 100644 (file)
@@ -387,6 +387,23 @@ struct Condition {
   };
 
   using unordered_multimap_it_pair = std::pair <std::unordered_multimap<std::string,std::string>::const_iterator, std::unordered_multimap<std::string,std::string>::const_iterator>;
+
+  template<typename F>
+  static bool andible(F&& f, const unordered_multimap_it_pair& it,
+                     const std::vector<std::string>& v) {
+    for (auto itr = it.first; itr != it.second; itr++) {
+      bool matched = false;
+      for (const auto& d : v) {
+        if (std::forward<F>(f)(itr->second, d)) {
+               matched = true;
+      }
+     }
+     if (!matched)
+      return false;
+    }
+    return true;
+  }
+
   template<typename F>
   static bool orrible(F&& f, const unordered_multimap_it_pair& it,
                      const std::vector<std::string>& v) {
index 4f6f22a9b73a7ffd01a71b68da7ed31668ee9151..af73dd130749a0807b3e8d5ff0639db5137f1b5b 100644 (file)
@@ -41,6 +41,12 @@ StringEqualsIgnoreCase, TokenKind::cond_op, TokenID::StringEqualsIgnoreCase, (ui
 StringNotEqualsIgnoreCase, TokenKind::cond_op, TokenID::StringNotEqualsIgnoreCase, (uint64_t) Type::string, true, true
 StringLike, TokenKind::cond_op, TokenID::StringLike, (uint64_t) Type::string, true, true,
 StringNotLike, TokenKind::cond_op, TokenID::StringNotLike, (uint64_t) Type::string, true, true
+ForAllValues:StringEquals, TokenKind::cond_op, TokenID::ForAllValuesStringEquals, (uint64_t) Type::string, true, true
+ForAnyValue:StringEquals, TokenKind::cond_op, TokenID::ForAnyValueStringEquals, (uint64_t) Type::string, true, true
+ForAllValues:StringLike, TokenKind::cond_op, TokenID::ForAllValuesStringLike, (uint64_t) Type::string, true, true
+ForAnyValue:StringLike, TokenKind::cond_op, TokenID::ForAnyValueStringLike, (uint64_t) Type::string, true, true
+ForAllValues:StringEqualsIgnoreCase, TokenKind::cond_op, TokenID::ForAllValuesStringEqualsIgnoreCase, (uint64_t) Type::string, true, true
+ForAnyValue:StringEqualsIgnoreCase, TokenKind::cond_op, TokenID::ForAnyValueStringEqualsIgnoreCase, (uint64_t) Type::string, true, true
 # Numeric
 NumericEquals, TokenKind::cond_op, TokenID::NumericEquals, (uint64_t) Type::number, true, true
 NumericNotEquals, TokenKind::cond_op, TokenID::NumericNotEquals, (uint64_t) Type::number, true, true
index 584a2580b6d672843beceb851eddf51007b4e0d5..1c94dfe17103956c95c0acd7c43880da0cc239f8 100644 (file)
@@ -29,6 +29,9 @@ enum class TokenID {
   // String!
   StringEquals, StringNotEquals, StringEqualsIgnoreCase,
   StringNotEqualsIgnoreCase, StringLike, StringNotLike,
+  ForAllValuesStringEquals, ForAnyValueStringEquals,
+  ForAllValuesStringLike, ForAnyValueStringLike,
+  ForAllValuesStringEqualsIgnoreCase, ForAnyValueStringEqualsIgnoreCase,
 
   // Numeric!
   NumericEquals, NumericNotEquals, NumericLessThan, NumericLessThanEquals,