#1) quit trying to be his buddy. Parent his ***. Children want boundaries. And when you establish them, they will push at them. Then there has to be consequences.
2) outline what those consequences are, and do them. My wife always threatened to spank her daughter, if the daughter did this or that. But she only spanked her when after several provocations, my wife lost her temper. When I got involved with them I told the daughter, don't do this or that. She did something in a restaurant and I told her not to. She looked at me, and did it again. I jumped up, and she jumped up, and ran, because she knew I was gonna spank her right then and there. She thought she could get away with it because we were kn a public place. I had spanked her once, early in the relationship. Told her not do something, she did, and I swatted her on the ***, once. She looked at me in shock, and surprise, "That hurt!" she said. "It is supposed to." I replied. From then on, she knew I wasn't playing any games, and what I said was law. Never had a lick of trouble out of her since.
3) never punish when angry. Sit 5 minutes if you have to.