Former defence personnel or public servants who spill the nation's most classified secrets will face decades behind bars under new laws.
Defence Minister Richard Marles introduced legislation on Thursday that will require former military personnel and defence staff members to obtain approval to work for a foreign military or government entity.
Failure to get approval could lead to 20 years in prison, while those who are granted permission but then stray from their requirements could face five years behind bars.
Those who do provide training about military techniques or weapons will also face 20 years.
The government says the new laws strengthen national security by identifying people who may be working either unwittingly or deliberately for a foreign entity or government.
There are set to be carve-outs for Five Eyes nations, which include the United States, United Kingdom, New Zealand and Canada.
Mr Marles said the legislation would give Washington and London greater confidence in Australia's commitment to keeping secrets under the AUKUS agreement, through which it will acquire nuclear-propelled submarines.
"The importance of protecting our nation's secrets and sensitive information cannot be overstated," he told parliament.
"The protection of our nation's secrets and sensitive information is central to preserving Australia's national security and to keeping Australians safe."
The defence minister said the new laws were modelled on similar measures in the US, saying it was a critical step towards technology transfers between AUKUS partners.
"(These laws are) not intended to prevent Australians from working overseas or with all foreign governments or militaries," Mr Marles said.
"Rather, our legislative intent is to prevent individuals with knowledge of sensitive defence information from training or working for certain foreign militaries or governments where that activity would put Australia's national security at risk."
Considerations include the type of work and information the person had access to, how long they worked for defence, the type of work they were seeking to do and what country it would be for.
The new rules will not apply if the work involves providing aid or humanitarian assistance to other countries or working in an official capacity for the United Nations or Red Cross.
The Safeguarding Australia's Military Secrets bill was born from a defence investigation into allegations China was headhunting Western military pilots.
The inquiry's findings have been kept secret but legislative change to strengthen national security laws was recommended.
The bill will be referred to the parliamentary intelligence and security committee to conduct private and public hearings.