Definitely the way you designed it is a right approach for doing it.
If you want to take it further you can use polymorphic relationships and allow assigning the roles to both the users and the teams using the same pivot table, it's structure would be something like this:
roleables [role_id, roleable_id, roleable_type]
If you're not aware of the polymorphic relationships, don't worry the way you have designed it is a good one, and actually could be the best if you have no need for the polymorphic relationship.