The Lord is with Joseph. The keeper of the prison commits the prison’s affairs into Joseph’s hands.

Genesis 39:21–23

21 But the Lord was with Joseph, and shewed him mercy, and gave him favour in the sight of the keeper of the prison.
22 And the keeper of the prison committed to Joseph’s hand all the prisoners that were in the prison; and whatsoever they did there, he was the doer of it.
23 The keeper of the prison looked not to any thing that was under his hand; because the Lord was with him, and that which he did, the Lord made it to prosper.

Elder L. Tom Perry wrote:

“Again, Joseph, through no fault of his own, was down—but not out. Joseph refused to become discouraged or depressed. If he had to be a prisoner, he would be the best prisoner in all the prison. His enthusiasm found favor in the sight of the keeper of the prison. He became chief among all the prisoners. This meant Joseph was responsible for all the prisoners in the prison. Once again, he had made the best out of a bad situation.”

(Living with Enthusiasm [1996], 2–3.)