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

Avoid exception when parsing AD path for port number #109977

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

steveharter
Copy link
Member

@steveharter steveharter commented Nov 19, 2024

Fixes #109858

This will need to be ported to v9

We don't have automated tests for this; can @kumarravik78c or @jay98014 verify.

Regression in v9 from #89787

@kumarravik78c
Copy link
Member

@steveharter no we do not have any test around this code.

Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the original PR regressed I wanted to give a bit more scrutiny. @kumarravik78c or @jay98014 Can you please have a look at my comments and let me know what you think? We need you expertise here. Thanks!


string dnsDomainName = "";

using (DirectoryEntry rootDse = new DirectoryEntry("LDAP://" + this.dnsHostName + ":" + port + "/rootDse", "", "", AuthenticationTypes.Anonymous))
using (DirectoryEntry rootDse = new DirectoryEntry($"LDAP://{this.dnsHostName}:{port}/rootDse", "", "", AuthenticationTypes.Anonymous))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it wasn't a reported problem, but double checking we are OK to add the default port values here when not specified by the user? Was that an important part of the original fix?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this code only interacts with a dc it is safe to use default ports, ie., 389 for regular LDAP and 636 for secure version of it.

{
port = ldapUri.Port;
}
else if (string.Equals(ldapUri.Scheme, "LDAPS", StringComparison.OrdinalIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another issue from the original PR - it seems odd to me that we ignore this scheme and instead use LDAP below with a port. Do you know if that's intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. should we use "LDAPS://" below when ldapUri.Scheme == "LDAPS"? Would the connection bel secure \ encrypted just because it's on the LDAPS port even though "LDAP://" is used?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been like this from day one. After digging a little deeper and talking with my team, I found out that LDAPS is not valid provider name supported. Hence it uses LDAP as the supported provider name. This allows the user to call the api with LDAPS and the api in turn uses the ssl port(636) along with the supported provider name which LDAP. This is a less strict way to call the api and allow ssl port. Other way would not allow LDAPS at all which might break a lot of applications.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth a comment?

@steveharter
Copy link
Member Author

PTAL @JasonDebug

Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the additional information, @kumarravik78c

@steveharter steveharter merged commit 0b87acc into dotnet:main Nov 22, 2024
83 checks passed
@steveharter steveharter deleted the Issue_109858 branch November 22, 2024 15:30
@steveharter
Copy link
Member Author

/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/12053724457

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants