  We demonstrate how to obtain optimal constraints on a primordial
gravitational wave component in lensed Cosmic Microwave Background (CMB) data
under ideal conditions. We first derive an estimator of the tensor-to-scalar
ratio, $r$, by using an error-controlled close approximation to the exact
posterior, under the assumption of Gaussian primordial CMB and lensing
deflection potential. This combines fast internal iterative lensing
reconstruction with optimal recovery of the unlensed CMB. We evaluate its
performance on simulated low-noise polarization data targeted at the
recombination peak. We carefully demonstrate our $r$-posterior estimate is
optimal and shows no significant bias, making it the most powerful estimator of
primordial gravitational waves from the CMB. We compare these constraints to
those obtained from $B$-mode band-power likelihood analyses on the same
simulated data, before and after map-level quadratic estimator delensing, and
iterative delensing. Internally, iteratively delensed band powers are only
slightly less powerful on average (by less than 10\%), promising
close-to-optimal constraints from a stage IV CMB experiment.
