I thought I'd chime in and point out that the police analogy is a little flawed if what you are looking for is education, versus detection. Granted my law enforcement experience is limited to an excessive love of Law & Order, but going with the cop show analogy - when police offers go under cover - it's generally the smart, experienced, stable guy who graduated with decent grades from the police academy. Not the summer intern. :)
Same thing for a penetration test (as John Hopkins describes) - companies are hired for pen tests based on corporate experience, the credentials of the individual engineers on the team, the professional reputation of everyone involved, and the cost and schedule proposed by the team. Just like you don't really want the crazy, unqualified cop to be the guy undercover, you don't hire a no-name, untrusted company to do your penetration testing.
The way to get to the point of being an individual on a pen test team?
It's the same almost any other career in engineering:
study the technology that allows and prevents security exploits - learn about as many areas of the security trade as you can - human factors, physical, network, software, operating systems, data protection, etc.
use academic institutions and professional certifications to establish credentials - some professional organizations also include a promise of ethics.
establish bonding as a way of providing additional reassurance of honesty - this is along the same lines of working as a lock smith.
work in the field in less high-risk jobs - security system development, system administration, IT security groups, risk management teams, etc.
do independent projects to get experience - like setting up a honey pot at home, or playing with security configurations on network gear.
get mentorship from someone more senior.
Just like undercover cops are a special group of police officers, who get special training, unique treatment and have particular credentials - penetration testers are a unique group of security professionals. The people I've met that do this type of work are often a similar personality type to the aggressive startup company programmer/architect/CTO type person - very smart, very driven, intensely focused on the state of the art, and quite intellectually aggressive. They generally come with very high level credentials and are very expensive.
I'm sure there are plenty of folks out there who are stupid and will try cracking into assets without corporate permission - but the folks I consider the real professionals in this area are too smart for that. They're aware of the laws in this domain, and they are too smart to jeopardize their careers by hacking on the side. A good pen tester knows that a portion of his high fee comes from the fact that the company is willing to trust him and if he does something on the side to break that trust, then he's out of a job and probably out of a career.