Ukraine may become a member of NATO after the war ends. NATO membership will serve as a security guarantee for Ukraine. Note that Russia invaded, attacked or has substantial troops present only in countries that are not NATO members (e.g., Moldova, Georgia, Syria, Ukraine). Russia has not invaded any of the NATO countries, despite consistent statements on Russian state-controlled TV threatening attacks on the NATO countries.
The fact that Russia is currently opposing Ukraine joining NATO is largely irrelevant, just as Russian opposition was irrelevant when other Eastern European countries joined NATO. NATO has consistently expanded from 1990s to the present in response to the constant threat of Russian aggression.
REFERENCES:
At the June 2021 Brussels summit, NATO leaders reiterated the decision
taken at the 2008 Bucharest Summit that Ukraine would become a member
of the Alliance with the NATO MAP as an integral part of the process
and Ukraine's right to determine its own future and foreign policy
course without outside interference. Secretary-General Stoltenberg
also stressed that Russia will not be able to veto Ukraine's accession
to NATO, as we will not return to the era of spheres of interest, when
large countries decide what smaller ones should do:
Each country chooses its own path, and this also applies to joining
NATO. It is up to Ukraine and the 30 NATO members to decide whether it
aspires to be a member of the Alliance. Russia has no say in whether
Ukraine should be a member of the Alliance. They cannot veto the
decisions of their neighbors. We will not return to the era of spheres
of interest, when large countries decide what to do with smaller ones.
Ukraine–NATO relations - Wikipedia: https://en.wikipedia.org/wiki/Ukraine%E2%80%93NATO_relations
NATO returns on Tuesday to the scene of one of its most controversial
decisions, intent on repeating its vow that Ukraine — now suffering
through the 10th month of a war against Russia — will join the world’s
biggest military alliance one day.
NATO foreign ministers will gather for two days at the Palace of the
Parliament in the Romanian capital Bucharest. It was there in April
2008 that U.S. President George W. Bush persuaded his allies to open
NATO’s door to Ukraine and Georgia, over vehement Russian objections.
“NATO welcomes Ukraine’s and Georgia’s Euro-Atlantic aspirations for
membership in NATO. We agreed today that these countries will become
members of NATO,” the leaders said in a statement. Russian President
Vladimir Putin, who was at the summit, described this as “a direct
threat” to Russia’s security.
Lorne Cook and Stephen McGrath, "14 years later, NATO is set to renew its vow to Ukraine", AP, November 28, 2022: https://apnews.com/article/russia-ukraine-putin-nato-europe-bucharest-1b3564af002c8e879c304a6a85bf1f97
By August 1993, Polish President Lech Wałęsa was actively campaigning
for his country to join NATO, at which time Yeltsin reportedly told
him that Russia did not perceive its membership in NATO as a threat to
his country. Yeltsin however retracted this informal declaration the
following month,[27] writing that expansion "would violate the spirit
of the treaty on the final settlement" which "precludes the option of
expanding the NATO zone into the East."[28][29] [...]
In February 1991, Poland, Hungary, and Czechoslovakia formed the
Visegrád Group to push for European integration under the European
Union and NATO, as well as to conduct military reforms in line with
NATO standards. [...] That year, Russian leaders like Foreign Minister
Andrei Kozyrev indicated their country's opposition to NATO
enlargement.[40] While Russian President Boris Yeltsin did sign an
agreement with NATO in May 1997 that included text referring to new
membership, he clearly described NATO expansion as "unacceptable" and
a threat to Russian security in his December 1997 National Security
Blueprint.[41] [...]
At the 1999 Washington summit NATO issued new guidelines for
membership with individualized "Membership Action Plans" for Albania,
Bulgaria, Estonia, Latvia, Lithuania, North Macedonia, Romania,
Slovakia, and Slovenia in order to standardize the process for new
members.[51] [...] Russia was particularly upset with the addition of
the three Baltic states, the first countries that were part of the
Soviet Union to join NATO.[54][52] Russian troops had been stationed
in Baltic states as late as 1995,[55] but the goals of European
integration and NATO membership were very attractive for the Baltic
states.[56] [...]
On 25 February [2022], a Russian Foreign Ministry spokesperson
threatened Finland and Sweden with "military and political
consequences" if they attempted to join NATO.
Enlargement of NATO - Wikipedia: https://en.wikipedia.org/wiki/Enlargement_of_NATO
Examples of statements on Russian state-controlled TV threatening attacks on the NATO countries:
Julia Davis, Russian Media Monitor: