feat(mssql): auto-derive Kerberos realm for cross-realm Windows Authentication#1949
feat(mssql): auto-derive Kerberos realm for cross-realm Windows Authentication#1949Seha16 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3dccf687a5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| let display = String(data: Data(bytes: value, count: displayBuffer.length), encoding: .utf8) ?? "" | ||
| guard let atIndex = display.lastIndex(of: "@") else { return nil } | ||
| let realm = String(display[display.index(after: atIndex)...]) | ||
| return realm.isEmpty ? nil : realm |
There was a problem hiding this comment.
Preserve the canonical host in Kerberos SPNs
When the user enters a short hostname or CNAME, GSS canonicalization can produce the FQDN that has the SQL Server SPN registered, but this resolver discards that canonical host and returns only the realm; the later MSSQLKerberosSPN.build(host: config.host, ...) rebuilds DBSETSERVERPRINCIPAL from the raw form field. Because that SPN is then passed verbatim to FreeTDS, connections that previously relied on FreeTDS/GSS host canonicalization can start requesting MSSQLSvc/alias:port@REALM and fail with S_PRINCIPAL_UNKNOWN. Return/build the canonical service name (or canonical host plus realm) instead of only the realm.
Useful? React with 👍 / 👎.
3dccf68 to
01b0027
Compare
|
Addressed in 01b0027 — the resolver now returns the canonical host + realm, not just the realm:
No behavior change for FQDN inputs; the short-name/alias path no longer regresses to |
Fixes #1947.
Problem
SQL Server Windows Authentication (Kerberos) fails for a server whose Kerberos realm differs from the Mac's
default_realm, even with a valid TGT and a working cross-realm trust. FreeTDS builds an unrealmed SPN (MSSQLSvc/host:port), and macOS Heimdal resolves that string principal againstdefault_realmwith no cross-realm referral — so the KDC returnsKRB5KDC_ERR_S_PRINCIPAL_UNKNOWNand the login is rejected.The JDBC driver (DataGrip) works in the same environment because Java derives the service realm from the hostname via the system
[domain_realm]mapping — not from the URL, and without changingdefault_realm.Change
Make TablePro derive the realm the same way:
MSSQLKerberosRealmResolver(macOS) resolveshost → realmvia GSS name canonicalization, which honors the system[domain_realm]/default_realmconfiguration (the already-linked GSS.framework; no new dependency).MSSQLSvc/host:port@REALM) handed to FreeTDS viaDBSETSERVERPRINCIPAL. FreeTDS usesserver_spnverbatim for the GSS target.default_realmchange required — it just works, matching the JDBC driver. When resolution yields nothing, it falls back to today's unrealmed behavior (no regression).#if os(macOS)-guarded.Also included (surfaced while testing this form):
Testing
MSSQLKerberosSPNTests).default_realm): connections that previously failed withS_PRINCIPAL_UNKNOWNnow authenticate. The FreeTDS protocol dump shows the realm-qualified SPN and GSS completing: