Add gssapi authentication method#513
Open
hb1915 wants to merge 1 commit intostarburstdata:masterfrom
Open
Conversation
Collaborator
|
Please address the conflicts on |
This adds a new `method: gssapi` to dbt-trino's profile schema, backed by
trino-python-client's `GSSAPIAuthentication` class (added upstream in trinodb/
trino-python-client#454). The existing `method: kerberos` continues to work
unchanged; `gssapi` is offered as a parallel option.
Why a new method instead of patching kerberos:
- trino-python-client deliberately ships two separate classes,
`KerberosAuthentication` (uses the older `requests-kerberos`) and
`GSSAPIAuthentication` (uses the modern `requests-gssapi` + `gssapi`
libraries). Mirroring that separation in dbt-trino keeps both paths
available and makes the underlying library choice explicit.
- The two classes have different defaults (e.g. `mutual_authentication`
defaults to REQUIRED in the legacy class and DISABLED in the new one) and
slightly different semantics around credential cache vs keytab.
Practical benefit for users:
- The legacy kerberos method requires a keytab (it always sets
KRB5_CLIENT_KTNAME and crashes if the field is None). The gssapi method
uses gssapi.Credentials, which falls back to the default credential cache
(KRB5CCNAME) when no principal is given. So 'kinit' followed by 'dbt run'
works natively without configuring a keytab.
API choices:
- mutual_authentication is exposed as a case-insensitive string
("REQUIRED" | "OPTIONAL" | "DISABLED"), translated to trino-python-
client's integer constants in trino_auth(). Defaults to "DISABLED" to
match the upstream class default. An invalid value raises DbtRuntimeError
with a clear message at connection time.
- All other parameters mirror the existing kerberos method's surface
(principal, krb5_config, service_name, force_preemptive,
hostname_override, sanitize_mutual_error_response, delegate, cert).
Tests:
- Adds three unit tests in tests/unit/test_adapter.py:
- test_gssapi_authentication: full profile happy-path mirroring the
existing kerberos test.
- test_gssapi_authentication_default_mutual_authentication: default
resolves to MUTUAL_DISABLED.
- test_gssapi_authentication_invalid_mutual_authentication: bad string
raises DbtRuntimeError.
Other:
- Updates dbt/include/trino/sample_profiles.yml to list gssapi alongside
the other supported methods in the comment hint.
- Adds a changie Features entry under .changes/unreleased/.
Author
Should be done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
gssapiauthentication methodSummary
This PR adds a new
method: gssapito dbt-trino's profile schema, backed bytrino.auth.GSSAPIAuthentication(introduced upstream in trinodb/trino-python-client#454).The existing
method: kerberosis untouched —gssapiis offered as a parallel option, mirroring the two-class separation that trino-python-client deliberately adopted.Why a new method instead of patching
kerberostrino-python-client ships two distinct authentication classes:
KerberosAuthentication— usesrequests-kerberos(less actively maintained, depends onpykerberos).GSSAPIAuthentication— usesrequests-gssapiplus the moderngssapilibrary.The two classes have different defaults (e.g.
mutual_authenticationdefaults toREQUIREDin the legacy class andDISABLEDin the new one) and different semantics around credential acquisition (legacy is keytab-centric; the new one defers togssapi.Credentials, which uses the default credential cache when no principal is given). Squashing them into one dbt method would hide that distinction; mirroring the upstream split keeps both paths available and makes the underlying library choice explicit.Practical benefit for users
The current
kerberosmethod requires a keytab —connections.pyunconditionally setsKRB5_CLIENT_KTNAMEfrom thekeytabfield, so any value other than a real path causes aTypeError. That forces operators to provision a keytab even when they already have a TGT in their credential cache.The new
gssapimethod has no such requirement. Withprincipalunset (the default),GSSAPIAuthenticationcallsgssapi.Credentials()with no name argument, which falls back to whatever's inKRB5CCNAME. So:just works — no keytab, no extra profile fields beyond
method: gssapi,host,port, anduser.API choices
mutual_authenticationis exposed as a case-insensitive string taking one of"REQUIRED","OPTIONAL","DISABLED", translated internally to trino-python-client's integer constants (MUTUAL_REQUIRED=1,MUTUAL_OPTIONAL=2,MUTUAL_DISABLED=3). Defaults to"DISABLED"to match the upstream class default. An invalid value raisesDbtRuntimeErrorwith a clear message at connection time.Rationale: the existing
kerberosmethod types this asOptional[bool](line 190 ofconnections.py), which can only expressREQUIRED/DISABLEDand silently misbehaves when givenFalse(which becomesint 0, not a value the underlyingrequests_kerberos.HTTPKerberosAuthrecognises). The string-enum API is the dbt-idiomatic way to expose a small set of named choices and avoids that footgun.All other parameters mirror the existing kerberos method's surface:
principal,krb5_config,service_name,force_preemptive,hostname_override,sanitize_mutual_error_response,delegate,cert.Example profile
Tests
Three unit tests added in
tests/unit/test_adapter.py:test_gssapi_authentication— full profile happy-path, mirrors the existing kerberos test.test_gssapi_authentication_default_mutual_authentication— default value resolves toMUTUAL_DISABLED.test_gssapi_authentication_invalid_mutual_authentication— bad string raisesDbtRuntimeError.I haven't added a docker-compose-based integration test because the existing kerberos integration test fixtures are scoped to the legacy library; happy to add
gssapi-side fixtures in a follow-up if you'd like.Out of scope (deliberately)
Two pre-existing bugs in
TrinoKerberosCredentialswere noted during this work but are not changed here, to keep this PR focused:mutual_authentication: Optional[bool] = False— wrong type; can't expressOPTIONAL. Same string-enum fix would apply.os.environ["KRB5_CLIENT_KTNAME"] = self.keytabcrashes whenkeytabisNonedespite the field being typedOptional[str].Happy to follow up with a separate PR for these if you'd prefer them addressed; or if you'd rather have them bundled here, let me know and I'll amend.
Checklist
README.mdupdated and added information about my change (no Kerberos-specific section currently exists; the canonical docs live at docs.getdbt.com/reference/warehouse-setups/trino-setup — happy to file a companion PR to dbt-labs/docs.getdbt.com once this lands)changie newto create a changelog entry