Since its creation, in 2002, the Department of Homeland Security has had six heads: two governors, a federal judge, the top lawyer at the Department of Defense, a four-star general, and Kirstjen Nielsen, who took over in December. Compared to her predecessors, Nielsen’s résumé is conspicuously thin. Prior to joining the Trump Administration, she was a little-known cybersecurity consultant with no major management experience. “In a normal Administration, there isn’t a chance in hell she would get nominated for anything above an undersecretary job,” a former national-security official, who served under George W. Bush, told me.

Over her first three months in the job, Nielsen has showcased her loyalty to the White House that elevated her. In early January, she cancelled the status of two hundred thousand Salvadorans who’ve lived legally in the U.S since 2001. A week later, in sworn testimony, she told members of the Senate Judiciary Committee that she couldn’t recall whether the President had used the word “shitholes” to describe African countries during an Oval Office meeting on immigration. Then, in February, Nielsen issued a series of aggressive statements criticizing bipartisan immigration bills that appeared to be gaining support in the Senate. One of the proposals, according to D.H.S., “would effectively make the United States a Sanctuary Nation where ignoring the rule of law is encouraged.” Lindsey Graham, the South Carolina Republican, complained, “It sounded like something that came from a political hack, not D.H.S.”

I recently spoke to seven current and former officials at D.H.S. to understand what’s been driving Nielsen. All of them described her as more of an opportunist than an ideologue. She rose through the ranks of the department because she positioned herself close to key figures in the White House, the officials told me; each of them characterized Nielsen as a close ally of John Kelly, the White House chief of staff. The tough stance she has adopted on immigration is largely an extension of his. To improve her standing with the President, Nielsen coöperated with a cadre of White House staffers, led by Stephen Miller, the President’s senior adviser, who see D.H.S. as a tool to advance their hard-line agenda on immigration. The officials I spoke with conceded that the alternatives to Nielsen’s nomination could have been more extreme. But Nielsen, in their view, posed a special problem: because she was so pliant and inexperienced, they said, she risked turning D.H.S. into an overt political pawn of the Trump White House.

Nielsen joined the Trump Administration in January, 2017, when she began serving as John Kelly’s chief of staff at the Department of Homeland Security. Her role was controversial from the start. After Kelly was tapped to lead D.H.S., he took the advice of his predecessor, Jeh Johnson, and chose a seasoned department hand, a former Air Force colonel named Alan Metzler, as his chief of staff. But the day before Trump’s Inauguration, Kelly received a phone call from Rick Dearborn, a senior Trump aide, telling him that Metzler was unacceptable to the President-elect. “Dearborn told him, ‘Anyone associated with the Obama Administration was no good. It didn’t matter what your credentials were,’ ” someone with knowledge of the conversation told me. “Kelly was livid.”

At the start of the Presidential transition, Nielsen and Kelly didn’t know each other personally, but they grew closer as the Inauguration approached. Nielsen, who was part of the transition team, was tasked with preparing Kelly for his confirmation hearings. She was also angling for an undersecretary job at a D.H.S. sub-agency called the National Protection and Programs Directorate, which specialized in cybersecurity. (According to the political news site Axios, Kelly planned to nominate her for that job.) The transition team had created a new position within D.H.S., known as the senior adviser to the White House, which was part of what the incoming Administration called its “beachhead team.” The idea was to staff government agencies with individuals who could serve as a check on career officials who might have reservations about Trump’s agenda. “It was basically the political commissar of the department,” one official told me. When the person who filled the post, a former naval intelligence officer and conservative-media personality named Frank Wuco, learned about Kelly’s pick for chief of staff, he blocked it. “They just didn’t want an Obama holdover,” the official told me. Although Kelly resented the interference, he acceded without a fight. Many senior officials at the department interpreted his acquiescence as a sign of political naïveté. One of them told me, “His thinking was, ‘I have my relationship with the President. The staff doesn’t matter so much.’ That was the military mind-set. And it was a mistake.” Nielsen emerged as the replacement.

The early days of the Trump Administration were especially chaotic at D.H.S., beginning with the travel ban, which was instituted a week after Trump took office. Even though D.H.S. was in charge of implementing it at airports, Kelly was blindsided by the sudden announcement of the executive order initiating the ban, one former official told me. (Both the White House and D.H.S. dispute this.) “He wasn’t really running the department at the time,” the official said. Gene Hamilton, a former Jeff Sessions staffer in his mid-thirties who served as a D.H.S. senior adviser, “was the only one who was really communicating with the White House about the travel ban.” (A White House official told me, “Hamilton was a very valuable adviser to General Kelly, but to imply that he played a more significant role than the Secretary is false.”) As the initial chaos subsided, Kelly increasingly relied on Hamilton as he settled into the job, particularly on technical issues related to immigration policy. “Kelly looked to Hamilton as the expert,” the official said. “It was something like, ‘Gene, make sure I have this right.’ Whatever Hamilton said, Kelly ate it up.”

Nielsen made the dynamic worse. Daily meetings among senior staff at D.H.S., which were routine in years past, were cancelled; in their place, Nielsen started inviting Hamilton and other political appointees to meet directly with Kelly. Meanwhile, other senior officials, including the deputy secretary of D.H.S., struggled to get one-on-one access to Kelly because Nielsen controlled his schedule and effectively shut them out. “She built a wall around him,” one former official told me. “She was with him constantly, even when he travelled. It was all about her getting face time with Kelly and also making the political appointees happy.” (A D.H.S. spokesperson denied that Nielsen did anything out of the ordinary.)

When Kelly was chosen as the White House chief of staff, in July, Nielsen initially went with him to serve as his deputy and as a special assistant to the President. She appealed to people at the White House because she had Kelly’s support, and Trump loyalists considered her unthreatening. “Nielsen doesn’t want to piss off the President,” one of the former officials told me. “She has zero independent political power base in Washington. She’s a hundred per cent this White House and John Kelly. They wanted someone who didn’t have a record speaking out against the President and who wouldn’t go in that direction.”

There was another advantage to having Nielsen as a nominee: she wouldn’t cause a protracted confirmation battle in the Senate. From 2002 to 2007, Nielsen served in the Bush Administration, where she spent most of her time overseeing domestic disaster-relief-and-prevention policy at the White House. She left for the private sector in the wake of controversy over how the Bush Administration had mishandled its response to Hurricane Katrina. Though two congressional reports faulted Nielsen and her team for failing to inform the White House about breaking developments on the ground in New Orleans, several Administration officials ultimately came to her defense. She rebranded herself in the private sector. “Like many other people of that era, she understood how big cybersecurity was going to be,” a former colleague of hers from the Bush Administration told me. “She did her best to characterize herself as a cyber expert. But I’d put her on the low end of that range of capacity and experience.” Still, it was enough to earn her notable cybersecurity-consulting jobs, an academic fellowship at George Washington University, and a prominent post at the World Economic Forum— irreproachably nonpartisan credentials.

When Trump nominated her, in October, many officials at D.H.S. were stunned. “No one thinks she’s qualified,” one of them told me at the time. “This is a big department, a young department. Leadership is especially important, and she definitely doesn’t have the gravitas to be Secretary. It’s terrible for morale.” There were rumors of impending resignations. (The D.H.S. spokesperson denied this.) Nevertheless, dozens of former D.H.S. officials signed letters supporting Nielsen’s nomination in November, citing, among other things, that she was the first department head to have already served in the department. “This means that there will be no learning curve for Ms. Nielsen and she can hit the ground running at the DHS on Day One,” two former D.H.S. secretaries, Tom Ridge and Michael Chertoff, wrote in one of them. As expected, Nielsen was swiftly confirmed.