Ali bin Abu Talib reported,

The Prophet ﷺ sent out an army and appointed a man to lead them. The commander lit a fire and ordered them to enter it. Some of the men intended to enter it, while others said, "We fled from the fire in the first place."The matter was mentioned to the Prophet ﷺ, and he said of those who had intended to enter it, "Had they entered it, they would have remained in it until the Day of Resurrection."To the others he said, "There is no obedience in disobedience to Allah. Obedience is only in what is right."

Bukhari 7257

Sahih

حدثنا محمد بن بشار حدثنا غندر حدثنا شعبة عن زبيد عن سعد بن عبيدة عن أبي عبد الرحمن

عن علي رضي الله عنه

أن النبي ﷺ بعث جيشا وأمر عليهم رجلا فأوقد نارا وقال ادخلوها فأرادوا أن يدخلوها وقال آخرون إنما فررنا منها فذكروا للنبي ﷺ فقال للذين أرادوا أن يدخلوها لو دخلوها لم يزالوا فيها إلى يوم القيامة وقال للآخرين لا طاعة في معصية إنما الطاعة في المعروف

البخاري 7257صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Reports of single narrators
Chapter
Acceptance of the report of a single truthful narrator regarding adhan, prayer, fasting, obligations, and rulings
Numbering
Darussalam 7257
Bukhari 7257