Immigration and Customs Enforcement had been auditing the companies' hiring records for the past four months as part of an anti-terrorism crackdown targeting areas such as military bases and airports.
Golden State was among more than 250 naval station contractors under investigation.
"Obviously the base is a critical infrastructure. There are nuclear ships out there," said Michael Unzueta, acting special agent in charge of investigations for U.S. Immigration and Customs Enforcement in San Diego. "It's a vulnerability and we want to know if people on the base are who they say they are."
Nearly all of those detained were from Mexico. Four of the 27 had criminal records and were legal residents. They now stand to lose their status. Some were longtime company employees, Golden State officials said.
Gary Hansen, a vice president for Golden State, said employees were issued paychecks and paid taxes and were given pre-employment physicals and health insurance.
"They presented to us what appeared to be legal documentation to work in the United States," Hansen said. "It's a shame."
ICE officials said the company cooperated with the investigation and provided employees' addresses. Golden State will not face either civil or criminal penalties.
Lilia Velasquez, a San Diego immigration attorney said it is common for companies to avoid penalties for hiring illegal immigrants.
"There is no requirement that they check with the immigration service to determine the authenticity, or with the Social Security Administration to verify whether it is a bona fide number," Velasquez said.
The Department of Homeland Security runs a program that allows companies to verify documents, but only 120 businesses in San Diego use it, the Union-Tribune reported.
Wayne Cornelius, director of the Center for Comparative Immigration Studies at the University of California, San Diego, called the focus on the immigrants rather than employers "terribly hypocritical." He said it will not help improve security, as employers have no incentive to avoid hiring more undocumented workers in the future.
ICE has detained 156 people in San Diego since last October as part of Operation Safe Cities, a post Sept. 11 initiative geared toward protecting sensitive businesses from security breaches