I wonder who was the highest ranking government official working knowingly and clandestinely for a foreign government.

Two nominations are possible:

Traitors
--------

A citizen of country X working officially for the government of X but secretly spying for country Y. Examples:

* [Cambridge Five](http://en.wikipedia.org/wiki/Cambridge_Five)
* [Aldrich Ames](http://en.wikipedia.org/wiki/Aldrich_Ames)
* [Robert Hanssen](http://en.wikipedia.org/wiki/Robert_Hanssen)
* [Oleg Penkovsky](http://en.wikipedia.org/wiki/Oleg_Penkovsky)

Note that [Marshal Beria](http://en.wikipedia.org/wiki/Lavrentiy_Beria), executed as a British spy, is, obviously, *not* an acceptable example here. :-)

Infiltrators
------------

A citizen of country Y working for the intelligence services of country Y, also working for the government of country X under an assumed name. Examples:

* [Stierlitz](https://en.wikipedia.org/wiki/Stierlitz) - fictional
* ???