Are Jews allowed to work for the government?

שְׁמַעְיָה אוֹמֵר, אֱהֹב אֶת הַמְּלָאכָה, וּשְׂנָא אֶת הָרַבָּנוּת, וְאַל תִּתְוַדַּע לָרָשׁוּת:

Shemayah says, "Love work, hate authority over others and do not become familiar with the government."

(ג) הֱווּ זְהִירִין בָּרָשׁוּת, שֶׁאֵין מְקָרְבִין לוֹ לָאָדָם אֶלָּא לְצֹרֶךְ עַצְמָן. נִרְאִין כְּאוֹהֲבִין בִּשְׁעַת הֲנָאָתָן, וְאֵין עוֹמְדִין לוֹ לָאָדָם בִּשְׁעַת דָּחְקוֹ:

(3) Be careful about the government, as they approach a man only when they need him. They seem like good friends in good times, but they don't stay for him in time of his trouble.

דרך חיים ב׳:ג׳:א׳

(א) ואמר הוו זהירין ברשות, לפי שאמר שיהיו עוסקים עם הצבור, אמר אחר זה הוו זהירין ברשות, כי הרשות הוא הפך הצבור כי בעל שררה מפני חשיבתו וגדולתו הוא מוציא עצמו מן הצבור רק נבדל מהם, כמו שהוא דרך כל בעל שררה אף שהוא רוצה להנהיג את הצבור כאלו היה עוסק בצרכי הצבור, אבל אין הדבר כך. ... ונראה עוד כי סמך אלו ב' דברים דהיינו וכל העוסקים עם הצבור וכו' הוו זהירין ברשות, מפני שבא לומר שיש לאדם להשתדל בטובת הצבור בכל מאמצי כחו מה שאפשר לו לעשות, והנה נמצא בני אדם רוצים להחניף ולהנות את השררה ונותנים עצה אל השררה נגד הצבור כדי למצא חן בעיני השררה כדי שיקבלו מהם הנאה, על זה אמר הוו זהירין ברשות רצה לומר שאין מקרבין את האדם רק לפי הנאתן

Derech Chaim On P"A 3:2

The statement "be careful of the government" was said by [Rabban Shimon Ben Gamliel] who also says that, "one should work on behalf of the public" because the government is the opposite of the public. A person with power excludes themselves from the public and becomes separate from them on account of their importance and might. Such is the way the way of every person with power; they act as if they govern the public in order to fulfill the public's needs', but that is not really the case... It appears that these two statement were juxtaposed ("be careful of the government, and "one should work on behalf on the public" in order to tell us that one should strive for the good of the public with all of his strength in any way he can. However, (those dealing with the government) want to flatter and benefit the ones in power. They give advice to the rulers that are against the interests of the public so that those in power will be pleased and (the flatterers) will receive receive benefit (from their closeness to power).

...ואלו שלש מדות יש בהן תיקון האמונה ובבקשת השררה והרבנות יארעו לו נסיונות בעולם ורעות כי מפני שיקנאו בו בני אדם ויחלקו עליו יפסיד אמונתו כמו שאמרו כיון שנתמנה אדם פרנס על הצבור מלמטה נעשה רשע מלמעלה. וכן ידיעת השלטון בימים הקדמונים וקרבתו רחוק היה מאד להנצל ממנה בעולם הזה והיא מפסדת אמונתו כי לא ישגיח בדבר רק במה שיקרבהו אליו...

...Through these three traits (mentioned in the first Mishnah) one achieves a refinement of faith. For when one seeks power and positions of authority he will end up with trails and travails. For people will be jealous of him and will create disputes with him. Therefore, he will lose his faith. This is what the sages meant (in the Talmud when) they said, "When someone is appointed a communal leader for the public in the lower world, he becomes (considered) a wicked person in the upper world (i.e. heaven)".

And in regards to becoming familiar with the government in days of old and becoming close to it, it was very hard to extract himself (from being close to the government) and this would cause him to lose faith, for he would only care about that which brought him closer to it.

(ד) כֹּ֥ה אָמַ֛ר ה' צְבָא֖וֹת אֱלֹקֵ֣י יִשְׂרָאֵ֑ל לְכָל־הַ֨גּוֹלָ֔ה אֲשֶׁר־הִגְלֵ֥יתִי מִירוּשָׁלִַ֖ם בָּבֶֽלָה׃ (ה) בְּנ֥וּ בָתִּ֖ים וְשֵׁ֑בוּ וְנִטְע֣וּ גַנּ֔וֹת וְאִכְל֖וּ אֶת־פִּרְיָֽן׃ (ו) קְח֣וּ נָשִׁ֗ים וְהוֹלִידוּ֮ בָּנִ֣ים וּבָנוֹת֒ וּקְח֨וּ לִבְנֵיכֶ֜ם נָשִׁ֗ים וְאֶת־בְּנֽוֹתֵיכֶם֙ תְּנ֣וּ לַֽאֲנָשִׁ֔ים וְתֵלַ֖דְנָה בָּנִ֣ים וּבָנ֑וֹת וּרְבוּ־שָׁ֖ם וְאַל־תִּמְעָֽטוּ׃ (ז) וְדִרְשׁ֞וּ אֶת־שְׁל֣וֹם הָעִ֗יר אֲשֶׁ֨ר הִגְלֵ֤יתִי אֶתְכֶם֙ שָׁ֔מָּה וְהִתְפַּֽלְל֥וּ בַעֲדָ֖הּ אֶל־ה' כִּ֣י בִשְׁלוֹמָ֔הּ יִהְיֶ֥ה לָכֶ֖ם שָׁלֽוֹם׃ (פ)

(4) Thus said the LORD of Hosts, the God of Israel, to the whole community which I exiled from Jerusalem to Babylon: (5) Build houses and live in them, plant gardens and eat their fruit. (6) Take wives and beget sons and daughters; and take wives for your sons, and give your daughters to husbands, that they may bear sons and daughters. Multiply there, do not decrease. (7) And seek the welfare of the city to which I have exiled you and pray to the LORD in its behalf; for in its prosperity you shall prosper.

(ב) רַבִּי חֲנִינָא סְגַן הַכֹּהֲנִים אוֹמֵר, הֱוֵי מִתְפַּלֵּל בִּשְׁלוֹמָהּ שֶׁל מַלְכוּת, שֶׁאִלְמָלֵא מוֹרָאָהּ, אִישׁ אֶת רֵעֵהוּ חַיִּים בְּלָעוֹ.

(2) Rabbi Chanina, the Deputy High Priest, says: Pray for the welfare of the government, for were it not for the fear of it, man would swallow his fellow alive.

אגרות צפון ט״ז:ד׳

(ד) הרדיפה וההגבלה בדרך החיים אינן בעצם תנאי הגלות, ונהפוך הוא, חוב מוטל עלינו לפי היכולת, להאחז במדינה אשר תקבל אותנו לגור בה; להשתדל להוציא לפועל את מטרת המדינה ותועלתה, ובדרשנו את טובת עצמנו, עלינו לדרוש גם את שלומה וטובתה.

Nineteen Letters 16:4

(4) To be pushed back and limited upon the path of life is, therefore, not an essential condition of the exile, but, on the contrary, it is our duty to join ourselves as closely as possible to the state which receives us into its midst, to promote its welfare and not to consider our well-being as in any way separate from that of the state to which we belong.

(ג) דרך חכמים הראשונים בורחים מלהתמנות ודוחקים עצמם הרבה שלא לישב בדין עד שידעו שאין שם ראוי כמוהו ושאם ימנעו עצמם מהדין תתקלקל השורה ואעפ"כ לא היו יושבים בדין עד שהיו מכבידים עליהם העם והזקינים ומפצירים בם:

The way of the sages of yore was to shun being appointed to office and they would press themselves not to act as a judge in a court case unless they knew that there was no else who was as suitable as they. For if they were to prevent themselves from judging (the court case), the structure (of society) would break down. And nevertheless, they would not act as a judge until the (Jewish) people and elders would pressure and implore them (to judge).