Skip to content

Commit 5d6d538

Browse files
authored
BUG: fix error when xinference run on docker with oath2 (#4161)
1 parent 7f039ae commit 5d6d538

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ install_requires =
4343
sse_starlette>=1.6.5 # ensure_bytes API break change: https://github.com/sysid/sse-starlette/issues/65
4444
openai>=1.40.0 # For typing
4545
python-jose[cryptography]
46-
passlib[bcrypt]<1.8.0
47-
bcrypt<4.1.0
46+
bcrypt>=4.0.0
4847
aioprometheus[starlette]>=23.12.0
4948
nvidia-ml-py
5049
pynvml>=12

xinference/api/oauth2/utils.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
from datetime import datetime, timedelta
1515
from typing import Union
1616

17+
import bcrypt
1718
from jose import jwt
18-
from passlib.context import CryptContext
19-
20-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
2119

2220

2321
def create_access_token(
@@ -37,8 +35,31 @@ def create_access_token(
3735

3836

3937
def verify_password(plain_password, hashed_password):
40-
return pwd_context.verify(plain_password, hashed_password)
38+
if isinstance(plain_password, str):
39+
plain_password = plain_password.encode("utf-8")
40+
if isinstance(hashed_password, str):
41+
hashed_password = hashed_password.encode("utf-8")
42+
43+
if len(plain_password) > 72:
44+
import hashlib
45+
46+
password_hash = hashlib.sha256(plain_password).digest()
47+
plain_password = password_hash[:72]
48+
49+
return bcrypt.checkpw(plain_password, hashed_password)
4150

4251

4352
def get_password_hash(password):
44-
return pwd_context.hash(password)
53+
if isinstance(password, str):
54+
password = password.encode("utf-8")
55+
56+
if len(password) > 72:
57+
import hashlib
58+
59+
password_hash = hashlib.sha256(password).digest()
60+
password = password_hash[:72]
61+
62+
salt = bcrypt.gensalt()
63+
hashed = bcrypt.hashpw(password, salt)
64+
65+
return hashed.decode("utf-8")

xinference/deploy/docker/requirements/requirements-base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ modelscope>=1.10.0
1414
sse_starlette>=1.6.5 # ensure_bytes API break change: https://github.com/sysid/sse-starlette/issues/65
1515
openai>=1.40.0 # For typing
1616
python-jose[cryptography]
17-
passlib[bcrypt]
17+
bcrypt>=4.0.0
1818
aioprometheus[starlette]>=23.12.0
1919
nvidia-ml-py
2020
pynvml>=12

xinference/deploy/docker/requirements_12.8/requirements-cu128-base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ modelscope>=1.10.0
1414
sse_starlette>=1.6.5 # ensure_bytes API break change: https://github.com/sysid/sse-starlette/issues/65
1515
openai>=1.40.0 # For typing
1616
python-jose[cryptography]
17-
passlib[bcrypt]
17+
bcrypt>=4.0.0
1818
aioprometheus[starlette]>=23.12.0
1919
nvidia-ml-py
2020
pynvml>=12

xinference/deploy/docker/requirements_cpu/requirements_cpu-base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ boto3>=1.28.55,<1.28.65
1414
sse_starlette>=1.6.5
1515
openai>1
1616
python-jose[cryptography]
17-
passlib[bcrypt]
17+
bcrypt>=4.0.0
1818
aioprometheus[starlette]>=23.12.0
1919
nvidia-ml-py
2020
async-timeout

0 commit comments

Comments
 (0)