The attackers then lobbed a grenade over the gate, killing five other officers, Brij Lal, another Uttar Pradesh police officer, said.
A rickshaw puller outside the gate was killed in the ensuing crossfire, Lal said.
It was unclear if the suspects were killed, he said.
The dead officers belonged to a special police force created to combat fighters, Lal said.
Police said they were hunting for the attackers, who were armed with assault rifles and grenades, and believed that two of them were wounded.
Police have cordoned off the attack site and are investigating the attack, Lal said.
The NDTV news channel quoted home ministry sources as saying they suspected Lashkar-e-Tayabba, an armed Muslim group, was behind the attack.
India blames Lashkar-e-Tayabba for an attack on its parliament in December 2001 and on a Hindu temple in western Gujarat state in 2002.
In November, a series of bombs ripped through courthouse complexes in three north Indian cities, including Lucknow.
The blasts killed at least 16 lawyers and wounded nearly 60 others.