My understanding is that soldiers at present not only have such a right, they have an obligation to do so.
Which doesn't mean superiors will later agree a particular order was illegal.
I wonder if a unionized soldier would obey an illegal order to fire on anti union citizens?