Not surprisingly, not everyone agrees that Israel has the right to attack Iran and dismantle its nuclear program. Even those with a background in international law are opposed to the attack.
Here's one such opinion on X from a professor of international law and security at the University of Copenhagen:

The argument is that Iran's nuclear threat is not imminent, and that changes Israel's attack from pre-emptive to preventive.
But Dershowitz offers a different response to the question of imminence: it doesn't matter. He quotes from a previous book of his, The Case Against the Iran Deal: How Can We Stop Iran Getting Nukes?
No democracy can afford to wait until such a threat against its civilian population is imminent. Both Israel and the United States should have the right under international law to protect their civilians and soldiers from a threatened nuclear holocaust, and that right must include--if that is the only realistic option--preemptive military action. [p. 83]
Tom Nichols, writing for The Atlantic, quotes John F. Kennedy to the same effect: a country cannot afford to wait until an attack is imminent. In 1962, during the Cuban Missile Crisis, Kennedy said:
We no longer live in a world where only the actual firing of weapons represents a sufficient challenge to a nation’s security to constitute maximum peril.
Not everyone will agree with that, and that leads to the question of whether Israel's attack was preemptive or preventive.
What difference does preventive vs preemptive make?
Tom Nichols writes that a preventive attack means the attacking country is "removing the source of a threat by surprise, on their own timetable and on terms they find favorable. They may be justified in doing so." On the other hand, preemptive attacks "are spoiling attacks, meant to thwart an imminent attack. In both tradition and law, this form of self-defense is perfectly defensible." The intended victim does not have to wait to be shot; he can fight back and kill his attacker first.
The key difference is that while preemptive attacks are accepted as legal,
Preventive attacks, however, have long been viewed in the international community as both illegal and immoral.
It may not be enough that Israel declares its attack to be preemptive.
Yet it seems more likely that Israel is speaking of its actions as pre-emptive for political purposes. Framing the attack in these terms allows Netanyahu to claim the right to “anticipatory self-defence”, minimising interference and condemnation from the perennially anti-Israel international law establishment.
All this talk about preemptive wars leads back to the fact that Israel wrote the book on preemption. Nichols writes:
The Israelis, ironically, are in the case books as the clearest example of a legitimate preemptive attack. In 1967, Israel got the jump on an Arab coalition that had been so obvious in its march to war that it was literally broadcasting its intention to destroy Israel while its troops massed for an offensive. Indeed, international-law experts have noted that the 1967 war is so clear that it is not much use as a precedent, because most enemies are not blockheaded enough to assemble an army and declare their intention to invade.
Ironically, not only does Israel provide the perfect example of a preemptive war, but it is too perfect.
But then, Nichols adds parenthetically:
(Of course, the Israelis could argue that they are already at war with Iran, a country that has launched many missiles at them and directed years of proxy attacks on their people and their military, which would be a far stronger case.)
Orton makes the same point with greater emphasis:
The clerical regime is publicly pledged to Israel’s destruction and has carried out numerous attacks in pursuit of this goal, including the 7 October massacre that started the current war in Gaza. This is a permanent threat Israel has every right to counter. It just means “preventive”, a more difficult legal-political category, is the more precise term for what is happening now.
Dershowitz goes further, arguing that the Six Day War still provides a solid justification for Israel's attacking Iran because it contains both aspects. He notes the argument that Egypt and Syria were bluffing and would not have attacked, removing the justification of Israel's preemptive attack. To this, he responds:
But Israel had a dual justification for its military action against Egypt, which had blocked the Strait of Tiran from Israeli shipping. That constituted a casus belli-an act of war-that justifies a reactive military response. [p. 84]
So too in regards to Iran, the nuclear threat is not the only justification for Israel's attack, because, similar to Egypt,
Iran has also engaged in acts that constitute a casus belli against Israel, both directly and indirectly, through its surrogates Hezbollah in Lebanon, Hamas in Gaza, and the Houthis in Yemen. Israel would be justified in reactively attacking Iran for these and other attacks, but its justification is enhanced by its legitimate need to prevent Iran from securing and deploying--as it promised (and also denied) it would do--a nuclear arsenal. [p. 85]
Some world leaders are already issuing the usual calls for Israel and Iran to dial down the violence, like parents telling their kids to stop fighting--not because they care who’s right, but because they’re trying to get some sleep.