1. The damage inflicted by the aggressor on the nation or community of nations must be lasting, grave, and certain.
2. All other means of putting an end to it must have been shown to be impractical or ineffective.
3. There must be serious prospects of success.
4. The use of arms must not produce evils and disorders graver than the evil to be eliminated.
The US gets tripped up on 4. a lot.
Clausewitz teaches that wars have a character all their own, unique to their time and circumstance, and that understanding the nature of the war you are engaged in is simultaneously vital and very, very difficult to do.
Defending themselves against foreign aggressors who have committed documented atrocities against their population, and who are on record as intending to commit genocide against them when they win, is immoral?