Your boss can legally yell at you or chew you out in front of other employees.
Legally the boss can yell at you for any reason they want too.
However if the boss is constantly yelling at you and you're doing your work like you're supposed to and it does not stop then the best thing to do is to wait it out and begin looking for another job.
Then when you find another job you can then quit that job and yell right back at them.
Although you need the job I would when possible get out of a job where a boss was always yelling at me and not treating me right.
Legally speaking though bosses, supervisors and managers are allowed to yell at employees.
However, when that yelling is about or against a protected class, the yelling may qualify as harassment.
This doesn't mean a boss, manager or supervisor is never allowed to get angry or frustrated, no one is perfect.