@@ -120,6 +120,18 @@ def get_one(self, name, requester_user, scope=None, user=None, decrypt=False):
120120 kvp_api = self ._get_one_by_scope_and_name (
121121 name = key_ref , scope = scope , from_model_kwargs = from_model_kwargs
122122 )
123+ if decrypt and kvp_api .secret :
124+ LOG .audit (
125+ "User %s decrypted the value %s " ,
126+ user ,
127+ name ,
128+ extra = {
129+ "user" : user ,
130+ "scope" : scope ,
131+ "key_name" : name ,
132+ "operation" : "decrypt" ,
133+ },
134+ )
123135
124136 return kvp_api
125137
@@ -212,6 +224,7 @@ def get_all(
212224 kvp_apis_user = []
213225
214226 if scope in [ALL_SCOPE , SYSTEM_SCOPE , FULL_SYSTEM_SCOPE ]:
227+ decrypted_keys = []
215228 # If user has system role, then retrieve all system scoped items
216229 if has_system_role :
217230 raw_filters ["scope" ] = FULL_SYSTEM_SCOPE
@@ -227,6 +240,10 @@ def get_all(
227240 )
228241
229242 kvp_apis_system .extend (items .json or [])
243+ if decrypt and items .json :
244+ decrypted_keys .extend (
245+ kv_api ["name" ] for kv_api in items .json if kv_api ["secret" ]
246+ )
230247 else :
231248 # Otherwise if user is not an admin, then get the list of
232249 # system scoped items that user is granted permission to.
@@ -241,6 +258,21 @@ def get_all(
241258 kvp_apis_system .append (item )
242259 except Exception as e :
243260 LOG .error ("Unable to get key %s: %s" , key , str (e ))
261+ continue
262+ if decrypt and item .secret :
263+ decrypted_keys .append (key )
264+ if decrypted_keys :
265+ LOG .audit (
266+ "User %s decrypted the values %s " ,
267+ user ,
268+ decrypted_keys ,
269+ extra = {
270+ "User" : user ,
271+ "scope" : FULL_SYSTEM_SCOPE ,
272+ "key_name" : decrypted_keys ,
273+ "operation" : "decrypt" ,
274+ },
275+ )
244276
245277 if scope in [ALL_SCOPE , USER_SCOPE , FULL_USER_SCOPE ]:
246278 # Retrieves all the user scoped items that the current user owns.
@@ -257,6 +289,22 @@ def get_all(
257289 )
258290
259291 kvp_apis_user .extend (items .json )
292+ if decrypt and items .json :
293+ decrypted_keys = [
294+ kvp_api ["name" ] for kvp_api in items .json if kvp_api ["secret" ]
295+ ]
296+ if decrypted_keys :
297+ LOG .audit (
298+ "User %s decrypted the values %s " ,
299+ user ,
300+ decrypted_keys ,
301+ extra = {
302+ "User" : user ,
303+ "scope" : FULL_USER_SCOPE ,
304+ "key_name" : decrypted_keys ,
305+ "operation" : "decrypt" ,
306+ },
307+ )
260308
261309 return kvp_apis_system + kvp_apis_user
262310
0 commit comments