Skip to content

Commit 7171516

Browse files
lokeshrangineniredhatHameed
authored andcommitted
Moved the common fixtures to the root conftest.py or auth_permissions_util.py (feast-dev#54)
* Moved the common fixtures to the root conftest.py or auth_permissions_util.py Signed-off-by: Lokesh Rangineni <lokeshforjava@gmail.com> Signed-off-by: Lokesh Rangineni <lokeshforjava@gmail.com> * Adding missed dependency and regenerated the requirements files. Signed-off-by: Lokesh Rangineni <lokeshforjava@gmail.com> Signed-off-by: Lokesh Rangineni <lokeshforjava@gmail.com> * Addinig missing changes from the original PR. Signed-off-by: Lokesh Rangineni <lokeshforjava@gmail.com> Signed-off-by: Lokesh Rangineni <lokeshforjava@gmail.com> --------- Signed-off-by: Lokesh Rangineni <lokeshforjava@gmail.com> Signed-off-by: Abdul Hameed <ahameed@redhat.com>
1 parent a6aaa0d commit 7171516

13 files changed

Lines changed: 366 additions & 152 deletions

File tree

sdk/python/feast/permissions/auth/oidc_token_parser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ async def user_details_from_access_token(self, access_token: str) -> User:
7373
signing_key.key,
7474
algorithms=["RS256"],
7575
audience="account",
76-
options={"verify_exp": True},
76+
options={
77+
"verify_aud": False,
78+
"verify_signature": True,
79+
"verify_exp": True,
80+
},
7781
)
7882

7983
if "preferred_username" not in data:
@@ -99,4 +103,5 @@ async def user_details_from_access_token(self, access_token: str) -> User:
99103
logger.info(f"Extracted user {current_user} and roles {roles}")
100104
return User(username=current_user, roles=roles)
101105
except jwt.exceptions.InvalidTokenError:
106+
logger.exception("Exception while parsing the token:")
102107
raise AuthenticationError("Invalid token.")

sdk/python/feast/permissions/client/http_auth_requests_wrapper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
class AuthenticatedRequestsSession(Session):
1212
def __init__(self, auth_token: str):
1313
super().__init__()
14-
self.auth_token = auth_token
15-
self.headers.update({"Authorization": f"Bearer {self.auth_token}"})
14+
self.headers.update({"Authorization": f"Bearer {auth_token}"})
1615

1716

1817
def get_http_auth_requests_session(auth_config: AuthConfig) -> Session:

sdk/python/feast/permissions/client/oidc_authentication_client_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ def get_token(self):
5454
return access_token
5555
else:
5656
raise RuntimeError(
57-
"Failed to obtain access token: {token_response.status_code} - {token_response.text}"
57+
f"""Failed to obtain oidc access token:url=[{token_endpoint}] {token_response.status_code} - {token_response.text}"""
5858
)

sdk/python/requirements/py3.10-ci-requirements.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ async-timeout==4.0.3
4040
# via
4141
# aiohttp
4242
# redis
43+
async-property==0.2.2
44+
# via python-keycloak
4345
atpublic==4.1.0
4446
# via ibis-framework
4547
attrs==23.2.0
@@ -63,6 +65,8 @@ beautifulsoup4==4.12.3
6365
# via nbconvert
6466
bidict==0.23.1
6567
# via ibis-framework
68+
bigtree==0.19.2
69+
# via feast (setup.py)
6670
bleach==6.1.0
6771
# via nbconvert
6872
boto3==1.34.131
@@ -131,6 +135,7 @@ cryptography==42.0.8
131135
# azure-identity
132136
# azure-storage-blob
133137
# great-expectations
138+
# jwcrypto
134139
# moto
135140
# msal
136141
# pyjwt
@@ -154,6 +159,8 @@ defusedxml==0.7.1
154159
# via nbconvert
155160
deltalake==0.18.1
156161
# via feast (setup.py)
162+
deprecation==2.1.0
163+
# via python-keycloak
157164
dill==0.3.8
158165
# via feast (setup.py)
159166
distlib==0.3.8
@@ -300,6 +307,7 @@ httpx==0.27.0
300307
# feast (setup.py)
301308
# fastapi
302309
# jupyterlab
310+
# python-keycloak
303311
ibis-framework[duckdb]==9.1.0
304312
# via
305313
# feast (setup.py)
@@ -409,6 +417,8 @@ jupyterlab-server==2.27.2
409417
# notebook
410418
jupyterlab-widgets==3.0.11
411419
# via ipywidgets
420+
jwcrypto==1.5.6
421+
# via python-keycloak
412422
kubernetes==20.13.0
413423
# via feast (setup.py)
414424
locket==1.0.0
@@ -502,6 +512,7 @@ packaging==24.1
502512
# build
503513
# dask
504514
# db-dtypes
515+
# deprecation
505516
# google-cloud-bigquery
506517
# great-expectations
507518
# gunicorn
@@ -712,6 +723,8 @@ python-dotenv==1.0.1
712723
# via uvicorn
713724
python-json-logger==2.0.7
714725
# via jupyter-events
726+
python-keycloak==4.2.2
727+
# via feast (setup.py)
715728
python-multipart==0.0.9
716729
# via fastapi
717730
pytz==2024.1
@@ -760,14 +773,18 @@ requests==2.32.3
760773
# kubernetes
761774
# moto
762775
# msal
776+
# python-keycloak
763777
# requests-oauthlib
778+
# requests-toolbelt
764779
# responses
765780
# singlestoredb
766781
# snowflake-connector-python
767782
# sphinx
768783
# trino
769784
requests-oauthlib==2.0.0
770785
# via kubernetes
786+
requests-toolbelt==1.0.0
787+
# via python-keycloak
771788
responses==0.25.3
772789
# via moto
773790
rfc3339-validator==0.1.4
@@ -972,6 +989,7 @@ typing-extensions==4.12.2
972989
# great-expectations
973990
# ibis-framework
974991
# ipython
992+
# jwcrypto
975993
# mypy
976994
# psycopg
977995
# psycopg-pool

sdk/python/requirements/py3.11-ci-requirements.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ asttokens==2.4.1
3636
# via stack-data
3737
async-lru==2.0.4
3838
# via jupyterlab
39+
async-property==0.2.2
40+
# via python-keycloak
3941
atpublic==4.1.0
4042
# via ibis-framework
4143
attrs==23.2.0
@@ -59,6 +61,8 @@ beautifulsoup4==4.12.3
5961
# via nbconvert
6062
bidict==0.23.1
6163
# via ibis-framework
64+
bigtree==0.19.2
65+
# via feast (setup.py)
6266
bleach==6.1.0
6367
# via nbconvert
6468
boto3==1.34.131
@@ -127,6 +131,7 @@ cryptography==42.0.8
127131
# azure-identity
128132
# azure-storage-blob
129133
# great-expectations
134+
# jwcrypto
130135
# moto
131136
# msal
132137
# pyjwt
@@ -150,6 +155,8 @@ defusedxml==0.7.1
150155
# via nbconvert
151156
deltalake==0.18.1
152157
# via feast (setup.py)
158+
deprecation==2.1.0
159+
# via python-keycloak
153160
dill==0.3.8
154161
# via feast (setup.py)
155162
distlib==0.3.8
@@ -291,6 +298,7 @@ httpx==0.27.0
291298
# feast (setup.py)
292299
# fastapi
293300
# jupyterlab
301+
# python-keycloak
294302
ibis-framework[duckdb]==9.1.0
295303
# via
296304
# feast (setup.py)
@@ -400,6 +408,8 @@ jupyterlab-server==2.27.2
400408
# notebook
401409
jupyterlab-widgets==3.0.11
402410
# via ipywidgets
411+
jwcrypto==1.5.6
412+
# via python-keycloak
403413
kubernetes==20.13.0
404414
# via feast (setup.py)
405415
locket==1.0.0
@@ -493,6 +503,7 @@ packaging==24.1
493503
# build
494504
# dask
495505
# db-dtypes
506+
# deprecation
496507
# google-cloud-bigquery
497508
# great-expectations
498509
# gunicorn
@@ -703,6 +714,8 @@ python-dotenv==1.0.1
703714
# via uvicorn
704715
python-json-logger==2.0.7
705716
# via jupyter-events
717+
python-keycloak==4.2.2
718+
# via feast (setup.py)
706719
python-multipart==0.0.9
707720
# via fastapi
708721
pytz==2024.1
@@ -751,14 +764,18 @@ requests==2.32.3
751764
# kubernetes
752765
# moto
753766
# msal
767+
# python-keycloak
754768
# requests-oauthlib
769+
# requests-toolbelt
755770
# responses
756771
# singlestoredb
757772
# snowflake-connector-python
758773
# sphinx
759774
# trino
760775
requests-oauthlib==2.0.0
761776
# via kubernetes
777+
requests-toolbelt==1.0.0
778+
# via python-keycloak
762779
responses==0.25.3
763780
# via moto
764781
rfc3339-validator==0.1.4
@@ -951,6 +968,7 @@ typing-extensions==4.12.2
951968
# great-expectations
952969
# ibis-framework
953970
# ipython
971+
# jwcrypto
954972
# mypy
955973
# psycopg
956974
# psycopg-pool
@@ -1028,4 +1046,3 @@ yarl==1.9.4
10281046
# via aiohttp
10291047
zipp==3.19.1
10301048
# via importlib-metadata
1031-
bigtree==0.19.2

sdk/python/requirements/py3.9-ci-requirements.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ async-timeout==4.0.3
4040
# via
4141
# aiohttp
4242
# redis
43+
async-property==0.2.2
44+
# via python-keycloak
4345
atpublic==4.1.0
4446
# via ibis-framework
4547
attrs==23.2.0
@@ -63,6 +65,8 @@ beautifulsoup4==4.12.3
6365
# via nbconvert
6466
bidict==0.23.1
6567
# via ibis-framework
68+
bigtree==0.19.2
69+
# via feast (setup.py)
6670
bleach==6.1.0
6771
# via nbconvert
6872
boto3==1.34.131
@@ -131,6 +135,7 @@ cryptography==42.0.8
131135
# azure-identity
132136
# azure-storage-blob
133137
# great-expectations
138+
# jwcrypto
134139
# moto
135140
# msal
136141
# pyjwt
@@ -154,6 +159,8 @@ defusedxml==0.7.1
154159
# via nbconvert
155160
deltalake==0.18.1
156161
# via feast (setup.py)
162+
deprecation==2.1.0
163+
# via python-keycloak
157164
dill==0.3.8
158165
# via feast (setup.py)
159166
distlib==0.3.8
@@ -300,6 +307,7 @@ httpx==0.27.0
300307
# feast (setup.py)
301308
# fastapi
302309
# jupyterlab
310+
# python-keycloak
303311
ibis-framework[duckdb]==9.0.0
304312
# via
305313
# feast (setup.py)
@@ -418,6 +426,8 @@ jupyterlab-server==2.27.2
418426
# notebook
419427
jupyterlab-widgets==3.0.11
420428
# via ipywidgets
429+
jwcrypto==1.5.6
430+
# via python-keycloak
421431
kubernetes==20.13.0
422432
# via feast (setup.py)
423433
locket==1.0.0
@@ -511,6 +521,7 @@ packaging==24.1
511521
# build
512522
# dask
513523
# db-dtypes
524+
# deprecation
514525
# google-cloud-bigquery
515526
# great-expectations
516527
# gunicorn
@@ -721,6 +732,8 @@ python-dotenv==1.0.1
721732
# via uvicorn
722733
python-json-logger==2.0.7
723734
# via jupyter-events
735+
python-keycloak==4.2.2
736+
# via feast (setup.py)
724737
python-multipart==0.0.9
725738
# via fastapi
726739
pytz==2024.1
@@ -769,14 +782,18 @@ requests==2.32.3
769782
# kubernetes
770783
# moto
771784
# msal
785+
# python-keycloak
772786
# requests-oauthlib
787+
# requests-toolbelt
773788
# responses
774789
# singlestoredb
775790
# snowflake-connector-python
776791
# sphinx
777792
# trino
778793
requests-oauthlib==2.0.0
779794
# via kubernetes
795+
requests-toolbelt==1.0.0
796+
# via python-keycloak
780797
responses==0.25.3
781798
# via moto
782799
rfc3339-validator==0.1.4
@@ -984,6 +1001,7 @@ typing-extensions==4.12.2
9841001
# great-expectations
9851002
# ibis-framework
9861003
# ipython
1004+
# jwcrypto
9871005
# mypy
9881006
# psycopg
9891007
# psycopg-pool
@@ -1064,4 +1082,3 @@ yarl==1.9.4
10641082
# via aiohttp
10651083
zipp==3.19.1
10661084
# via importlib-metadata
1067-
bigtree==0.19.2

sdk/python/tests/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import multiprocessing
1616
import os
1717
import random
18+
import tempfile
1819
from datetime import timedelta
1920
from multiprocessing import Process
2021
from sys import platform
@@ -24,6 +25,7 @@
2425
import pandas as pd
2526
import pytest
2627
from _pytest.nodes import Item
28+
from testcontainers.keycloak import KeycloakContainer
2729

2830
from feast.data_source import DataSource
2931
from feast.feature_store import FeatureStore # noqa: E402
@@ -54,6 +56,10 @@
5456
driver,
5557
location,
5658
)
59+
from tests.utils.auth_permissions_util import (
60+
default_store,
61+
setup_permissions_on_keycloak,
62+
)
5763
from tests.utils.http_server import check_port_open, free_port # noqa: E402
5864

5965
logger = logging.getLogger(__name__)
@@ -406,3 +412,28 @@ def fake_document_data(environment: Environment) -> Tuple[pd.DataFrame, DataSour
406412
environment.feature_store.project,
407413
)
408414
return df, data_source
415+
416+
417+
@pytest.fixture
418+
def temp_dir():
419+
with tempfile.TemporaryDirectory() as temp_dir:
420+
print(f"Created {temp_dir}")
421+
yield temp_dir
422+
423+
424+
@pytest.fixture
425+
def start_keycloak_server():
426+
with KeycloakContainer("quay.io/keycloak/keycloak:24.0.1") as keycloak_container:
427+
setup_permissions_on_keycloak(keycloak_container.get_client())
428+
yield keycloak_container.get_url()
429+
430+
431+
@pytest.fixture
432+
def server_port():
433+
return free_port()
434+
435+
436+
@pytest.fixture
437+
def feature_store(temp_dir, auth_config, applied_permissions):
438+
print(f"Creating store at {temp_dir}")
439+
return default_store(str(temp_dir), auth_config, applied_permissions)

0 commit comments

Comments
 (0)