ci: publish to NuGet via Trusted Publishing, not a long-lived key - #197
Conversation
The publish job passed a NUGET_API_KEY repository secret to cake. It now exchanges the GitHub OIDC token for a key valid ~1 hour (NuGet/login v1.2.0) and passes that instead — cake neither knows nor cares that the key is short-lived, it just receives one through --nuget-key, so build.cake is unchanged. The only remaining secret is NUGET_USER, the nuget.org profile name. The job gains an explicit minimal permissions block: build.cake's Publish-NuGet target only pushes to nuget.org, so contents: read plus id-token: write is all it needs. --github-key is dropped in the same change: build.cake reads only 'nuget-key', so it was handing GITHUB_TOKEN to a script that never asked for it.
Up to standards ✅🟢 Issues
|
|
Important Bloquée : ne pas merger tant que la politique nuget.org n'est pas déclarée. Cette PR est verte, et son code est bon. Elle casserait quand même la prochaine release, silencieusement. Pourquoi la CI ne peut pas le voir. L'étape de login est gardée par Ordre impératif pour débloquer (l'inverse laisse sans retour arrière) :
Table des 7 politiques à déclarer : Passée en brouillon exprès, pour qu'elle ne ressorte pas comme « verte et mergeable » dans le tableau de bord. |
|
Les deux prérequis de cette PR sont faits (2026-07-27).
Vérifié : Il ne reste que l'étape 3 : une release réelle, vérifier que le paquet apparaît, puis supprimer Procédure complète : |
The publish job handed a long-lived
NUGET_API_KEYto cake. It now uses Trusted Publishing: the GitHub OIDC token is exchanged for a NuGet key valid ~1 hour and that is passed through--nuget-keyinstead. The only remaining secret isNUGET_USER— the nuget.org profile name, not a credential.build.cakeis unchanged. Cake neither knows nor cares that the key is short-lived; it just receives one. That is what makes this migration cheap for tool-driven builds.Two findings while reading the publish path
--github-keywas dead.build.cakereads onlynuget-key—--github-key=${{ secrets.GITHUB_TOKEN }}was handing a token to a script that never asked for it. Dropped in this change.The job had no
permissionsblock at all, so it ran on repository defaults. It now declares the minimum:contents: read+id-token: write. I checkedPublish-NuGetbefore narrowing it — it only pushes to nuget.org, so nothing needs write access. (Its inline comment says "Publish to GitHub Packages" but the source isapi.nuget.org; stale comment, left alone as out of scope.)Required before the next release
MasterCommander, namingphmatray/MasterCommanderandpublish.yml.NUGET_USERsecret.NUGET_API_KEY.