It is very easy.

As you drive through each border control, you will buy the insurance there, immediately. Just tell the guy at the border between Qatar and Saudi how many days your ENTIRE trip will last, and he will give you the insurance for those days... roughly 100QR for 14 days. Same happens in the area between Saudi and Dubai.
In Saudi there is just a small hut, but in Dubai you get a choice of 3 or 4 agents in small shops.
When you return to Saudi from Dubai, keep your paper from the original entry and they will stamp it again!