From 07c3b178c798cca4e20a09fb38974f1cc2dfc093 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Fri, 26 May 2023 01:48:38 +0530 Subject: [PATCH 1/2] adds ip to failed logs #12562 --- netbox/users/signals.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netbox/users/signals.py b/netbox/users/signals.py index 8915af1dcda..652753b254b 100644 --- a/netbox/users/signals.py +++ b/netbox/users/signals.py @@ -1,10 +1,11 @@ import logging from django.dispatch import receiver from django.contrib.auth.signals import user_login_failed +from utilities.request import get_client_ip @receiver(user_login_failed) def log_user_login_failed(sender, credentials, request, **kwargs): logger = logging.getLogger('netbox.auth.login') username = credentials.get("username") - logger.info(f"Failed login attempt for username: {username}") + logger.info(f"Failed login attempt for username: {username} from {get_client_ip(request)}") From 6f634c74eb1acc89a07f5753c039e73ac3ccf04d Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Fri, 26 May 2023 02:21:56 +0530 Subject: [PATCH 2/2] added additional logging when client ip cannot be determined --- netbox/users/signals.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/netbox/users/signals.py b/netbox/users/signals.py index 652753b254b..98036d5d10b 100644 --- a/netbox/users/signals.py +++ b/netbox/users/signals.py @@ -8,4 +8,11 @@ def log_user_login_failed(sender, credentials, request, **kwargs): logger = logging.getLogger('netbox.auth.login') username = credentials.get("username") - logger.info(f"Failed login attempt for username: {username} from {get_client_ip(request)}") + if client_ip := get_client_ip(request): + logger.info(f"Failed login attempt for username: {username} from {client_ip}") + else: + logger.warning( + "Client IP address could not be determined for validation. Check that the HTTP server is properly " + "configured to pass the required header(s)." + ) + logger.info(f"Failed login attempt for username: {username}")