In many countries that is done based on laws describing career progression process.
In Germany most administration workers are "career" folks, who study at the university of administration and then have a career paths, where levels at are relatively clearly described. Only heads of different authorities are "political" positions, which are nominated by ministers and can be fired/retired relatively easily but even those in most cases stay across administrations. Only ministers and their direct staff change.
In some ministries there sometimes is the saying "we don't care who is minoster below us" but if a some minister with an agenda is appointed they still can be very effective.