Log relevant request info.

This commit is contained in:
Philippe Pittoli 2024-12-13 13:39:16 +01:00
parent df2b3f7638
commit d325b43c04
19 changed files with 161 additions and 8 deletions

View File

@ -7,6 +7,10 @@ class IPC::JSON
def handle(service : AuthD::Service, fd : Int32) def handle(service : AuthD::Service, fd : Int32)
raise "unimplemented" raise "unimplemented"
end end
def to_s(io : IO)
io << self.class.name.sub /[^:]+::[^:]+::/, ""
end
end end
module AuthD module AuthD

View File

@ -9,6 +9,11 @@ class AuthD::Request
def initialize(@login, @password, @admin, @email, @profile) def initialize(@login, @password, @admin, @email, @profile)
end end
def to_s(io : IO)
super io
io << " (login: #{@login}, email: #{@email})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil? return Response::ErrorMustBeAuthenticated.new if logged_user.nil?
@ -56,6 +61,11 @@ class AuthD::Request
def initialize(@login, @password, @email, @profile = nil) def initialize(@login, @password, @email, @profile = nil)
end end
def to_s(io : IO)
super io
io << " (login: #{@login}, email: #{email})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
# Check if there already is a registered user. # Check if there already is a registered user.
if authd.users.to_a.size > 0 if authd.users.to_a.size > 0
@ -90,6 +100,11 @@ class AuthD::Request
def initialize(@token) def initialize(@token)
end end
def to_s(io : IO)
super io
io << " (token size: #{@token.size})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil? return Response::ErrorMustBeAuthenticated.new if logged_user.nil?

View File

@ -6,6 +6,11 @@ class AuthD::Request
def initialize(@user = nil) def initialize(@user = nil)
end end
def to_s(io : IO)
super io
io << " (user: #{@user})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil? return Response::ErrorMustBeAuthenticated.new if logged_user.nil?

View File

@ -22,6 +22,11 @@ class AuthD::Request
def initialize(@login, @password) def initialize(@login, @password)
end end
def to_s(io : IO)
super io
io << " (login: #{@login})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
begin begin
user = authd.users_per_login.get @login user = authd.users_per_login.get @login

View File

@ -10,6 +10,11 @@ class AuthD::Request
def initialize(@login, @password_hash_brkn, @admin = false, @email = nil, @profile = nil) def initialize(@login, @password_hash_brkn, @admin = false, @email = nil, @profile = nil)
end end
def to_s(io : IO)
super io
io << " (login: #{@login}, admin: #{@admin})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil? return Response::ErrorMustBeAuthenticated.new if logged_user.nil?

View File

@ -8,6 +8,11 @@ class AuthD::Request
def initialize(@user, @admin, @password, @email) def initialize(@user, @admin, @password, @email)
end end
def to_s(io : IO)
super io
io << " (user: #{@user}, admin: #{@admin})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil? return Response::ErrorMustBeAuthenticated.new if logged_user.nil?

View File

@ -6,6 +6,11 @@ class AuthD::Request
def initialize(@login = nil, @email = nil) def initialize(@login = nil, @email = nil)
end end
def to_s(io : IO)
super io
io << " (login: #{@login})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
if @login.nil? && @email.nil? if @login.nil? && @email.nil?
return Response::ErrorUserNotFound.new return Response::ErrorUserNotFound.new
@ -54,6 +59,11 @@ class AuthD::Request
def initialize(@user, @password_renew_key, @new_password) def initialize(@user, @password_renew_key, @new_password)
end end
def to_s(io : IO)
super io
io << " (user: #{@user}, password_renew_key: #{@password_renew_key})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
user = authd.user? @user user = authd.user? @user
# This is a way for an attacker to know what are the valid logins. # This is a way for an attacker to know what are the valid logins.

View File

@ -7,6 +7,11 @@ class AuthD::Request
def initialize(@user, @service, @resource) def initialize(@user, @service, @resource)
end end
def to_s(io : IO)
super io
io << " (user: #{@user}, service: #{@service}, resource: #{@resource})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil? return Response::ErrorMustBeAuthenticated.new if logged_user.nil?
@ -42,6 +47,11 @@ class AuthD::Request
def initialize(@user, @service, @resource, @permission) def initialize(@user, @service, @resource, @permission)
end end
def to_s(io : IO)
super io
io << " (user: #{@user}, service: #{@service}, resource: #{@resource}, permission: #{@permission})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil? return Response::ErrorMustBeAuthenticated.new if logged_user.nil?

View File

@ -8,6 +8,11 @@ class AuthD::Request
def initialize(@new_profile_entries, @user = nil) def initialize(@new_profile_entries, @user = nil)
end end
def to_s(io : IO)
super io
io << " (user: #{@user})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil? return Response::ErrorMustBeAuthenticated.new if logged_user.nil?

View File

@ -8,6 +8,11 @@ class AuthD::Request
def initialize(@login, @password, @email, @profile) def initialize(@login, @password, @email, @profile)
end end
def to_s(io : IO)
super io
io << " (login: #{@login})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
unless authd.configuration.registrations unless authd.configuration.registrations
return Response::ErrorRegistrationsClosed.new return Response::ErrorRegistrationsClosed.new

View File

@ -9,6 +9,11 @@ class AuthD::Request
def initialize(@regex = nil, @offset = 0) def initialize(@regex = nil, @offset = 0)
end end
def to_s(io : IO)
super io
io << " (regex: #{@regex}, offset: #{@offset})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil? return Response::ErrorMustBeAuthenticated.new if logged_user.nil?

View File

@ -6,6 +6,11 @@ class AuthD::Request
def initialize(@user, @activation_key) def initialize(@user, @activation_key)
end end
def to_s(io : IO)
super io
io << " (user: #{@user}, activation_key: #{@activation_key})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
user = authd.user? @user user = authd.user? @user
# This is a way for an attacker to know what are the valid logins. # This is a way for an attacker to know what are the valid logins.
@ -40,6 +45,11 @@ class AuthD::Request
def initialize(@user) def initialize(@user)
end end
def to_s(io : IO)
super io
io << " (user: #{@user})"
end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user? fd logged_user = authd.get_logged_user? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil? return Response::ErrorMustBeAuthenticated.new if logged_user.nil?

View File

@ -4,6 +4,12 @@ class AuthD::Response
property email : String? = nil property email : String? = nil
def initialize(@user, @email) def initialize(@user, @email)
end end
def to_s(io : IO)
super io
io << " (user: #{@user}, email: #{@email})"
end
end end
AuthD.responses << Contacts AuthD.responses << Contacts
end end

View File

@ -9,6 +9,11 @@ class AuthD::Response
property email : String property email : String
def initialize(@email) def initialize(@email)
end end
def to_s(io : IO)
super io
io << " (email: #{@email})"
end
end end
AuthD.responses << NewEmailAddressValidated AuthD.responses << NewEmailAddressValidated
end end

View File

@ -3,6 +3,11 @@ class AuthD::Response
property reason : String? = nil property reason : String? = nil
def initialize(@reason) def initialize(@reason)
end end
def to_s(io : IO)
super io
io << " (reason: #{@reason})"
end
end end
AuthD.responses << Error AuthD.responses << Error
@ -70,6 +75,11 @@ class AuthD::Response
property read_only_keys : Array(String) property read_only_keys : Array(String)
def initialize(@read_only_keys) def initialize(@read_only_keys)
end end
def to_s(io : IO)
super io
io << " (read_only_keys: #{@read_only_keys.join(",")})"
end
end end
AuthD.responses << ErrorReadOnlyProfileKeys AuthD.responses << ErrorReadOnlyProfileKeys

View File

@ -6,6 +6,11 @@ class AuthD::Response
property pending_email : String? = nil property pending_email : String? = nil
def initialize(@token, @uid, @current_email, @pending_email) def initialize(@token, @uid, @current_email, @pending_email)
end end
def to_s(io : IO)
super io
io << " (uid: #{@uid})"
end
end end
AuthD.responses << Login AuthD.responses << Login
end end

View File

@ -6,6 +6,11 @@ class AuthD::Response
property permission : ::AuthD::User::PermissionLevel property permission : ::AuthD::User::PermissionLevel
def initialize(@service, @resource, @user, @permission) def initialize(@service, @resource, @user, @permission)
end end
def to_s(io : IO)
super io
io << " (user: #{@user}, service: #{@service}, resource: #{@resource}, permission: #{@permission})"
end
end end
AuthD.responses << PermissionCheck AuthD.responses << PermissionCheck
@ -16,6 +21,11 @@ class AuthD::Response
property permission : ::AuthD::User::PermissionLevel property permission : ::AuthD::User::PermissionLevel
def initialize(@user, @service, @resource, @permission) def initialize(@user, @service, @resource, @permission)
end end
def to_s(io : IO)
super io
io << " (user: #{@user}, service: #{@service}, resource: #{@resource}, permission: #{@permission})"
end
end end
AuthD.responses << PermissionSet AuthD.responses << PermissionSet
end end

View File

@ -3,6 +3,11 @@ class AuthD::Response
property user : ::AuthD::User::Public property user : ::AuthD::User::Public
def initialize(@user) def initialize(@user)
end end
def to_s(io : IO)
super io
io << " (user public data: #{@user})"
end
end end
AuthD.responses << User AuthD.responses << User
@ -10,6 +15,11 @@ class AuthD::Response
property user : ::AuthD::User::Public property user : ::AuthD::User::Public
def initialize(@user) def initialize(@user)
end end
def to_s(io : IO)
super io
io << " (user public data: #{@user})"
end
end end
AuthD.responses << UserAdded AuthD.responses << UserAdded
@ -17,6 +27,11 @@ class AuthD::Response
property uid : UInt32 property uid : UInt32
def initialize(@uid) def initialize(@uid)
end end
def to_s(io : IO)
super io
io << " (uid: #{@uid})"
end
end end
AuthD.responses << UserEdited AuthD.responses << UserEdited
@ -24,6 +39,11 @@ class AuthD::Response
property user : ::AuthD::User::Public property user : ::AuthD::User::Public
def initialize(@user) def initialize(@user)
end end
def to_s(io : IO)
super io
io << " (user public data: #{@user})"
end
end end
AuthD.responses << UserValidated AuthD.responses << UserValidated
@ -31,6 +51,11 @@ class AuthD::Response
property users : Array(::AuthD::User::Public) property users : Array(::AuthD::User::Public)
def initialize(@users) def initialize(@users)
end end
def to_s(io : IO)
super io
io << " (users public data: #{(@users.map &.uid).join ","})"
end
end end
AuthD.responses << UsersList AuthD.responses << UsersList
@ -38,6 +63,11 @@ class AuthD::Response
property users : Array(::AuthD::User::Public) property users : Array(::AuthD::User::Public)
def initialize(@users) def initialize(@users)
end end
def to_s(io : IO)
super io
io << " (users public data: #{(@users.map &.uid).join ","})"
end
end end
AuthD.responses << MatchingUsers AuthD.responses << MatchingUsers
@ -45,6 +75,11 @@ class AuthD::Response
property uid : UInt32 property uid : UInt32
def initialize(@uid) def initialize(@uid)
end end
def to_s(io : IO)
super io
io << " (uid: #{@uid})"
end
end end
AuthD.responses << UserDeleted AuthD.responses << UserDeleted
end end

View File

@ -148,16 +148,16 @@ class AuthD::Service < IPC
response = begin response = begin
request.handle self, event.fd request.handle self, event.fd
rescue e : UserNotFound rescue e : UserNotFound
Baguette::Log.error "(fd #{ "%4d" % event.fd}) #{request_name} user not found" Baguette::Log.error "(fd #{ "%4d" % event.fd}) #{request} user not found"
AuthD::Response::Error.new "authorization error" AuthD::Response::Error.new "authorization error"
rescue e : AuthenticationInfoLacking rescue e : AuthenticationInfoLacking
Baguette::Log.error "(fd #{ "%4d" % event.fd}) #{request_name} lacking authentication info" Baguette::Log.error "(fd #{ "%4d" % event.fd}) #{request} lacking authentication info"
AuthD::Response::Error.new "authorization error" AuthD::Response::Error.new "authorization error"
rescue e : AdminAuthorizationException rescue e : AdminAuthorizationException
Baguette::Log.error "(fd #{ "%4d" % event.fd}) #{request_name} admin authentication failed" Baguette::Log.error "(fd #{ "%4d" % event.fd}) #{request} admin authentication failed"
AuthD::Response::Error.new "authorization error" AuthD::Response::Error.new "authorization error"
rescue e rescue e
Baguette::Log.error "(fd #{ "%4d" % event.fd}) #{request_name} generic error #{e}" Baguette::Log.error "(fd #{ "%4d" % event.fd}) #{request} generic error #{e}"
AuthD::Response::Error.new "unknown error" AuthD::Response::Error.new "unknown error"
end end
@ -169,13 +169,11 @@ class AuthD::Service < IPC
duration = Time.utc - request_start duration = Time.utc - request_start
response_name = response.class.name.sub /^AuthD::Response::/, ""
if response.is_a? AuthD::Response::Error if response.is_a? AuthD::Response::Error
Baguette::Log.warning "fd #{ "%4d" % event.fd} (#{duration}) #{request_name} >> #{response_name} (#{response.reason})" Baguette::Log.warning "fd #{ "%4d" % event.fd} (#{duration}) #{request} >> #{response}"
else else
if request_name != "KeepAlive" || should_display? AUTHMESSAGE::KEEPALIVE if request_name != "KeepAlive" || should_display? AUTHMESSAGE::KEEPALIVE
Baguette::Log.debug "fd #{ "%4d" % event.fd} (#{duration}) #{request_name} >> #{response_name}" Baguette::Log.debug "fd #{ "%4d" % event.fd} (#{duration}) #{request} >> #{response}"
end end
end end
end end