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

GSSAPI support on Windows, attempt 1 #95

Closed
wants to merge 4 commits into from
Closed

GSSAPI support on Windows, attempt 1 #95

wants to merge 4 commits into from

Conversation

fluggo
Copy link

@fluggo fluggo commented Nov 12, 2013

These patches add GSSAPI support on Windows, allow the connection string builder to get the user's Active Directory username in the proper case (and with optional realm), and close a security hole with regards to connection pooling and integrated security.

Guessing the user's Active Directory name requires an additional reference to to the System.DirectoryServices.AccountManagement library, but from what I can tell, Mono supports this library. If that's a deal breaker, the 23a931d commit can be omitted, but 26195b5 is critical.

Brian Crowell added 4 commits November 12, 2013 11:26
The NpgsqlPasswordPacket class assumes that it needs to null-terminate all
passwords that come through, but GSSAPI and SSPI send binary data. I move
the null-termination logic up to the state class, where it can decide
whether a password needs to be null-terminated.
For a Windows client to connect to a Linux-hosted PostgreSQL, it needs to
support GSSAPI. Fortunately, that just requires two changes:

* Use the hostname in the SPN
* Ask for the "kerberos" package instead of "negotiate"
…rated auth

When PostgreSQL receives our username, it will expect the case to match
Active Directory. For us to guess it correctly requires a lookup into
Active Directory. .NET makes that easy; I don't know how well this ports
to Mono.

While I'm here, I'm also adding an "IncludeRealm" option to the connection
string to add the realm to the username if the include_realm option is
being used on the server side.

WARNING: There's a serious bug here where one user could get access to
another user's cached connection is connection pooling is on and integrated
security is being used. This is because the user ID is not in the
connection string until the connection is opened, which is after any
pooling logic. I'll address this in the next patch.
…d security

When connection pooling is turned on, connections are cached by connection
string. But when integrated security is turned on, the user's identity
isn't part of the connection string, so two users can get each other's
connections back from the connection pool.

This patch forces the username to appear in the connection string if
integrated security is on, before any pooling takes place.
@franciscojunior
Copy link
Member

Hi, Brian!!

Would you mind to rebase your pull request?
I merged #85 which brought a lot of performance improvements but also introduced some conflicting changes.

Also, Npgsql needs to be compatible with .net 2.0. And we got this error when compiling your pr with .net 2.0:

Npgsql\NpgsqlConnectionStringBuilder.cs(34, 14): error CS0234: The type or namespace name 'DirectoryServices' does not exist in the namespace 'System' (are you missing an assembly reference?)
Project src\Npgsql.csproj failed.

Thanks in advance.

@fluggo
Copy link
Author

fluggo commented Nov 15, 2013

That error-- the assembly for System.DirectoryServices.AccountManagement unfortunately was introduced in .NET 3.5. I'm going to have to go back and rewrite that with lower-level code.

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

Successfully merging this pull request may close these issues.

None yet

2 participants