The government in its background investigations of employees can ask about their drug treatment, medical conditions or other personal information, the Supreme Court ruled on Wednesday in a case that pitted privacy rights against national security concerns.

The high court unanimously upheld the National Aeronautics and Space Administration's background checks of scientists in California and ruled the questions do not violate the employees' constitutional privacy rights.

The Obama administration had defended the routine background security investigations and described them as standard for millions of federal employees since 1953 and for contractors since 2005.

It said that NASA facilities have sensitive information, that the questions can be justified partly on national security grounds and that adequate privacy safeguards existed to prevent any improper disclosures.

The ruling was a defeat for 28 scientists, engineers and other employees who challenged the in-depth background checks required at the Jet Propulsion Laboratory in California as needlessly intrusive.

The longtime contract employees, who had been classified as low risk, refused to submit to the checks for information on medical treatment or counseling for drug use or any other adverse information, including private sexual matters.

Government background checks typically include inquiries to an employee's neighbors and friends in seeking personal information, such as emotional and financial stability.

The laboratory, owned by the space agency and operated by the California Institute of Technology, is known for developing satellites, rockets, spacecraft and telescopes.

NASA in 2007 required that every employee undergo the background investigation as a condition to being allowed access to the facilities. Employees who do not agree to the checks could lose their jobs.

The justices overturned a U.S. appeals court ruling that had blocked NASA from conducting the background checks.