Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables in setapikey #7145

Open
CJHarmath opened this issue Jul 25, 2018 · 4 comments
Open

Environment variables in setapikey #7145

CJHarmath opened this issue Jul 25, 2018 · 4 comments
Labels
Area:Settings NuGet.Config and related issues Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Status:Excluded from icebox cleanup Status:Inactive Icebox issues not updated for a specific long time Type:Feature
Milestone

Comments

@CJHarmath
Copy link

Details about Problem

NuGet product used: NuGet.exe
NuGet version 4.6.2.5055

When using an environment variable with setapikey, it's not getting evaluated during set or during push.

Use case

Use case is kind of weird, but here it goes:
We have a custom Nuget Server implementation which emails the Kerberos authenticated user as the package pusher which works great when humans use it.
But when the CI server running as a service account is pushing then you can only see the CI server's account as the authenticated user and I got a request to try to include the git committer as well.

To workaround this, I've hijacked the API Key (as haven't seen any other ways to add a custom header to nuget push) to include the git author which is injected as an env var on my Jenkins instance.
So it looks something like this:
nuget push *.nupkg -source MyNugetServer -apiKey OnBehalfOf:%gitlabUserEmail%

And on the server side, I just check the X-NuGet-ApiKey if it has the on behalf of.
The actual auth(z) is done via Kerberos / AD group membership, so the API key is ignored otherwise.

Based on the docs here I wasn't sure if it's supported or not, but it seems like it's not working, so just wanted to clarify if this something which would make sense to support ?
Or if you guys have a better idea to pass some extra header with nuget.exe push ? ( which TBH would be a more elegant solution )

Detailed repro steps so we can see the same problem

  1. PS> $env:NugetApiKey = "12345"
  2. nuget setapikey "%NugetApiKey%" -source test
  3. nuget push *.nupkg -source test

Result: API key is passed in as "%NugetApiKey%" instead of 12345

Thanks for checking!

@zhili1208 zhili1208 added Priority:2 Issues for the current backlog. Area:Settings NuGet.Config and related issues labels Jul 25, 2018
@zhili1208 zhili1208 added this to the Backlog milestone Jul 25, 2018
@nkolev92
Copy link
Member

It's not supported currently.
The nuget api key would need to be associated with a source however so it can't be as simple as the above.

@CJHarmath
Copy link
Author

Thanks @nkolev92 for checking!
I figured it's not supported right now as the value seems to be encrypted in the config after calling setapikey.

A more generalized way to pass extra information from nuget.exe to a nuget service could be allowing custom headers to be passed in via command line args or config per source.
Similarly to the X-NuGet-ApiKey.

For example:
nuget push *.nupkg -source test -header "X-NuGet-OnBehalfOf:joe"

Allowing use cases such as a CI server adding a header with the git commit author, etc.

Thanks

@nkolev92
Copy link
Member

nkolev92 commented Jul 31, 2018

Related to what you are articulating.
#6574

That issue talks about a plugin that can add params to the http requests.

@CJHarmath
Copy link
Author

yeah, something like that could also be surfaced as a command line arg / config attribute per source.
Being able to use environment variables as header values per source would be an extra nice touch for the CI server use-case as for example Jenkins already sets a bunch of GIT releated env vars.

@ghost ghost added the Status:Inactive Icebox issues not updated for a specific long time label Sep 1, 2022
@nkolev92 nkolev92 added Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. and removed Priority:2 Issues for the current backlog. labels Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:Settings NuGet.Config and related issues Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Status:Excluded from icebox cleanup Status:Inactive Icebox issues not updated for a specific long time Type:Feature
Projects
None yet
Development

No branches or pull requests

5 participants