Yes, employers make those rules for their buildings, company cars and parking lots.
Simply stated this is usually not the employer's rule per say. It is likely a rule forced on them by their insurance policies or legal team. So they post, add it to the manual, etc.
Now, let's look at enforcement. They rarely enforce these rules because of the implications. For example, they have a right to search all cars, but never search inner circle management cars. Even if I say Joe has a gun in his car, they will likely not forcefully search Joe's car. They won't because it brings up the question why they don't search all cars. I guess what I'm saying is the to defend a policy, you have to prove that you are enforcing it consistently. Likely Joe will be fired because he is late 2 days in one month, his management doesn't like him, and he was seen or reported to have been carrying a gun on company property. He will be fired for attendance because they have fired regularly for that. His management not liking him will be the driver for enforcing attendance. The gun thing will be backup if he proves in court that the attendance thing is BS.
Related to search requests. ALWAYS say NO if you have something to hide. Being fired for saying no to a search will open up their policy books and enforcement record to your legal team. Since in most states it is difficult to fire for something other than attendance and continuous insubordination, they will likely not go through with the firing. They will likely resort to a lesser punishment and keep you on. Still, your management will not be on your side at that point, so you have to get another job in the next 3 months or you will find issues with insubordination, expense reporting and attendance which you didn't know you had.
I'm sorry that this is how we live. The reason you always say no to the search is that being fired for refusing a search is much easier for your legal team to defend. I'm not a lawyer, so take this for what it is worth. It doesn't take a lawyer to see that they must show consistency in the policies or they are being used to create a harassing work environment. "Why are you singling me out and harassing me?," is a great question to ask when this comes up. In general, the law is on the employee's side related to issues of discrimination and creation of a harassing work environment.
Admin people are very well trained on these boundaries and will work slow to build a "firing" case. You need to be slow and thoughtful about answers you provide them as they will all be used against you.
Good luck and make good choices.