There is a fine line that military officers cannot cross. Article 88 of the UCMJ provides:
“Any commissioned officer who uses contemptuous words against the President, the Vice President, Congress, the Secretary of Defense, the Secretary of a military department, the Secretary of Transportation,
or the Governor or legislature of any State, Territory, Commonwealth, or possession in which he is on duty or present shall be punished as a court-martial may direct.”
You can do less than use contemptuous words and be charged with a variety of other UCMJ charges since the military has a number of regulations on protesting and, in general, going against the grain. For instance, I cannot don on my service dress and protest in front of the white house, lest I risk punishment under the UCMJ.
My point here is that often the option is to shut up and color, notwithstanding your own personal views of policy. Keep in mind, there is a limit, as Ollie North learned. Unlawful orders cannot be followed and military members are obligated to testify truthfully before congress if called.