A non-citizen must meet certain requirements to be eligible to join the military. The must have an Alien Registration Receipt Card (stamped I-94 or I-551 Green card/INS Form 1-551) as well as a bona fide residence established with an established a record of the U.S. as their home. If the non-citizens comes from countries with a reputation of hostility towards the U.S, they may require a waiver. The federal government cannot petition on behalf of an illegal immigrant so that they can obtain legal status and be able to enlist in the military.
Undocumented immigrants may not enlist in the U.S. military.
https://www.thebalance.com/immigrants-in-the-us-armed-forces-3353965