runtime icon indicating copy to clipboard operation
runtime copied to clipboard

AccountManagement Context.cs

Open nzcoward opened this issue 9 years ago • 8 comments

In the AccountManagement namespace I am unable to create a PrincipalContext with no password. This is useful for situations where we're using a gMSA or MSA. PrincipalContext throws an exception in the constructor.

With DirectoryEntry, I am able to do so:

var entry = new DirectoryEntry(userDistinguishedName, WindowsIdentity.GetCurrent().Name, null)

Note, this isn't just corefx - it's also in the .NET 4 (v4.0.30319) version.

nzcoward avatar Feb 07 '17 13:02 nzcoward

CoreFX does not expose DirectoryServices namespace yet (it's only work in progress).

We do not track "full" .NET Framework bugs on GitHub, please see CoreFX main page for .NET Framework bugs guidance.

karelz avatar Feb 07 '17 16:02 karelz

Sure, but is it a bug or feature-request? It's an API shortfall, that I think corefx might look to resolve - I don't think it's something for the full framework (except perhaps for parity, and assuming the two frameworks don't share the assembly in the future), but moving forward, it would be good to have. Is there a way to register this against a work in progress?

nzcoward avatar Feb 09 '17 19:02 nzcoward

Fair point - I let @tquerec to triage the issue from long-term DirectoryServices in CoreFX point of view.

karelz avatar Feb 09 '17 20:02 karelz

@nzcoward, is there a reason you can't use the PrincipalContext constructors which don't take a username and password. For example, https://msdn.microsoft.com/en-us/library/bb339842(v=vs.110).aspx

tquerec avatar Apr 06 '17 17:04 tquerec

I'm using a gMSA to authenticate in order to create/modify entries. If there's a way of using that account in the context, then sure. If you've got thoughts on how I may go about that, let me know.

The thing is, there's clearly a check for an empty password with a throw, but you don't need a password for a network credential (?) Some sort of overload to circumvent the check would be the ideal.

On 6 Apr 2017 6:38 pm, "Travis Querec" [email protected] wrote:

@nzcoward https://github.com/nzcoward, is there a reason you can't use the PrincipalContext constructors which don't take a username and password. For example, https://msdn.microsoft.com/en-us/library/bb339842(v=vs.110). aspx

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dotnet/corefx/issues/15902#issuecomment-292250809, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ-lD8nNh4u4xWkqvkbRZFYNrubGXrTIks5rtSMDgaJpZM4L5d_P .

nzcoward avatar Apr 06 '17 18:04 nzcoward

The PrincipalContext constructors which don't accept a username or password will use the security context of the current thread.

For example, PrincipalContext pctx = new PrincipalContext(ContextType.Domain, "MyDomain");

This will connect to "MyDomain" using the current thread's security principal. This should work properly for GMSAs and MSAs.

tquerec avatar Apr 06 '17 18:04 tquerec

Sure, I'm running it in IIS so the context is the interactive user, which is either anon or their windows account.

I'm running the app pool as the MSA, which I'm not overly happy about, but it is very locked down. But it means I have to manually pull the account details (name). If I could use the app pool context in the principal context...

On 6 Apr 2017 7:24 pm, "Travis Querec" [email protected] wrote:

The PrincipalContext constructors which don't accept a username or password will use the security context of the current thread.

For example, PrincipalContext pctx = new PrincipalContext(ContextType.Domain, "MyDomain");

This will connect to "MyDomain" using the current thread's security principal. This should work properly for GMSAs and MSAs.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dotnet/corefx/issues/15902#issuecomment-292263941, or mute the thread https://github.com/notifications/unsubscribe-auth/AJ-lDzi_FYR6Wqj0UrDEGHcZPfEBH83Qks5rtS28gaJpZM4L5d_P .

nzcoward avatar Apr 06 '17 19:04 nzcoward

To summarize, PrincipalContext provides two models for authentication. You need to either provide a username and password or execute the thread in the appropriate security context and don't pass any account information. Trying to use an account by just specifying a username without providing credentials is not supported. It seems like you have some constraints in your system you need to design around. The best place to get this sorted out is through support or connect. I'm going to close this issue as it's not a bug or a design gap in this API.

tquerec avatar Apr 06 '17 20:04 tquerec