Open subgroups of Galois group with restricted ramification

I am trying to work out Problem 1.24 of Gouvea's lecture notes on deformations of Galois representations, which goes as follows:

Let $K$ be a number field and $S$ a finite set of primes of $K$. We consider $K_S=$ the maximal extension of $K$ which is unramified outside $S$, and the Galois group $G_{K,S}=Gal(K_S/K)$. Show that any open subgroup $H$ of $G_{K,S}$ is again of the form $H=G_{K_1,S_1}$ for some finite extension $K_1/K$.

So the obvious idea is to take the fixed field $K_1=K_S^H$ (which is finite over $K$ because $H$ is of finite index) and set $S_1=\{\text{primes of$K_1$that lie above a prime belonging to$S$}\}$. Then $H=Gal(K_S/K_1)$ so all we have to show is that $$K_S={K_1}_{S_1}.$$ Is this correct? I think I have proven at least "$\subseteq$": It suffices to show that, if $K_2/K$ is finite and unramified outside $S$, then $K_2\subseteq {K_1}_{S_1}$. For such a $K_2$, we have that the composite $K_2K_1/K$ is finite and unramified outside $S$ (because $K_1$ and $K_2$ have these properties), and we conclude that $K_2K_1/K_1$ is unramified outside $S_1$, because if a prime $\mathfrak P\notin S_1$ of $K_1$ ramifies in $K_2K_1$, i.e. $\mathfrak P \mathcal O\subseteq \mathfrak Q^2$ for the ring of integers $\mathcal O$ in and a prime $\mathfrak Q$ in $K_2K_1$, then we have for $\mathfrak p:=\mathfrak P \cap K\notin S$ that $\mathfrak p \mathcal O \subseteq \mathfrak P \mathcal O \subseteq \mathfrak Q^2$ also ramifies, a contradiction.

For the reverse inclusion it suffices to show that, if $L/K_1$ is finite and unramified outside $S_1$, then $L/K$ is finite and unramified outside $S$. Maybe this is obvious but I do not see it... EDIT: this is true, because we additionally have that $K_1/K$ is unramified outside $S$ (see the comments for a counterexample to the general situation). Indeed, a prime $\mathfrak p \notin S$ of $K$ factors in $K_1$ as $\mathfrak p \mathcal O_{K_1}=\mathfrak P_1 \cdots\mathfrak P_g$ (the $\mathfrak P_i$ all pairwise distinct) and in $L$ as $\mathfrak p \mathcal O_{L}= \mathfrak p \mathcal O_{K_1} \mathcal O_L=\prod_i (\text {prime factors of }\mathfrak P_i, \text{all pairwise distinct})$, which means that $\mathfrak p$ is unramified in $L$.

• The last statement is certainly false on its own (e.g. $\mathbb Q(i,\sqrt{-5})/\mathbb Q(\sqrt{-5})/\mathbb Q$). However, you haven't used the fact that $K_1/K$ is unramified outside $S$! – Mathmo123 May 7 '18 at 21:08
• I don't see how that is a counterexample, $\mathbb Q(i,\sqrt{-5})/\mathbb Q(\sqrt{-5})$ is unramified (so in particular unramified outside $S_1$) and $\mathbb Q(i,\sqrt{-5})/\mathbb Q$ is unramified outside $S=\{2,5\}$. Please correct me if I miscalculated something here. Besides, if my last statement were false, then my main statement would also be false... – Layer Cake May 8 '18 at 9:03
• If $S =\{2\}$, then it would be a counterexample to the statement as you've written it. The point is that you also know that $K_1/K$ itself is unramified outside $S$. And once you know that $K_1/K$ is unramified outside $S$ and $L/K_1$ is unramified outside $S_1$, then it really is clear that $L/K$ is unramified outside $S$. – Mathmo123 May 8 '18 at 13:03
• Oh, of course! I'm sorry, I haven't been thinking clearly today! Many thanks for your help. – Layer Cake May 8 '18 at 18:14