Are there European laws that prohibit discriminating against people who live in Iran? Or that prohibit discriminating against companies who employ people who live in Iran? If not, the legal basis is that you can do anything you want unless it's prohibited by law, and the action in question isn't prohibited by law.
Yes, it actually is illegal to arbitrarily discriminate people based on their ethnicity, political views or nationality (unless there is a specific law that allows that for a particular nationality, e.g. in case of a legal embargo)