When a federal government position requires a security clearance, before you can take the position you agree to have an examination by federal officers, including the FBI, or your private life. In truth, the security exam is not significantly different from that done by a variety of private sources when you apply for medical or health insurance, a mortgage, bank loan, or even job applications.
The exam is done after consent, but the conditions remain in effect during the time you hold that position. There are safeguards and seccurity precautions about the information collected, and serious restrictions and limitations on access to any of it.
Keep in mind, too, some of the outrageous security breaches by senior officials like the CIA's Ames, or the FBI's Hansen that were ignored for years despite obvious signs of something wrong, life showing up at work with a new Jaguar, regular fancy foreign trips, etc.