Strange UTF-8 problem with docker in api/auth.pi for jwt.decode

Hello

First of all, thanks for this wonderful project !

I made a dockerfile (based on python:3.8.7-slim-buster) to deploy PrivacyIDEA 3.5 and found some strange behaviour : I received an error about “utf-8” in api/auth.pi, right after jwt.encode (line 368). Actually, it seem that jwt.encode (in my setup) does not output utf-8…

I looked on the docs, forum and issues and couldn’t find any clue… so I decided to “patch” the problem by removing the “.decode(‘utf8’)”

So, in my patched version:

token = jwt.encode({“username”: loginname,
“realm”: realm,
“nonce”: nonce,
“role”: role,
“authtype”: authtype,
“exp”: datetime.utcnow() + validity,
“rights”: rights},
secret, algorithm=‘HS256’).decode(‘utf8’)

is now:

token = jwt.encode({“username”: loginname,
“realm”: realm,
“nonce”: nonce,
“role”: role,
“authtype”: authtype,
“exp”: datetime.utcnow() + validity,
“rights”: rights},
secret, algorithm=‘HS256’)

I can’t tell if the problem comes from: 1) my server 2) docker 3) the dockerfile 4) jwt.encode or python configuration…
I guess that it is a combination of a bit of everything, as nobody seemed to report it before (and it’s blocking)

Anyway: if someone has the same problem… you’re not alone :slight_smile:

I didn’t see any drawback to my “fix” (seem quite a local fix)… except maybe for UTF-8 loginname…
Do you see some ? And do you think that it should be considered as a bug ? A feature ? A configuration problem on my server ?

Hello and welcome to the forum,

how did You install/deploy privacyIDEA in the container?
Current releases of PyJWT introduce some changes (jwt.encode() returns an utf8 string since they dropped support for Python 2).
We strongly recommend using the pinned packages from the requirements.txt file, these are the ones we are testing with.

Actually, I used:

FROM python:3.8.7-slim-buster

RUN \
    apt-get update -y \
    && apt-get install -y sqlite \
    && apt-get install -y python-dev python-pip nginx supervisor \
    && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN pip install privacyidea

But after reading : https://privacyidea.readthedocs.io/en/latest/installation/pip.html
I will now use:

pip install -r https://raw.githubusercontent.com/privacyidea/privacyidea/v${PI_VERSION}/requirements.txt
pip install git+https://github.com/privacyidea/privacyidea.git@v${PI_VERSION}

Thanks a lot for the information