It was born out of American and British intelligence collaboration in World War II, a long-private club nicknamed the Five Eyes. The members are five English-speaking countries who share virtually all intelligence and pledge not to spy on each other: USA, UK, Australia, New Zealand, & Canada.
Actually it was designed so that Brit intel can spy on Americans and hand then info over to the CIA. Then the CIA pretends it came from a “foreign source”, and that they broke no US law.
But this is a fiction, the conspiracy with foreign intel services to spy on Americans is precisely where the illegality happened. It’s basically the “murder for hire” concept. You don’t escape culpability by HIRING someone to do it for you.