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

[DRAFT] [Issue 305] Introduce a hook in Microsoft.Data.SqlClient to allow different mechanisms to acquire a Kerberos ticket #1379

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

srdan-bozovic-msft
Copy link

No description provided.

@dnfadmin
Copy link

dnfadmin commented Nov 8, 2021

CLA assistant check
All CLA requirements met.

@srdan-bozovic-msft
Copy link
Author

resolves #305

@@ -135,6 +138,9 @@ sealed internal class SqlInternalConnectionTds : SqlInternalConnection, IDisposa
SqlFedAuthToken _fedAuthToken = null;
internal byte[] _accessTokenInBytes;

// Kerberos ticket provided by OnRetrieveKerberosTicket
internal byte[] _kerberosTicketInBytes;
Copy link
Contributor

Choose a reason for hiding this comment

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

I realise that this follow the naming convention from the line above, the same logic will apply to that field as well if someone added it today.
Do we need the InBytes suffix? Do we have any other form of the same data (string etc) that is used? If not then it could just be called _kerberosTicket

Copy link
Author

Choose a reason for hiding this comment

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

Agree with the comment. As you've noticed correctly the idea was to follow the established convention. Team may consider name refactoring.

string instanceName = null;

// ReadOnlySpan is not supported in netstandard 2.0, but installing System.Memory solves the issue
ReadOnlySpan<char> input = dataSource.AsSpan().TrimStart();
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for using spans, almost always better for perf 😁

Copy link
Author

Choose a reason for hiding this comment

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

This is c/p of a class from netcore path. This needs some refactoring and unification as it's useful for both necore and netfx.


private bool InferConnectionDetails()
{
string[] tokensByCommaAndSlash = _dataSourceAfterTrimmingProtocol.Split(BackSlashCharacter, CommaSeparator);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this use span to avoid the string and array allocations? We had some interesting back and forth on using spans while parsing in #1237 that might be useful to review.

Copy link
Author

Choose a reason for hiding this comment

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

It's definitely worth exploring. Everything said above applies.

/// A callback to provide kerberos ticket for given service principal name (SPN) on demand.
/// </summary>
/// <returns></returns>
public delegate byte[] KerberosTicketRetrievalCallback(string serverPrincipalName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be a new type, or is there a reason to use a type over a Func<byte[],string> ?

I'm also no sure about the naming. Is it really a callback? it feels more like a provider or an adapter. The user will set the this property of the connection to and it will be called by the connection to get the ticket to use. So we're not really calling back to anything instead we're providing a way to get an external value by some means. KerberosTicketProvider ? something like that?

Copy link
Author

Choose a reason for hiding this comment

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

This follows conventions for this library ( https://github.com/dotnet/SqlClient/search?q=callback ). Team is also exploring changing this into adapter pattern design already used in FedAuth flow.

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.

3 participants