What security clearances does a foreign citizen doing a flying course in the United States have to pass?
You need 2 things before you can start flight training in the U.S.:


An appropriate visa. A tourist visa (B2), business visa (B1) or VWP (Visa Waiver Program) is not accepted
TSA clearance through the Alien Flight Student Program (AFSP)


The complete process is documented at the AOPA website.

In a nutshell, this is what you need to do:


Make sure you have a proper visa or permanent resident card (green card). A visa that allows you to live in the U.S. is fine (you don't need a specific visa for flight training). Examples of appropriate visas: H1B, H4, L1, L2 but there are many others
If you don't have one of the visas mentioned above, you need to apply for a student visa (M-1). You need to contact a flight school that will assist you with the visa application.
Contact a flight school if you haven't already done so in the previous step. They will register your "case" and provide you with information you need when applying for TSA clearance.
Apply for the AFSP program on the TSA website
Wait for approval by the TSA (is a multistep process that could take a while. It includes having your fingerprints scanned, among other things)
Start your training