Skip to content

Commit 731a0cc

Browse files
committed
Allow authentication over HTTP
1 parent 1e95bbf commit 731a0cc

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,41 @@ It follows the interface for `KerberosAuthentication`, but is using
365365
)
366366
```
367367

368+
369+
### Insecure authentication
370+
371+
All authentication methods require secure HTTPS channel to the Trino cluster. Although not recommended, you can enable authentication over insecure HTTP channel by using `insecure` connection argument.
372+
373+
- DBAPI
374+
375+
```python
376+
from trino.dbapi import connect
377+
...
378+
379+
conn = connect(
380+
auth=...,
381+
insecure=True,
382+
...
383+
)
384+
```
385+
386+
- SQLAlchemy
387+
388+
```python
389+
from sqlalchemy import create_engine
390+
391+
engine = create_engine("trino://<username>:<password>@<host>:<port>/<catalog>/?insecure=true")
392+
393+
# or as connect_args
394+
engine = create_engine(
395+
"trino://<username>@<host>:<port>/<catalog>",
396+
connect_args={
397+
"auth"=...,
398+
"insecure": True,
399+
}
400+
)
401+
```
402+
368403
## User impersonation
369404

370405
In the case where user who submits the query is not the same as user who authenticates to Trino server (e.g in Superset),

tests/unit/sqlalchemy/test_dialect.py

-10
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def setup_method(self):
5858
catalog="system",
5959
user="user",
6060
auth=BasicAuthentication("user", "pass"),
61-
http_scheme="https",
6261
source="trino-rulez"
6362
),
6463
),
@@ -80,7 +79,6 @@ def setup_method(self):
8079
catalog="system",
8180
user="user",
8281
auth=CertificateAuthentication("/my/path/to/cert", "afdlsdfk%4#'"),
83-
http_scheme="https",
8482
source="trino-sqlalchemy"
8583
),
8684
),
@@ -100,7 +98,6 @@ def setup_method(self):
10098
catalog="system",
10199
user="user",
102100
auth=JWTAuthentication("afdlsdfk%4#'"),
103-
http_scheme="https",
104101
source="trino-sqlalchemy"
105102
),
106103
),
@@ -168,7 +165,6 @@ def setup_method(self):
168165
catalog="system",
169166
user="[email protected]/my_role",
170167
auth=BasicAuthentication("[email protected]/my_role", "pass /*&"),
171-
http_scheme="https",
172168
source="trino-sqlalchemy",
173169
session_properties={"query_max_run_time": "1d"},
174170
http_headers={"trino": 1},
@@ -270,7 +266,6 @@ def test_trino_connection_basic_auth():
270266
url = make_url(f'trino://{username}:{password}@host')
271267
_, cparams = dialect.create_connect_args(url)
272268

273-
assert cparams['http_scheme'] == "https"
274269
assert isinstance(cparams['auth'], BasicAuthentication)
275270
assert cparams['auth']._username == username
276271
assert cparams['auth']._password == password
@@ -282,7 +277,6 @@ def test_trino_connection_jwt_auth():
282277
url = make_url(f'trino://host/?access_token={access_token}')
283278
_, cparams = dialect.create_connect_args(url)
284279

285-
assert cparams['http_scheme'] == "https"
286280
assert isinstance(cparams['auth'], JWTAuthentication)
287281
assert cparams['auth'].token == access_token
288282

@@ -294,7 +288,6 @@ def test_trino_connection_certificate_auth():
294288
url = make_url(f'trino://host/?cert={cert}&key={key}')
295289
_, cparams = dialect.create_connect_args(url)
296290

297-
assert cparams['http_scheme'] == "https"
298291
assert isinstance(cparams['auth'], CertificateAuthentication)
299292
assert cparams['auth']._cert == cert
300293
assert cparams['auth']._key == key
@@ -307,13 +300,11 @@ def test_trino_connection_certificate_auth_cert_and_key_required():
307300
url = make_url(f'trino://host/?cert={cert}')
308301
_, cparams = dialect.create_connect_args(url)
309302

310-
assert 'http_scheme' not in cparams
311303
assert 'auth' not in cparams
312304

313305
url = make_url(f'trino://host/?key={key}')
314306
_, cparams = dialect.create_connect_args(url)
315307

316-
assert 'http_scheme' not in cparams
317308
assert 'auth' not in cparams
318309

319310

@@ -322,5 +313,4 @@ def test_trino_connection_oauth2_auth():
322313
url = make_url('trino://host/?externalAuthentication=true')
323314
_, cparams = dialect.create_connect_args(url)
324315

325-
assert cparams['http_scheme'] == "https"
326316
assert isinstance(cparams['auth'], OAuth2Authentication)

trino/client.py

-2
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,6 @@ def __init__(
489489
self._exceptions = self.HTTP_EXCEPTIONS
490490
self._auth = auth
491491
if self._auth:
492-
if self._http_scheme == constants.HTTP:
493-
raise ValueError("cannot use authentication with HTTP")
494492
self._auth.set_http_session(self._http_session)
495493
self._exceptions += self._auth.get_exceptions()
496494

trino/sqlalchemy/dialect.py

-4
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,15 @@ def create_connect_args(self, url: URL) -> Tuple[Sequence[Any], Mapping[str, Any
133133
if url.password:
134134
if not url.username:
135135
raise ValueError("Username is required when specify password in connection URL")
136-
kwargs["http_scheme"] = "https"
137136
kwargs["auth"] = BasicAuthentication(unquote_plus(url.username), unquote_plus(url.password))
138137

139138
if "access_token" in url.query:
140-
kwargs["http_scheme"] = "https"
141139
kwargs["auth"] = JWTAuthentication(unquote_plus(url.query["access_token"]))
142140

143141
if "cert" in url.query and "key" in url.query:
144-
kwargs["http_scheme"] = "https"
145142
kwargs["auth"] = CertificateAuthentication(unquote_plus(url.query['cert']), unquote_plus(url.query['key']))
146143

147144
if "externalAuthentication" in url.query:
148-
kwargs["http_scheme"] = "https"
149145
kwargs["auth"] = OAuth2Authentication()
150146

151147
if "source" in url.query:

0 commit comments

Comments
 (0)