-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
WindowsIdentity.RunImpersonatedAsync sending wrong credentials #63136
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionHi! This issue is the continuation of issue #58033. I've made a sample project to reproduce the error https://github.com/daniilzaonegin/ImpersonationTest. var result = await WindowsIdentity.RunImpersonatedAsync(windowsIdentity.AccessToken,
async () =>
{
HttpClient? client =
_clientFactory.CreateClient(ServiceConsts.ImpersonateClientName);
var result = await client.GetAsync("http://localhost:5246/api/User");
return await result.Content.ReadAsStringAsync();
}); Reproduction StepsTo reproduce. Clone and run https://github.com/daniilzaonegin/ImpersonationTest:
If you disable connection pooling, when adding HttpClient (PooledConnectionLifetime = TimeSpan.Zero), then everything works as expected: builder.Services.AddHttpClient(ServiceConsts.ImpersonateClientName)
.ConfigurePrimaryHttpMessageHandler(_ =>
new SocketsHttpHandler()
{
UseProxy = false,
Credentials = CredentialCache.DefaultCredentials,
PreAuthenticate = false,
PooledConnectionLifetime = TimeSpan.Zero
}); Expected behaviorWindowsIdentity.RunImpersonatedAsync should use credentials of the user, that is calling api right now, not the credentials of a previous api call. Actual behaviorWindowsIdentity.RunImpersonatedAsync reuses the credentials of a previous api call. Regression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
@wfurt can you take a look? |
sure. I'm not sure how Kestrel and factory plays into this but having specific example should be sufficient to see what is going on. |
I could not get the demo working. It is failing with
This is not my area and perhaps @Tratcher would have some insight. I modified it to use Negotiate scheme: With that I can access the UserRightsDelegating url and based on the user I pass in I get
or
e.g. the response content does respect the used user for first service. (I did not change the timeout) |
This issue has been marked |
@wfurt, this solution works only on IIS/IIS Express. I had an issue on IIS and posted same code that is used in our application. So when you run it from visual studio 2022 on IIS Express, there will be no errors. |
I tested it with |
Good to know. I have no experience with Postman. I tried it, but eventually fall-back to tools I'm familiar with. |
Description
Hi!
This issue is the continuation of issue #58033.
I've made a sample project to reproduce the error https://github.com/daniilzaonegin/ImpersonationTest.
WindowsIdentity.RunImpersonatedAsync reuses the credentials of previous api call.
Reproduction Steps
To reproduce. Clone and run https://github.com/daniilzaonegin/ImpersonationTest:
If you disable connection pooling, when adding HttpClient (PooledConnectionLifetime = TimeSpan.Zero), then everything works as expected:
Expected behavior
WindowsIdentity.RunImpersonatedAsync should use credentials of the user, that is calling api right now, not the credentials of a previous api call.
Actual behavior
WindowsIdentity.RunImpersonatedAsync reuses the credentials of a previous api call.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: