This 2010 presentation and speaking notes from the NSA’s Office of Legal Counsel explains the legal authorities governing the agency’s computer network operations (CNO) activities: see the New York Times article Hunting for Hackers, N.S.A. Secretly Expands Internet Spying at U.S. Border, 4 June 2015.