It would be quicker to say when the British were not partly or wholly the government of Afghanistan or Pakistan.
Afghanistan 1919 - 2001. and 2014 to date. The rest of the time including pre 1919 the British were wholly or partly the government of Afghanistan. Law and Government was wholly or partly imposed by the British.
Pakistan Pre 1843, Post 1947. The times between 1843 and 1947 Pakistan was wholly a British Colony, law and government was wholly imposed by the British.
To be in the UK government you must be either a British citizen, or a citizen of the Irish Republic, or a citizen of one of the Commonwealth countries with an appropriate permission to remain indefinitely.
Some roles in the government are reserved strictly for UK Nationals.