The only Secretary of Defense to require a legal waiver to serve because he had recently been a senior military officer [in fact, a five-star General of the Army] was George C. Marshall. At the time of his nomination, in the early weeks of the Korean War, Congress insisted that the waiver was a one-time action, not a precedent for the future. [We'll see what happens with General Mattis.]
I've dug back into the files about Marshall and came across this story that shows how he handled a very difficult political problem. In September, 1944 Marshall learned that the Republican presidential candidate, New York Governor Thomas Dewey, was planning to charge President Franklin Roosevelt with failing to prevent the Pearl Harbor attack despite warnings provided by breaking Japanese codes. Without clearing his action with Roosevelt, Marshall three times sent a trusted aide to tell Dewey that disclosure of the code-breaking would greatly harm the war effort because the Japanese were still using the same codes, and the allies were relying on them for valuable information on both the war in the Pacific and the war in Europe. He explained the problem in a carefully written letter, pleading with Dewey not to use the information publicly.
Dewey said he already knew what was in the letter and thought that FDR was behind Marshall's letter. But he wisely decided not to make the argument in his campaign, and the story came out only when documents were declassified in 1981.
The incident reconfirmed my view that Marshall -- who refused to vote because he wanted to be able to serve loyally whoever was elected -- was a very politically astute general.