This was originally posted at The Guardian.

After yet another avalanche of documents showing how the NSA has spied on our communications for years, Americans should be asking, how did we get here?

The answer is simple: secrecy poisoned our system of checks and balances. Both our courts and Congress failed to put meaningful limits on the NSA's surveillance, trading away our privacy in the process. The American people never consented to the National Security Agency's (NSA) effort to "collect it all" by tracking and inspecting every digital footprint we leave behind. Instead, the secret opinions of a secret court retroactively blessed a vast NSA surveillance program years after it began.

The more we learn, the clearer it is that our surveillance laws and oversight rules are in dramatic need of reform, like the USA Freedom Act, that provide both transparency and real protections for privacy.

The latest documents show how secrecy distorted the oversight process from the beginning. The Foreign Intelligence Surveillance Court (known as the Fisa court) rewrote the so-called pen register statute behind closed doors to meet the NSA's demands for dragnet surveillance of Americans' internet activity. (The pen-register law allows the government to obtain – without a warrant – phone-call details such as who an individual calls, and when.)

For years, Congress sat back as the Fisa court fruitlessly sought to deal with the NSA's repeated violations of the court's own rules. The irony is that the NSA ultimately gave up on the internet-metadata program entirely – ending the bulk collection of this data in 2011 for "operational and resource reasons". But the damage lives on, in other mass-surveillance programs that continue to this day, authorized by the same faulty legal reasoning.

Among the newly released documents is an opinion written in July 2004 by Colleen Kollar-Kotelly, the former presiding judge of the Fisa court, authorizing the bulk collection of internet metadata from US switches.

What's most striking about the opinion is not that it paved the way for the NSA's internet-metadata program, it's that the NSA's internet-metadata program paved the way for the opinion. As the 2009 NSA Inspector General Report disclosed this summer by the Guardian reveals, the internet-metadata program existed long before the government ever sought court approval. First carried out under a secret authorization by President George W Bush, it was only when lawyers from the Department of Justice threatened to resign in March 2004 – in what has been described as a heroic intervention in Attorney General John Ashcroft's hospital room – that the White House decided to put the program under judicial supervision.

But the storied confrontation at Ashcroft's bedside did not put an end to the bulk collection of internet metadata. Nor did it prompt the executive branch to propose changes to the law that would put bulk collection on firm statutory ground. Instead, the episode led government lawyers to try to recreate a basis for bulk collection in existing statutory authorities – in this case, the "pen register and trap-and-trace" provisions. And the Fisacourt acquiesced, reverse-engineering statutory authority for the very government surveillance program that was already underway.

Perhaps that's why the Kollar-Kotelly opinion reads as if it is an attempt to drive a square peg in a round hole. The opinion even acknowledges, in a footnote, that Congress never contemplated the use of the pen register provision for bulk collection. But rather than rejecting the mass tracking of Americans' internet activity, the opinion sets off in search of a way to justify it.

Indeed, that was the whole point. The outcome was all but prearranged. As the Inspector General report reveals, members of the court sat through secret briefings by intelligence officials about the efforts of NSAand Department of Justice lawyers to find bulk collection a statutory home. By ordinary standards, the process was hardly an adversarial one. Instead, it has all the look of a friendly negotiation en route to a predetermined result.

Years later, the flaws inherent in the program's secret origins and retroactive court approval continued to come to light. Recounting one compliance incident after the next, the new documents show the Fisacourt's long-running struggle to rein in an intelligence agency whose surveillance programs long predated the court's involvement. The court repeatedly admonished the government for gross violations of court orders, only to approve more and more far-reaching collection based on government promises that next time, things would be different.

With the exception of a handful of outspoken senators, like Senators Ron Wyden (Democrat from Oregon) and Mark Udall (Democrat from Colorado.), Congress appears to have been an almost-passive player in the oversight process. Letters and reports show that Congress was generally informed of compliance problems only months after DOJ lawyers first reported them to the Fisa court. The congressional committees charged with oversight appear to have been content to sit back and watch the court attempt to supervise these programs.

The result is not heartening, though it may be predictable. Secrecy ensures there is no vocal constituency on the side of privacy. It means there is no one to object, either at the ballot box or in court. Rather, we're left to the mercy of a secret agency overseen by a secret court and less than transparent congressional intelligence committees.

In the end, the internet-metadata program was discontinued because it failed to provide useful counterterrorism information. Yet its precedent continues, in court opinions justifying other bulk-collection programs, including the NSA's mass call-tracking program. That is a twisted irony, and it calls into further question the legal legitimacy of mass surveillance.

It is also a vital lesson. It should be no surprise that a surveillance program whose existence was assumed rather than debated, and whose legal basis was retrofitted rather than carefully considered by Congress, trampled on the privacy rights of hundreds of millions.

Learn more about government surveillance and other civil liberties issues: Sign up for breaking news alertsfollow us on Twitter, and like us on Facebook.