Runtime: Impersonation

Created on 10 Apr 2018  路  6Comments  路  Source: dotnet/runtime

I need to do a impersonation in one of my services, but this service will run on a linux container.

In windows i use like that
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]

I could not find any reference do this situation, could you have example of that?

area-System.Security

All 6 comments

Related/duplicate of https://github.com/dotnet/corefx/issues/3187. Based on @eerhardt's suggestion there, try:

c# [DllImport ("libc", SetLastError=true)] public static extern int seteuid (uint euid)

corefx is using setuid in some places:
https://github.com/dotnet/corefx/blob/5608a9f41a65d4ea665f9253768db606453bee95/src/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Unix.cs#L197

Duplicate of dotnet/runtime#15177

Instead of using [DllImport("libc"), I would recommend using the Mono.Posix.NETStandard package. It takes care of the interop for you, and has some good wrapper/helper APIs over top of the metal POSIX APIs.

Another related issue that has been resolved in .NET Core 2.1 is https://github.com/dotnet/corefx/issues/26268. You can start a new process as a different user on Unix (assuming the calling process has permission to run the process as a different user).

@eerhardt, thanks for mentioning Mono.POSIX! I was thinking about suggesting [DllImport("System.Native") from runtime directory, as it is always present where dotnet-cli's sdk directory, but Mono.POSIX package would a better choice.

[DllImport("System.Native") is even less recommended than [DllImport("libc"). It is actually strongly suggested to never do this. The System.*.Native assemblies in corefx are not for public consumption. Their APIs are not stable and they can change just like any internal or private method.

Tks a lot guys, i will test it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chunseoklee picture chunseoklee  路  3Comments

Timovzl picture Timovzl  路  3Comments

jamesqo picture jamesqo  路  3Comments

btecu picture btecu  路  3Comments

v0l picture v0l  路  3Comments