From 64fce0fb298ec3497250ff4fce197a204d7ed6d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Thu, 4 Apr 2024 11:31:14 +0200 Subject: [PATCH 1/5] Update logs with more relevant info for debugging purposes --- app/alias_utils.py | 25 +++++++++++++------------ app/dashboard/views/index.py | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/alias_utils.py b/app/alias_utils.py index b02cb1fc7..def8c4d22 100644 --- a/app/alias_utils.py +++ b/app/alias_utils.py @@ -308,28 +308,29 @@ def delete_alias(alias: Alias, user: User): Delete an alias and add it to either global or domain trash Should be used instead of Alias.delete, DomainDeletedAlias.create, DeletedAlias.create """ - # save deleted alias to either global or domain trash + LOG.i(f"User {user} has deleted alias {alias}") + # save deleted alias to either global or domain tra if alias.custom_domain_id: if not DomainDeletedAlias.get_by( email=alias.email, domain_id=alias.custom_domain_id ): - LOG.d("add %s to domain %s trash", alias, alias.custom_domain_id) - Session.add( - DomainDeletedAlias( - user_id=user.id, - email=alias.email, - domain_id=alias.custom_domain_id, - ) + domain_deleted_alias = DomainDeletedAlias( + user_id=user.id, + email=alias.email, + domain_id=alias.custom_domain_id, ) + Session.add(domain_deleted_alias) Session.commit() - + LOG.i( + f"Moving {alias} to domain {alias.custom_domain_id} trash {domain_deleted_alias}" + ) else: if not DeletedAlias.get_by(email=alias.email): - LOG.d("add %s to global trash", alias) - Session.add(DeletedAlias(email=alias.email)) + deleted_alias = DeletedAlias(email=alias.email) + Session.add() Session.commit() + LOG.i(f"Moving {alias} to global trash {deleted_alias}") - LOG.i("delete alias %s", alias) Alias.filter(Alias.id == alias.id).delete() Session.commit() diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index 8422b06dc..cadcaeea2 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -141,7 +141,7 @@ def index(): ) if request.form.get("form-name") == "delete-alias": - LOG.d("delete alias %s", alias) + LOG.i(f"User {current_user} requested deletion of alias {alias}") email = alias.email alias_utils.delete_alias(alias, current_user) flash(f"Alias {email} has been deleted", "success") From 5c4bf40bad0a8a438fb4a7e1d7011322a741f1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Mon, 8 Apr 2024 12:45:48 +0200 Subject: [PATCH 2/5] Improved logs for alias creation rate-limit --- app/rate_limiter.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/rate_limiter.py b/app/rate_limiter.py index 40b076d52..39c441e06 100644 --- a/app/rate_limiter.py +++ b/app/rate_limiter.py @@ -30,7 +30,9 @@ def check_bucket_limit( try: value = lock_redis.incr(bucket_lock_name, bucket_seconds) if value > max_hits: - LOG.i(f"Rate limit hit for {bucket_lock_name} -> {value}/{max_hits}") + LOG.i( + f"Rate limit hit for {lock_name} (bucket it {bucket_id} -> {value}/{max_hits}" + ) newrelic.agent.record_custom_event( "BucketRateLimit", {"lock_name": lock_name, "bucket_seconds": bucket_seconds}, From b8f1fc5ae18059b3d498a78ee00e2deb076255b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Mon, 8 Apr 2024 12:46:12 +0200 Subject: [PATCH 3/5] Reduce sudo time to 120 secs --- app/dashboard/views/enter_sudo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/dashboard/views/enter_sudo.py b/app/dashboard/views/enter_sudo.py index 3910873e3..8f6b80ab4 100644 --- a/app/dashboard/views/enter_sudo.py +++ b/app/dashboard/views/enter_sudo.py @@ -14,7 +14,7 @@ from app.proton.utils import get_proton_partner from app.utils import sanitize_next_url -_SUDO_GAP = 900 +_SUDO_GAP = 120 class LoginForm(FlaskForm): From ec0a25bdbd17962d3be982874776fb0590ee311d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Mon, 8 Apr 2024 12:52:43 +0200 Subject: [PATCH 4/5] log fixes --- app/rate_limiter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/rate_limiter.py b/app/rate_limiter.py index 39c441e06..a1dcfbb88 100644 --- a/app/rate_limiter.py +++ b/app/rate_limiter.py @@ -31,7 +31,7 @@ def check_bucket_limit( value = lock_redis.incr(bucket_lock_name, bucket_seconds) if value > max_hits: LOG.i( - f"Rate limit hit for {lock_name} (bucket it {bucket_id} -> {value}/{max_hits}" + f"Rate limit hit for {lock_name} (bucket id {bucket_id}) -> {value}/{max_hits}" ) newrelic.agent.record_custom_event( "BucketRateLimit", From 8dd6b60dbd0c3638e2fa7da8558f060827f30c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Mon, 8 Apr 2024 12:59:07 +0200 Subject: [PATCH 5/5] Fix missing object to add to the session --- app/alias_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/alias_utils.py b/app/alias_utils.py index def8c4d22..40cc607ca 100644 --- a/app/alias_utils.py +++ b/app/alias_utils.py @@ -327,7 +327,7 @@ def delete_alias(alias: Alias, user: User): else: if not DeletedAlias.get_by(email=alias.email): deleted_alias = DeletedAlias(email=alias.email) - Session.add() + Session.add(deleted_alias) Session.commit() LOG.i(f"Moving {alias} to global trash {deleted_alias}")