How to 2-pass h264 with CRF and maximum bitrate with ffmpeg? Based on CRF Guide (Constant Rate Factor in x264, x265 and libvpx), quoting:


  Streaming nowadays is done a little more cleverly. YouTube or Netflix
  are using 2-pass or even 3-pass algorithms, where in the latter, a CRF
  encode for a given source determines the best bitrate at which to
  2-pass encode your stream. They can make sure that enough bitrate is
  reserved for complex scenes while not exceeding your bandwidth.


also the article Saving on Encoding and Streaming: Deploy Capped CRF also claims that "Capped CRF" is the highest quality while also making sure bitrate does not go above X but they propose a single pass with:

ffmpeg -i input_file -crf 23 -maxrate 6750k -bufsize 6750k output_file


What's the correct way to generate the highest quality possible file inside a bitrate constraint using ffmpeg with x264?
What's the correct way to generate the highest quality possible file
  inside a bitrate constraint using ffmpeg with x264?


There is no "correct" way. This is still an evolving area of research, and about half the articles you have read on the subject are more marketing that they are science. The "correct" way may also be different for every video. Netflix for example just encodes the video a couple dozen ways, and keeps the one it thinks is best and throws the rest away.

The closest thing to a "best" single answer, would be 2 pass placebo capped CRF.