Investigate JWT "Not enough segments" errors
Problem to solve
Currently that there are quite a few of requests resulted in Not enough segments
error https://log.gprd.gitlab.net/app/r/s/q3B1k :
Traceback (most recent call last):
File "/opt/venv/ai-gateway-9TtSrW0h-py3.10/lib/python3.10/site-packages/jose/jws.py", line 176, in _load
signing_input, crypto_segment = jwt.rsplit(b".", 1)
ValueError: not enough values to unpack (expected 2, got 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/venv/ai-gateway-9TtSrW0h-py3.10/lib/python3.10/site-packages/jose/jwt.py", line 142, in decode
payload = jws.verify(token, key, algorithms, verify=verify_signature)
File "/opt/venv/ai-gateway-9TtSrW0h-py3.10/lib/python3.10/site-packages/jose/jws.py", line 70, in verify
header, payload, signing_input, signature = _load(token)
File "/opt/venv/ai-gateway-9TtSrW0h-py3.10/lib/python3.10/site-packages/jose/jws.py", line 180, in _load
raise JWSError("Not enough segments")
jose.exceptions.JWSError: Not enough segments
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/ai_gateway/auth/providers.py", line 53, in authenticate
jwt_claims = jwt.decode(
File "/opt/venv/ai-gateway-9TtSrW0h-py3.10/lib/python3.10/site-packages/jose/jwt.py", line 144, in decode
raise JWTError(e)
jose.exceptions.JWTError: Not enough segments
This indicates that the JWT is malformed (e.g. .
is missing), however, this is odd since the tokens are fetched from Customer Dot in Self-managed GitLab instances.