Sayyiduna al-Miqdam (may Allah be pleased with him) said that the Messenger of Allah (peace and blessings be upon him) said: "Obey your rulers, whatever they may be. If they command you with something of what I have brought you, they will be rewarded for it, and you will be rewarded for obeying them. And if they command you with something that I have not brought you, then it is upon them and you are free of it. That is because when you meet Allah, you will say: 'Our Lord, no injustice.' He will say: 'No injustice.' Then you will say: 'Our Lord, You sent messengers to us and we obeyed them by Your permission; You appointed successors (khalifahs) over us and we obeyed them by Your permission; and You appointed rulers over us and we obeyed them for Your sake.' He will say: 'You have spoken the truth; it is upon them and you are free of it.'"
Hadith Referenceالمعجم الكبير للطبراني / باب الميم / 17792