Local gauge transformation in Fock space of photons I'm currently playing around with gauge transformations in the Fock space of photons.
Let's consider a local gauge transformation with gauge function $f(\mathbf{r})$.
So the magnetic vector potential transforms like
$$\begin{align}
\mathbf{A}'(\mathbf{r}) 
 &= \mathbf{A}(\mathbf{r}) + \mathbf{\nabla}f(\mathbf{r}) \\
 &= U(f)\ \mathbf{A}(\mathbf{r})\ U^\dagger(f)
\end{align} \tag{1}$$
and the Fock state of photons transforms like
$$|F'\rangle = U(f)\ |F\rangle \tag{2}$$
where $U(f)$ is a still unknown unitary operator.
According to Quantization of the electromagnetic field
the quantized vector potential is given by the operator field
$$\mathbf{A}(\mathbf{r})=
\sum_{\mathbf{k},\mu}\sqrt{\frac{\hbar}{2\omega V\epsilon_0}}\left\{
\mathbf{e}^{(\mu)}a^{(\mu)}(\mathbf{k})e^{i\mathbf{k}\cdot\mathbf{r}}+
\bar{\mathbf{e}}^{(\mu)}{a^\dagger}^{(\mu)}(\mathbf{k})e^{-i\mathbf{k}\cdot\mathbf{r}}
\right\} \tag{3}$$
where $\omega=c|\mathbf{k}|=ck$ is the frequency,
and ${a^\dagger}^{(\mu)}(\mathbf{k})$ and $a^{(\mu)}(\mathbf{k})$
are the canonical creation and annihilation operators
for photons with wave vector $\mathbf{k}$ and polarization $\mu$.
Now my goal is to express the unitary operator $U(f)$ in terms
of the gauge function $f(\mathbf{r})$ and the photon creation and annihilation operators.
In search for the operator $U(f)$ I make the approach
$$U(f)= e^{iG(f)} \tag{4}$$
where $G(f)$ is an unknown Hermitian operator.
Plugging this into (1) and using $e^{iG}=1+iG+O(G^2)$ I get
$$i[G(f),\mathbf{A}(\mathbf{r})] = \mathbf{\nabla}f(\mathbf{r}) \tag{5}$$
And now I'm stuck.
The only thing I can guess is that the solution will probably look like this
$$G(f)=\int d^3r\ f(\mathbf{r}) \sum_{\mathbf{k},\mu} \ ...??... $$
Any ideas how to proceed? Is it even possible?
 A: You have touched on a point here which, in my experience, often gets glossed over, mentioned offhand, or mentioned indirectly (meaning it would be hard to realize it's the same point being mentioned without already knowing the answer) in first treatments of QFT.
You may have heard it mentioned at some point that the modern perspective on gauge symmetry is that it's a redundancy in our description rather than a symmetry which really tells us something. This will usually be mentioned in passing, but not actually given any substance till one is introduced to the Faddeev-Popov method which involves integrating over only the gauge-inequivalent configurations in the Feynman path integral. How much detail or justification is given for this would then depend entirely upon the source you're working from.
Off the top of my head, I remember what the following sources mention on the matter: David Tong's gauge theory notes mention offhand that the Noether charge generating local gauge transformations should annihilate physical states (which is equivalent to @ACuriousMind's comment about BRST quantization) and are generally good notes on gauge theory. Weinberg's QFT volume 2 which, if you can make your way through it, has a very nice discussion about the connection between BRST symmetry, the Faddeev-Popov method I mentioned, and the annihilation of physical states. There's also a QFT book by Nair which dedicates some time to a more canonical treatment than most modern books, and has some nice things in general to say about gauge theories.
To get more at your question, however, I can first tell you what the answer is, then make a couple comments about what's going on. But since it's actually a fairly involved thing you've hit on, I will have to leave you with a couple references which I found very helpful when I first encountered these ideas properly.
So, (I may have some signs off here), the $G$ you're looking for will look roughly like
$$
G[f]=-\int d^3x f(x)\partial_i E^i
$$
where $E^i$ are the components of the electric field (just using the canonical commutation relations between $A_i$ and its conjugate momenta you can show that this indeed genergates the right transformation). You may note that $\pi^i=-E^i$ is the momentum canonically conjugate to the vector potential and that this quantity is the Noether charge implied by Noether's theorem applied to the gauge symmetry. You may have heard before that Gauss' law, the left hand side of which is being integrated against $f$ here, is a constraint equation, which is true if we were to write out the Maxwell Lagrangian and observe that $A_0$ plays the role of a Lagrange multiplier. This sort of thing is actually entirely typical of gauge symmetry...the generator of gauge transformations always looks like a constraint which vanishes on the equations of motion. This is actually the reason behind why the generators of gauge transformations annihilate physical states. They represent constraints which must be imposed on our states.
So, this has all been handwaving and vague statements. I can add to them even further by pointing out that it's possible for some gauge transformations to actually produce a charge $G$ which does not vanish, and these therefore will act non-trivially on our physical states despite being "gauge" transformations. Indeed, we know this needs to be the case because electric charge exists. This leads to the idea of asymptotic symmetries, which I don't think I can really do any justice to in this post. The nice thing is that essentially everything about them can be understood classically, so there's no barrier to entry if you're still learning QFT (as you mentioned in a comment). I can, however recommend some references. This reference by Banados and Reyes I found to be a good first introduction to some of the ideas here and fairly approachable. I find Dirac brackets (a modification to the Poisson bracket of classical mechanics) hard to work with though, so I can also recommend this which uses, in my opinion, more elegant methods if you don't mind playing with some differential geometry, though their goal is more focused on spacetime symmetries and gravity (where these asymptotic symmetries are more commonly discussed). The ideas, however, are essentially the same for non-spacetime symmetries, though some of the technical details change.
