His first master was simply experience
Batman's "training" is usually described to have involved a period of "reckless youth", where he wandered the world just getting into trouble. In the Nolan films, we see him stealing Wayne Enterprises property, and living as a vagabond in Asia. He seems to have taken a false name, although I don't recall if we ever learn it. But he talks about needing to steal to eat, so we know he's "roughing it". Various comic and cartoon stories have touched on this, but it's almost always there, and it's usually where he begins to pick up some skills in stealth, combat, and investigation. They're unrefined, but he has an aptitude even by this point.
For this period, he likely didn't make many close friends (he was an angry kid), and he probably used a fake name. If anyone did recognize his face later, it'd be one of those "wow that kid from ten years ago kind of looks like that celebrity" sort of things. Hardly a security risk.
His true "masters" often did know his identity
Bruce Wayne has had many masters and mentors in various stories, but the more they meant to him and the more important they are to his origin, the more likely they are to know his identity. Using the Nolan films as an example again, Ra's al Ghul did know his name, even before they started training together. I seem to recall an episode of the animated series where his old master dies or is in danger, and his identity is no secret there either. (I could be wrong about that, though.)
Generally, these figures are either so remote (e.g. a temple in Nowheresville, Nepal) that they aren't likely to ever spill the secret, or they are powerful and discreet enough (e.g. Ra's al Ghul and the League of Shadows) that they're keeping his secret, along with their own. Notably, this latter scenario has come back to haunt Bruce (for example in Batman Begins).
I can't recall him "training" or receiving any truly vital skills from anyone who was a security risk. His primary mentors seem to be either involved with him (like Alfred), aligned with him (like Ra's), or simply on the back-end of nowhere. They aren't strangers, who might "figure it out" and spill the beans. I've never seen any stories that had him learning to fight at the YMCA.