Were these pre existing borders of ethnic groups or states? Were they all drawn on the fly? If so by who?
The borders of the (to use a then-current term) "Newly Independent States" were themselves not very new in 1991.
If you look at a map of the USSR from 1974 showing its administrative divisions, you will see all 15 of the post-Soviet republics there as members of the Union, and with their post-1991 borders. Even the oblast (provincial) borders are mostly the same, although there are some exceptions - Russia and Kazakhstan merged a few of their late-Soviet oblasts into bigger oblasts.
So where did these borders come from? They are largely the result of Soviet national delimitation in the 1920s. The Russian Soviet Federative Socialist Republic, the Ukrainian Soviet Socialist Republic, the Belorussian Soviet Socialist Republic, and the Trancaucasian Socialist Federative Soviet Republic (which included Georgia, Armenia and Azerbaijan) were nominally independent but all controlled by the Bolshevik Party, and agreed to form a Union by treaty in 1922 (this incidentally was Lenin winning an argument over Stalin who wanted all these territories absorbed directly into Russia - Putin referenced this in his Feb. 21 speech that now feels like a million years ago).
Anyway, national delimitation continued after the formal commencement of the Union, with Belorussia and Ukraine gaining some territories on their border with the RSFSR to align better with ethnicity. A massive reorganization of Soviet Central Asia was undertaken, and former Russian Turkestan, Russian Steppe Governate, and the Emirates of Khiva and Bukhara (which had become People's Republics and were effectively Soviet satellite states) were all abolished, and reorganized in 1924 into a Turkmen Soviet Socialist Republic, Uzbek Soviet Socialist Republic, and an autonomous Tajik SSR in the Uzbek SSR, and autonomous Kazakh and Kirgiz SSRs in the RSFSR. The Tajik republic was elevated to full SSR status in 1929, and the Kazakh and Kirgiz ones in 1936. 1936 also saw the TSFSR dissolved and Armenia, Azerbaijan and Georgia elevated to full SSRs.
This is basically how the structure of the USSR remained, with the obvious changes on the western border after 1940/1945, when the Baltics and Moldavia became SSRs and Belorussia and Ukraine were expanded west. From 1940 to 1956 there was also a Karelian SSR, but this got dropped back to an autonomous republic in the RSFSR, and the Karelian Republic is a federal subject of Russia today.
Otherwise after World War II there were very little internal changes to borders, with the notable exception of Crimea being transferred from the RSFSR to the Ukrainian SSR in 1954. In theory all the SSRs were equal members of a union, and in the 1977 Soviet Constitution they even possessed a right to secession (which no one at the time seriously expected them to use). All of the republics had their own flag, constitution and legislature. Interestingly, all the republics bar one had their own republic-level communist party, academy of arts and sciences, republic-level KGB and (tiny) ministry of foreign affairs (the Ukrainian and Belorussian SSRs were even UN members), and that one exception was the RSFSR.
Part of what happened from 1989 to 1991 is that Gorbachev weakened the all-union Communist Party at the expense of the government institutions, hoping to concentrate power in the Union government for the purposes of reform, but inadvertently strengthening republican governments as well. The 1990 "War of Laws" led to a major constitutional crisis that Gorbachev hoped to resolve with a new Union Treaty - it was the formal signing of this new treaty on August 19, 1991 that the coup plotters tried to prevent. The coup failed and the republics promptly declared full independence if they had not already done so, and the Russian President Boris Yeltsin, following the coup conducted a "counter coup" whereby he banned the Communist Party, seized their assets, and effectively controlled the remaining Union government institutions with Gorbachev remaining titular head. The political wrangling between Yeltsin and Gorbachev carried on for months (while the economy effectively disintegrated), and when the Ukrainian SSR voted overwhelmingly for independence on December 1, 1991, Yeltsin negotiated with the heads of Ukraine and Belorussia the Belovezha Accords, that effectively dissolved the 1922 Union Treaty (the argument that Russia, Ukraine and Belarus were the remaining original signatories). The other SSRs didn't particularly care for being left out of this agreement, but further negotiations saw 8 more of the republics agree with the East Slavic 3 to formally dissolve the USSR in the Alma-Ata Protocol, signed on December 21. Gorbachev would resign and turn over all remaining Union institutions and assets to Yeltsin four days later.
Both the agreements of December 8 and December 21 included statements that signatories would accept each other's then territorial integrity and the inviolability of existing borders. This was already being somewhat violated on the ground by conflicts breaking out, notably between Armenia and Azerbaijan in Nagorno-Karabakh, in Chechnya (which declared independence from Russia) and in Abkhazia and South Ossetia, which wanted to separate from Georgia. In all of those cases, the territories in question were already-existing autonomous regions that wanted to switch which republic they were under - their borders had been drawn up decades earlier. But the agreements are a major reason why none of the states that have declared independence since 1991 in the former Soviet Union have gained almost any international recognition - there has been a commitment to recognize only the SSR level borders as of 1991 as the international frontiers.