Yes, that’s possible. Have a look here:
This was written to remove rooting with Apatch, but also applies if you’re on root with Magisk.