It was a photo op designed to deliver public relations gold — pictures of the prime minister standing alongside Canadian troops in the battlefield, but it didn't go quite as planned.

Newly released documents have shed fresh light on the confusion unleashed within the military when a 2015 trip to Iraq and Kuwait by former prime minister Stephen Harper took an unexpected turn.

Reporters travelling with Harper were required to sign a lengthy written agreement pledging not to photograph or identify Canadian service members working at an airbase in Kuwait and alongside Kurdish Peshmerga forces in Iraq. Journalists were warned doing so could expose those members and their families to threats from ISIS.

Reporters were careful to respect the guidelines. So, many were surprised when Harper's own media handlers appeared to flout them.

A team from 24/7, an in-house Prime Minister's Office (PMO) production unit that put together flattering online videos of the prime minister, posted images of Harper posing with the troops. Trouble was the pictures  clearly showed the faces of Canadian personnel in the background.

When media outlets published stories pointing out the apparent contradiction, the PMO claimed, at first, that the images had been cleared by the military. Documents obtained by CBC News under the Access to Information Act show that statement left the defence department scrambling.

"We have been directly ordered by [the Canadian Joint Operations Command] to get the details on who exactly in the 'department' approved the PM videos (issue in the media now) from his visit in theatre since CJOC was not involved in the imagery approval process," reads one e-mail sent on the morning of May 5, 2015, the day the first news stories about the images were published.

"Further to that we have been tasked to review the videos now," the e-mail continues.

Harper Foreign Trip 20150502

Prime Minister Stephen Harper speaks to members of the media as he visits members of the Advise and Assist mission west of Erbil, Iraq, on Saturday, May 2, 2015. (Sean Kilpatrick/Canadian Press)

In more than 500 pages of documents, it's never revealed who, if anyone, approved the release of the images. The documents, instead, show the military clearly in the dark.

"We were never approached to review prior to release. Only the reporters asked me about their own footage," writes one public affairs officer in an e-mail to a brigadier-general looking for answers.

That same brigadier-general writes in another e-mail: "I was told someone on the ground vetted but no name at this point."  

Another email chain, marked "secret" shows military officials openly questioning the official line from the PMO.

"Quick question that I'm pretty sure I know the answer to, did anyone in the [Task Force] have a look and approve the 24/7 videos that the PMO took on the recent visit for [Operational Security]?" reads one email — with the sender and recipient's names redacted.

"We have not seen any videos," comes the reply.

"Knock me over with a feather," the correspondence concludes.

Messages continued to fly, with some showing a growing level of frustration among military officials.

One military officer writes of receiving a "panic'd call" from the Privy Council Office.

Another message urgently asking whether anyone on the ground in Iraq had reviewed the videos prior to their release concludes, "I don't suspect so. So [now] the [minister of national defence] is scrambling to back up their story."

PMO video: Harper visits Canadian troops in Iraq1:05

Other emails show questions were being raised about whether the prime minister's staff agreed to the same strict conditions as the media when it came to publishing images and video.

"Did the PMO staff sign the same 3-4 page (legal size paper) undertaking that the rest of the media signed in Camp Canada," reads one e-mail. "It was longer than my mortgage document."

The military eventually did review the images. The PMO removed two videos from its website and admitted posting them was a mistake.

Rob Nicol was Stephen Harper's Director of Communications during the trip to Iraq and Kuwait and now works at a private consulting firm.

"When concerns were first raised, it was initially understood that all the images had been submitted, reviewed and approved," Nicol wrote in an e-mail to CBC News. 

"On further investigation, it turned out that some images had not. The PMO withdrew the unapproved images, corrected the record at that time, apologized and subsequently worked to improve the approval protocols."

The documents include copies of several images taken from the prime minister's website. In all of them, the faces of military personnel are carefully whited out.

Two-year wait for documents

The documents show the military carefully monitored media coverage of the incident and took great care to craft a response from Gen. Tom Lawson, then chief of the defence staff. 

The general issued a statement on May 5, 2015 that read, in part: "following a CAF assessment of the photos and video in question, we have determined, though the risk is assessed as low, to recommend two not be posted."

It took the Department of National Defence two years to process an Access to Information Request from CBC News for the documents related to the prime minister's visit. In that time, Stephen Harper and his Conservative Party were swept from power.

As for 24/7, the Liberals under Justin Trudeau scrapped the in-house project soon after taking office.