Is it legal to do a barrel roll?
This answer is for the US. A parachute is required of everyone when the aircraft is carrying someone who is not a crew member.  The maneuver must not be prohibited by the aircraft flight manual. (Or must it be specifically permitted?)   (Future edit needed.)  And of course you must not exceed the permitted airspeed and G-load parameters.

There is no relation to the license (certificate) the pilot holds.

Actually, this related answer indicates that the airplane or glider must be in the "acrobatic" category: What are the US definition and restrictions on aerobatic flight?. But it's not clear what specific FAR is involved, if any.