No prisoner in the custody of the secretary of corrections shall be required to attend as a witness in any criminal action or proceeding except on order of the court before whom the prosecution is pending and under such terms as the court may prescribe.