So funny, I've done it quite a bit. Russian, Turkish, Romanian, it's very much appreciated when I get it right and engage in a conversation about their mother country.
Of course, if you're a really good judge of character and able to make a brilliant on-the-spot judgement of the situation, depending upon the context, you can ask about (in a round-about way, giving the other person an "out" to save face, if necessary) the other person's genetic make-up without it appearing tactless / without stepping on anyone's toes. But most people lack those skills.
Likewise, a lot of people are so oblivious that they won't mind your asking.
Americans, for instance, are usually quite eager to share their ethnic roots with you.
But on the whole, I'd advise against doing so without a careful appraisal of the situation in advance - especially abroad, and especially with people belonging to an entirely different cultural and ethnic background.
It is very easy to give offense - though in many cases, the other party might not show that they are offended.
Regards,