stonefishspine with an points out the soldiers’ oath is to the Constitution…

In fact, within the framework of the Constitution, we govern ourselves, and our citizen soldiers vow to support the Constitution even before they agree to follow the orders of the President or their officers. This hierarchy is important because, if officers or presidents prove to be domestic enemies of the Constitution, soldiers are no longer obligated to serve them. They are, rather, sworn to defend the Constitution against them.

(Highly recommended read)