Surface bundle with flat connection and monodromy representation I saw the following statement:

An $S_g$-bundle $p: E\to B$ admits a flat connection if and only if the
monodromy representation $\rho:\pi_1(B)\to\text{Mod}(S_g)$ lifts to $\rho':\pi_1(B)\to\text{Diff}^+(S_g)$.

I have no idea why it is true, is there a reference or can you give proof?
 A: Suppose that you have smooth connected manifolds $B$, $F$ and a representation $\phi: \pi_1(B)\to Diff(F)$. This defines the associated bundle
$$
E=B\times_\phi F 
$$
over $B$ together with a flat connection $\nabla$ on $E$. Namely, start with the product $\tilde E=\tilde{B}\times F$, where $\tilde{B}$ is the universal covering space of $B$. The fundamental group $\pi=\pi(B)$ acts on the product space diagonally: by covering transformations on $\tilde B$ and via the representation $\phi$ on $F$. This product action is free and properly discontinuous, hence, you form the quotient $E= \tilde E/\pi$. The projection $\tilde E\to \tilde B$ descends to a bundle map $p: E\to B$. At the same time, the product foliation $\{x\}\times F, x\in \tilde B$ on $\tilde E$ descends to a foliation on $E$ which is transversal to fibers of $p$. The tangent distribution of that foliation is your flat connection $\nabla$ on $p: E\to B$.
Conversely, given a flat bundle $p: E\to B$ (i.e. a bundle with a flat connection), you have its holonomy homomorphism $\pi_1(B)\to Diff(F)$.
My favorite reference for this staff is
Steenrod, Norman, The topology of fibre bundles., Princeton Landmarks in Mathematics. Princeton, NJ: Princeton University Press. viii, 229 p. (1999). ZBL0942.55002.
For surface bundles, check also Morita's book
Morita, Shigeyuki, Geometry of characteristic classes. Transl. from the Japanese by the author, Translations of Mathematical Monographs. Iwanami Series in Modern Mathematics. 199. Providence, RI: American Mathematical Society (AMS). xiii, 185 p. (2001). ZBL0976.57026.
