the legal framework for war is quite clear. respecting and enforcing it is another matter. the mechanisms to get authorization are often subverted (which means those actions my be technically legal but still fraudulent) and even more often are ignored altogether.
the us war against iraq in 1991 had a mandate from the un security council, which is the sole international authority to authorize military action, thus was a legal action according international law. the us tried to reuse this same mandate to invade iraq in 2003 but the un explicitly ruled this illegal. the un charter was signed in 1945 and has authorized armed intervention in about 7 other instances (many on dubious grounds, but still legal) so except for those all other us wars from there on were straight out illegal according to international law.
according to us law, the constitution gives the sole authority to declare war to the us congress. the last time congress did this was in 1942 in ww2. in 2001 congress gave a statutory authorization of military action against any country which "planned, authorized, commited or aided" the 9/11 attacks. this authorization was used for aggression on several countries but all evidence of "planning, authorizing, committing or aiding" by any of them was fabricated and phony (if provided at all), so those wars weren't really covered by that statutory authorization. meaning (unless i'm missing something) all us wars since 1942 with the exception of iraq 1991 were also illegal under us law, except nobody ever bothered to figure that out.
some examples where both parties agreed itâ(TM)s legal and fair
both parties agreeing to anything has little bearing on legality. the un charter does ofc allow military action in self defense, but that's a gray area and there is rarely consent about who started hostilities. the right to preemptive strikes has been invoked quite often too but to my knowledge in no instance the legal requirements were actually met (not even remotely because they're very strict), as of today the un hasn't sanctioned a single instance of preemptive action in the world.
so it's basically a "might makes right" scenario with occasional nice words or lies thrown into it. as clausewitz put it, war is a continuation of politics by other means.