server: use context.principal only when it is defined

In server-like context we use LDAPI connection with auto-binding to LDAP
object based on the UID of the process connecting to LDAPI UNIX domain
socket. This means context.principal is not set and we cannot use it.

Make sure to reject requests unless we are operating as a Directory
Manager in such cases.

Fixes: https://pagure.io/freeipa/issue/9583

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-By: Thomas Woerner <twoerner@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
Reviewed-By: Rafael Guterres Jeffman <rjeffman@redhat.com>
This commit is contained in:
Alexander Bokovoy 2024-04-26 19:52:32 +03:00 committed by Antonio Torres
parent 71d886f071
commit ab5465639d
No known key found for this signature in database
GPG Key ID: 359FAF777296F653

View File

@ -934,7 +934,8 @@ class server_conncheck(crud.PKQuery):
# the user must have the Replication Administrators privilege
privilege = u'Replication Administrators'
if not principal_has_privilege(self.api, context.principal, privilege):
op_account = getattr(context, 'principal', None)
if not principal_has_privilege(self.api, op_account, privilege):
raise errors.ACIError(
info=_("not allowed to perform server connection check"))