redhat-cop / group-sync-operator

Synchronizes groups from external providers into OpenShift
Apache License 2.0
111 stars 60 forks source link

Azure userattr nil fix #269

Closed lbac-redhat closed 1 year ago

lbac-redhat commented 1 year ago

Fixes #268

The logic that checks if a username is present in the group when a userNameAttribute is set does not guard against nil values, it only checks if the reflected method call would be valid. This results in calling .Interface() on a nil value which crashes the operator.

This PR fixes this issue by explicitly checking if the reflected value is nil before calling .Elem().Interface(). If it is nil, it simply returns false, as was the original logic.

This also adds some preliminary logging at least alerting users that they are hitting this issue,... unfortunately, in my tests, the user object retrieved from the Graph API had a UPN that was also nil, so the logging does not specify which user had the problem. This points to the fact that there may be a deeper underlying issue,... (or something I do not understand)

Nevertheless, this at least fixes the crash and alerts the user to an issue.