The gravitational wave event from the binary neutron star (BNS) merger GW170817 and the following multi-messenger observations present strong evidence for i) merger ejecta expanding with substantial velocities and ii) a relativistic jet which had to propagate through the merger ejecta. The ejecta's expansion velocity is not negligible for the jet head motion, which is a fundamental difference from the other systems like collapsars and active galactic nuclei. Here we present an analytic model of the jet propagation in an expanding medium. In particular, we notice a new term in the expression of the breakout time and velocity. In parallel, we perform a series of over a hundred 2D numerical simulations of jet propagation. The BNS merger ejecta is prepared based on numerical relativity simulations of a BNS merger with the highestresolution to date. We show that our analytic results agree with numerical simulations over a wide parameter space. Then we apply our analytic model to GW170817, and obtain two solid constraints on: i) the central engine luminosity as L iso,0 ∼ 3 × 10 49 − 2.5 × 10 52 erg s −1 , and on ii) the delay time between the merger and engine activation t 0 − t m < 1.3 s. The engine power implies that the apparently-faint short gamma-ray burst (sGRB) sGRB 170817A is similar to typical sGRBs if observed on-axis.