The ability of a government to meet the needs of its citizens is a direct function of its ability to provide security. If a government does not have the means to defend itself and its interests, then not only will it be impossible for the government to foster any other necessity, but it will cease to exist. No government can sustain itself without the capacity to resist assault.
To begin, war (in the present context) is the attempt of nations to physically coerce one another to accept their will after all diplomatic means have been exhausted. This does not propose that the victor of war is wrong since he "coercively" won. Simply because one uses force to obtain a desired end-state does not necessarily imply that either the force or the end-state are unjustifiable. The goal of one's war can be the theft of land just as easily as it can be peace and the tactics of war can be barbaric or lawful.
So, when is it permissible for nations to wage war? Generally speaking, nations may engage in conflict when they are repelling the initiation of physical force. It is admissible for nations to employ self-defenses to safeguard themselves and their interests, but they may not begin attacks (a notable exception is pre-emptive war, but that may be used to defend against impending attack since it is still a form of self-defense).
Saint Thomas Aquinas proffered three guidelines for nations to adopt to satisfy the conditions of a "just war." First, the war must be started and controlled by the sovereign state authority. Ordinary civilians may not start a war and the legitimate authority in power must be responsible for beginning, maintaining and ending the battle. The government's purview of war is therefore monopolistic. Second, the cause of the war must be just. "Just" means that those being fought against must deserve the harm. Additionally, just requires that the war not be fought for purposes of revenge or greed, but for protection or the defeat of evil. Third, the war must be for good or against evil and that law and order should be restored following the end of struggle. During the clash, a nation must always be on the side of good and when the discord is over, all laws must be obeyed and life should resume its pre-war harmony.
Given the evolution of combat and war, rules governing just wars have been augmented to accommodate modern considerations. For example, a just war should only be fought if and only if there is a reasonable chance of success. To dive into war when one is destined to suffer defeat is senseless and a detriment to humanity. Second, the degree of violence used in war must be tantamount to the injury suffered. Nations should be prohibited from using excessive force when redressing grievances since that is a direct transition from self-defense to attack. Third, there must be discrimination between combatants and non-combatants. Blind attack on any member of a nation is not war, but savagery. Since there are specifications dictating the behavior of and in war, mindless brutality on innocent citizens cannot be properly classified as "war." Lastly, the chief goal of war is to re-establish peace. This is not a reinstatement of the pre-war status quo, but a reinstatement of the peaceful conditions of the pre-war status quo.
Intuitively, one might question whether civil wars are ever justified since they do not satisfy the first condition of just war, i.e. that legitimate government authority and not citizens wage war. However, a crucial limitation of government is authorities must act in accordance with the rights of its citizens. Even if the government authority is legitimately placed in power, the citizens are permitted to resist the government's efforts if they violate their rights. Citizens can be permitted (as a last resort) to defend themselves against a tyrannical government (likewise, governments are justified in defeating violent upheaval if they have maintained citizens' rights and have not committed any crimes in office). Therefore, "sovereign" in the first condition of just war means legitimately elected authority that adheres to the proper internal restrictions on government.
The underlying premise of "just war" rules (and all rules governing conflict) is that the only justifiable use of force is self-defense (in the interest of people and other investments). No nation can be lawfully permitted to bring harm to another for any reason other than maintaining existence in the repulsion of threats.
Unfortunately, the preservation of freedom and the safeguarding of values often necessitate the use of force. Nations that promote freedom and democratic values have been the targets of those nations who rule by force over their own citizens and therefore naturally strive to use force as their only means of interstate diplomacy.
In the modern world, technology has enabled both violent nations to further their plans of coercive rule and helped peaceful nations develop means to stymie violent attacks. Due to the immense harm that can be inlicted by modern weapons, peaceful nations are fully justified in maintaining militaries that are able to combat such threats. There is the appearance of incongruity when a peaceful nation of freedom is buttressed by an extraordinarily powerful military. However, the military may be infinitely powerful as long as external threats merit strong armament and it acts for purposes of self-defense.