Another hypothetical alternative which wouldn't violate EU law (not that they have any reason of using it) would be to make the ticket only valid to people who legally reside in Germany, regardless of their nationality.
Correct, that wouldn't violate it. For German citizens only would.