If you randomly assign students to teachers (which is already more or less the case) and each teacher has a large enough sample size of students (which is already more or less the case), aggregating the performance of all of a teacher's students will say more about the teacher than about these confounding variables, since all the other factors would be shared between all teachers at the school.
Of course there are other problems to be solved. But the fact that there are no effective controls whatsoever on teacher performance, and that teaching is not a highly selective profession, is still a problem.