Legality vs. illegality is determined by the specific jurisdiction. Almost every nation can legally declare war, except Japan due to Art 9 of the Japanese Constitution (there is a "work-around" which may or may not be legal, and only recently could defend itself). Thus the US can declare war under circumstances defined by certain aspects of US law, and engage in war-like activities under other legally-defined circumstances. Canada can as well, following Canadian law, similarly Norwegian law defines the ability of Norway to declare war. It is up to the individual nation to enforce such laws on themselves.
In principle, an agreement i.e. a treaty could exist between certain nations that they will not engage in mutual war, in which case it might be illegal for A to declare war against B. This can give rise to a legal dispute, to be resolved in some trans-national court. The Hague Convention of 1904 attempted in Art III to require a "reasoned declaration of war or of an ultimatum with conditional declaration of war", but that requirement is de facto dead. The UN Charter Art 2 can be interpreted as saying that members legally cannot engage in war, which is the main legal basis for saying that the war in question is illegal. This Congressional research document summarizes the present issue. Under the UN Charter, war is allowed in self defense, or to maintain or restore international peace and security. Availing itself of that exception, Russia has served the UN with a list of grievances to justify the invasion: a generalized threat from NATO relating to Ukraine; in collective self-defense of certain areas of Ukraine (Luhansk, Donetsk); finally, "genocide perpetrated by the Kiev regime" against ethnic Russians.
Apart from the legality or not of an attack on Ukraine, the conduct of the attack is also subject to legal scrutiny, for example limits on attacks against civilians, children, medical and religious personnel, aid workers.
Theoretically, the UN could sanction / take action against Russia, but any binding action can be vetoed by Russia (as a permanent member of the Security Council).