Get push API key from environment variable #12539
Labels
Area:Authentication
Area:Settings
NuGet.Config and related issues
Functionality:Push
Priority:2
Issues for the current backlog.
Type:Feature
NuGet Product(s) Involved
dotnet.exe
The Elevator Pitch
When someone wants to push a package, particularly in a CI or deployment script, they don't want secrets like API keys to be used on the command line or output to logs. At the time of writing this feature request, the dotnet CLI doesn't have an equivalent of
setapikey
, but even if it did, it would require the API key to be passed on the command line. Additionally, API keys currently can only be encrypted, and dur to NuGet using .NET's ProtectedData API, which is Windows only, it also means that this doesn't work on Linux or Mac.While we have issues for all the above limitations, I believe the need for most of those other work items will be significantly reduced if
push
itself could read the API key from an environment variable. Since API key is only used for push, not restore or other actions, there often isn't a benefit (at least in a CI script) to store the apikey in a nuget.config file. So, we can eliminate one extra step from customer's scripts if push can read the environment variable directly.Proposal: Add a `--use--environment-variable` argument to `dotnet nuget push`, which when used will treat the values provided to `--api-key` and `--symbol-api-key` as envionrment variable names, rather than as the secret values.Therefore, an example usage would be:
Thanks to @AraHaan for the better idea below:
Push should prefer
--api-key
and--symbol-api-key
, if provided. If not provided, try to get a saved API key from nuget.config (all of this is existing behaviour). Finally, if an API key is still not found, get the environment variableNUGET_API_KEY
andNUGET_SYMBOL_API_KEY
.Additional Context and Details
Relevant other issues:
The text was updated successfully, but these errors were encountered: