The Border is controlled on the federal level by federal immigration officers (CBP) where Marijuana is still illegal. And immigration officers have the right to search anyone entering the country for any reason and deny them access for crimes involving moral turpitude.
Ergo, CBP was operating within their authority.
8 U.S.C. § 1357(a)(3) Authorizes federal immigration officers (e.g., CBP) to search vehicles, vessels, and persons within 100 miles of a border for immigration enforcement purposes without a warrant.
21 U.S.C. § 844 Makes possession of controlled substances (like marijuana, LSD, cocaine, etc.) federally illegal unless prescribed or legally obtained.
8 U.S.C. § 1182(a)(2)(A)(i)(I) – Crimes Involving Moral Turpitude (CIMT) Any alien convicted of, or who admits having committed, or who admits committing acts which constitute the essential elements of a crime involving moral turpitude (other than a purely political offense)... is inadmissible.