KIRKUK, Iraq — Tensions in the ancient city of Kirkuk are threatening to boil over as Kurdish forces move to turn their battle lines with ISIS into the border for a Kurdish state.

The city traditionally has had a mix of Iraq’s main ethnic and confessional groups—Kurds, Turkmens (many of whom are Shia), Shia Arabs and Sunni Arabs. But the province is rich in oil and natural gas that the Kurds deem essential as they plan for economic independence, especially since the Kurdistan Regional Government signed a major oil deal with Turkey. They don’t intend to share it. And hostilities with Shia Arabs are growing increasingly dangerous.

Even though ISIS, the so-called Islamic State, is practically on the city’s doorstep, Masoud Barzani, the president of Iraqi Kurdistan, has opposed arming the city’s Arab and Turkmen population since Kurdish forces took control of the region from the Iraqi government last summer. The Kurdish advance came after ISIS took the city of Tikrit, which lies to the south between Kirkuk and Baghdad.

In a recent interview with the London-based Arabic daily newspaper Al Hayat, Barzani said that “We will not allow any forces to enter Kirkuk,” in a message clearly directed at Iranian-backed Shia militias.

The increasing split that threatens to turn into open armed conflict between the Shia militias and Kurdish forces is just the kind of thing the shrewd jihadists of ISIS have exploited in the past, moving into vacuums of power created by corruption and infighting among their opponents to built their pop-up empire in Iraq and Syria. And Kirkuk, with its oil, would be a major prize.

Today, ISIS flags fly just a few hundred meters from Kurdish forces on the tense and active front line near the village of Matara on the Little Zab River, 20 kilometers from the entrance to Kirkuk. On the flat, dusty landscape punctuated by occasional green fields, a mix of Kurdish units in the Iraqi government forces, Peshmerga soldiers from the Kurdistan Regional Government, and Kurdistan Workers Party (PKK) guerrillas (deemed terrorists in Turkey, but fighting alongside U.S. allies in Iraq and Syria) take up positions near the riverbanks. The road that follows this de facto border is well within range of ISIS sniper fire. Several of the villages along the highway proudly fly Shia flags and are dotted with billboards of the cleric Muqtada al Sadr and Hadi al Ameri, the commander of the Iranian-backed Badr Organization. Shia militias fly Iraqi and religious flags from their watchtowers at the entrance to the towns. Any conflict between Shia and Kurds here would be an invitation for an ISIS advance.

It’s a volatile enough situation that the local area commander for the PKK, Ageed Kalary, condemns in no uncertain terms Barzani’s assertion warning off the Shia. “This statement will only push separation and what we need is unity to fight Daesh [the Arabic acronym for ISIS],” says the grizzled guerrilla leader sitting next to a propped-up M16 under a yellow flag bearing the image of his movement’s jailed leader, Abdullah Ocalan.

Kalary’s fighters share a base with a Kurdish unit of the Iraqi government forces only 500 meters from the Zab, and they have been key to holding back the bloody, repressive forces of ISIS for the last seven months. Kalary contends that the river separating his forces from ISIS is a good border to mark Kurdish control, sure, but he argues it is dangerous to pick a fight with Shia militias based on Kurdish ambitions for territory in the future. “Such statements won’t help the Kurds now,” he says unequivocally.

Inside the city of Kirkuk the sense of division and instability is everywhere. Kurdish forces have replaced the Iraqi government in many of the blast-wall-reinforced bases and police stations. At the checkpoints around the city, their soldiers appear on edge. ISIS bombings are a regular occurrence, and although Kirkuk is Iraq’s most diverse metropolis, it is also incredibly segregated and increasingly polarized.

When ISIS attacks hit, panic sweeps through the city’s Sunni Arab communities, where there is fear not only of the barbaric jihadists but of random retribution. Because ISIS claims it fights to defend Sunni Islam and seeks to exploit Arab-Kurdish national divisions, all Sunni Arabs are likely to fall under suspicion, and they commonly are targeted for individual acts of vengeance when civilians in Shia, Turkmen or Kurdish neighborhoods are hit by ISIS terror attacks. Unlike the Shia and Turkmen, the Sunnis don’t have community militias to protect them, nor do they have the same confidence in the official security forces that Kurds do, but some are finding increased acceptance in Kurdish neighborhoods.

Abu Bassem, a Sunni refugee from Tikrit who fled when ISIS took the city, has found refuge in the Kurdish quarter of Runaki along with his family. He declines to give his real name because he was a member of the Iraqi army and is concerned about jihadist reprisals. Although grateful to find a safe haven, he feels neglected by Kurdish authorities. “We haven’t received any support since we arrived here,” he complains, citing the difficulty of paying for food and shelter.

“We can’t live in Shia areas because of the tension,” says Abu Bassem, and yet he worries about those sympathetic to ISIS in the Sunni districts, so he doesn’t feel welcome among his own people.

As this war continues, it chips away at Kirkuk’s social cohesion, and if open clashes erupt between Kurdish and Shia forces it could crack the city wide open. That would provide the path for an ISIS advance that would brutally punish both groups.