I don't know if they still do it, but when I was in you had to attend a class on exactly that subject. Your duty includes refusing to follow an illegal order. The class taught you how to do that in a lawful (UCMJ) manner.