Commit 570c37e2 authored by Daniele Venzano's avatar Daniele Venzano

Better log messages for the Zoe API process

parent f15bd893
......@@ -41,14 +41,19 @@ class BaseAuthenticator:
return None
if user.auth_source == "textfile" and PlainTextAuthenticator(get_conf().auth_file).auth(username, password):
log.info('User {} authenticated via textfile'.format(user.username))
return user
elif user.auth_source == "ldap" and LDAPAuthenticator(get_conf(), sasl=False).auth(username, password):
log.info('User {} authenticated via ldap'.format(user.username))
return user
elif user.auth_source == "ldap+sasl" and LDAPAuthenticator(get_conf(), sasl=True).auth(username, password):
log.info('User {} authenticated via ldap+sasl'.format(user.username))
return user
elif user.auth_source == "internal" and user.check_password(password):
log.info('User {} authenticated via internal db'.format(user.username))
return user
elif user.auth_source == "pam" and pam_authenticate(username, password):
log.info('User {} authenticated via PAM'.format(user.username))
return user
else:
return None
......
......@@ -43,14 +43,11 @@ class ZoeRequestHandler(tornado.web.RequestHandler):
if self.get_secure_cookie('zoe'): # cookie auth
username = tornado.escape.xhtml_escape(self.get_secure_cookie('zoe'))
user = self.api_endpoint.user_by_name(username)
method = "cookie"
elif auth_header is not None and auth_header.startswith('Basic '): # basic auth
auth_decoded = base64.decodebytes(bytes(auth_header[6:], 'ascii')).decode('utf-8')
username, password = auth_decoded.split(':', 2)
user = BaseAuthenticator().full_auth(username, password)
method = "basic_auth"
else:
method = None
user = None
if user is None:
......@@ -58,9 +55,16 @@ class ZoeRequestHandler(tornado.web.RequestHandler):
if not user.enabled:
raise ZoeAuthException('User has been disabled by the administrator')
log.debug('Authentication done using {} (user {} from {} for {})'.format(method, user.username, self.request.remote_ip, self.request.path))
return user
def on_finish(self):
"""Log request."""
try:
user = ZoeRequestHandler.get_current_user(self)
except ZoeAuthException:
user = "not authenticated"
log.info("{} {} {} ({}, {}) {:.2f}ms".format(self.get_status(), self.request.method, self.request.path, self.request.remote_ip, user, self.request.request_time()))
def data_received(self, chunk):
"""Not implemented as we do not use stream uploads"""
pass
......
......@@ -51,6 +51,7 @@ def zoe_web_main(test_conf=None) -> int:
log_args['filename'] = args.log_file
logging.basicConfig(**log_args)
logging.getLogger("MARKDOWN").setLevel(logging.WARNING)
logging.getLogger("asyncio").setLevel(logging.INFO)
logging.getLogger("tornado").setLevel(logging.WARNING)
sql_manager = zoe_lib.state.SQLManager(zoe_lib.config.get_conf())
......
......@@ -191,4 +191,5 @@ class UserOAuthCallbackAPI(ZoeAPIRequestHandler):
if not self.get_secure_cookie('zoe'):
cookie_val = user.username
self.set_secure_cookie('zoe', cookie_val)
log.debug('User {} authenticated via gitlab (from {})'.format(user.username, self.request.remote_ip))
self.redirect(self.get_argument("next", self.reverse_url("home_user")))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment