I was told a soldier never salutes if their head is uncovered, but that doesn't seem to be the case with US servicemembers if films are to be believed. Soldiers in formation stand at attention if witnessing the flag being carried, hoisted or lowered. IIRC we never saluted the flag itself.

Civilians or soldiers out of uniform don't salute anything. The polite thing to do is to stand up and watch the proceedings when the flag is hoisted or taken down.