Security forces shot and killed the gunman, who was also an Afghan army officer.
"It is difficult to say at this time if he was an infiltrator or a real soldier," said Defense Ministry spokesman Gen. Mohammad Zahir Azimi. "Many soldiers and officers come to the ministry daily to bring reports and perform their daily duties. An investigation is needed to find out if he was enlisted or not."
The Taliban is claiming responsibility for the attack, saying it was planned to coincide with the French foreign minister's visit. He was not in the compound when the shooting started.
It was the third deadly breach of security in Afghanistan in less than a week.
On Saturday, an Afghan soldier working as a Taliban sleeper agent turned on his colleagues, killing five NATO service members, four Afghan soldiers and an interpreter. A day earlier, a suicide bomber dressed as a policeman blew himself up inside the Kandahar police headquarters complex, killing the top law enforcement officer in the restive southern province.
Six policemen were killed also on Monday in a roadside bomb blast in eastern Afghanistan. Officials say they were on patrol in Jaghatu district when their car hit explosives planted in the road.
The Associated Press contributed to this report.