denisenkom / go-mssqldb

Microsoft SQL server driver written in go language
BSD 3-Clause "New" or "Revised" License
1.81k stars 493 forks source link

Export auth interface to allow external implementations e.g. krb5 #718

Closed PeteBassettBet365 closed 2 years ago

PeteBassettBet365 commented 2 years ago

The original driver auth interface and implementations have been moved into their own packages and exported. There are two implementations within the driver, NTLM and Windows SSPI. As before the default on windows is the winsspi package and NTLM on Linux.

The consuming application can now override this at runtime by calling mssql.SetIntegratedAuthenticationProvider(authProvider) e.g.

// create a new auth.Provider around the kerberos client
provider := krb5.NewAuthProvider(krbClient)

// pass the provider to mssql to override the default authentication mechanism
mssql.SetIntegratedAuthenticationProvider(provider)

We have created an integratedauth.Provider implementation here https://github.com/bet365/go-mssqldb-auth-krb5 which uses http://github.com/jcmturner/gokrb5 to authenticate with active directory.

This keep the main driver free from the krb5 dependency and opens the possibility for other implementations in future.

If this pull request is accepted we will update our implementation to the main repo master. Currently it is using a replacement to point at a branch.

We are aware of #702 but have been using the go-mssqldb driver in production since last year with this kerberos integration change and wanted to offer an alternative and are happy to discuss approach or changes. Thanks again for the excellent work.

codecov[bot] commented 2 years ago

Codecov Report

Merging #718 (279444b) into master (e538731) will increase coverage by 0.66%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #718      +/-   ##
==========================================
+ Coverage   71.29%   71.96%   +0.66%     
==========================================
  Files          24       25       +1     
  Lines        5386     5250     -136     
==========================================
- Hits         3840     3778      -62     
+ Misses       1301     1228      -73     
+ Partials      245      244       -1     
Impacted Files Coverage Δ
auth.go 100.00% <100.00%> (ø)
auth_windows.go 100.00% <100.00%> (ø)
tds.go 65.13% <100.00%> (-0.73%) :arrow_down:
token.go 63.62% <0.00%> (-0.59%) :arrow_down:
integratedauth/winsspi/winsspi.go

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e538731...279444b. Read the comment docs.