Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Key grants are not removed from Redis #14800

Open
jgoizueta opened this issue Apr 2, 2019 · 1 comment
Open

API Key grants are not removed from Redis #14800

jgoizueta opened this issue Apr 2, 2019 · 1 comment
Labels

Comments

@jgoizueta
Copy link
Member

If an API Key is modified and some of its grants removed, this will not be reflected in Redis, because we use HMSET to update the Redis keys (HMSET set the specified fields, any other fields present are left untouched).
We should remove (HDEL) fields not present in the new grants (we could do this by either looking an the record changes or at the Redis hash value.

@jgoizueta jgoizueta added the bug label Apr 2, 2019
@jgoizueta
Copy link
Member Author

I think this could be a fix for this: it sets the removed api grants to false:

diff --git a/app/models/carto/api_key.rb b/app/models/carto/api_key.rb
index 3b0566358c..02be25a153 100644
--- a/app/models/carto/api_key.rb
+++ b/app/models/carto/api_key.rb
@@ -503,9 +503,19 @@ module Carto
       @user_db_connection ||= user.in_database
     end

+    def removed_granted_apis
+      if changes[:grants]
+        old_apis, new_apis = changes[:grants].map { |g| g.find { |v| v[:type] == 'apis' }[:apis] }
+        old_apis - new_apis
+      else
+        []
+      end
+    end
+
     def redis_hash_as_array
       hash = ['user', user.username, 'type', type, 'database_role', db_role, 'database_password', db_password]
       granted_apis.each { |api| hash += ["grants_#{api}", true] }
+      removed_granted_apis.each { |api| hash += ["grants_#{api}", false] }
       hash
     end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant