We present a new, general approach to gauge theory on principal $G$-spectral triples, where $G$ is a compact connected Lie group. We introduce a notion of vertical Riemannian geometry for $G$-$C^\ast$-algebras and prove that the resulting noncommutative orbitwise family of Kostant's cubic Dirac operators defines a natural unbounded $KK^G$-cycle in the case of a principal $G$-action. Then, we introduce a notion of principal $G$-spectral triple and prove, in particular, that any such spectral triple admits a canonical factorisation in unbounded $KK^G$-theory with respect to such a cycle: up to a remainder, the total geometry is the twisting of the basic geometry by a noncommutative superconnection encoding the vertical geometry and underlying principal connection. Using these notions, we formulate an approach to gauge theory that explicitly generalises the classical case up to a groupoid cocycle and is compatible in general with this factorisation; in the unital case, it correctly yields a real affine space of noncommutative principal connections with affine gauge action. Our definitions cover all locally compact classical principal $G$-bundles and are compatible with $\theta$-deformation; in particular, they cover the $\theta$-deformed quaternionic Hopf fibration $C^\infty(S^7_\theta) \hookleftarrow C^\infty(S^4_\theta)$ as a noncommutative principal $\operatorname{SU}(2)$-bundle.