Search code examples
djangodockercsrfpodmancsrf-token

Error 403 while running Docker image on Windows, but works on RHEL8


I have a web application made in Django, I build it and run it in Linux Redhat 8 and it works fine. Trying to run it on Windows using Docker allows me to get into webpage, but I can't login, I just get [POST] Error 403 (Forbidden), But the image is the same at both envs.

I'm accesing it via 127.0.0.1:8000, which is CSRF Enabled in settings.py and in ALLOWED_HOSTS and works on RHEL8, but doesn't allow me to login on Windows (same for 0.0.0.0:8000 and localhost:8000)

How I run it in both environments docker run -it --rm -p 8000:8000 my_image_name

Dockerfile:

FROM my_image_repo
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY . /app/
EXPOSE 8000
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
settings.py:

CSRF_TRUSTED_ORIGINS = [
'http://localhost',
'http://localhost:8000',
'http://127.0.0.1:8000',
'http://127.0.0.1',
'http://0.0.0.0'
]
ALLOWED_HOSTS = [
'http://localhost',
'http://localhost:8000',
'http://127.0.0.1:8000',
'http://127.0.0.1',
'http://0.0.0.0',
'localhost',
'0.0.0.0',
'localhost:8000',
'127.0.0.1',
'127.0.0.1:8000'
]

Are there any firewall settings I need to change for it to allow me to do that on windows? I usually work on Linux only, but company requires me to make this work on Windows as well

I tried adding more URLS to ALLOWED_HOSTS and CSRF, as well as I added to settings.py this line: SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

Didn't help.

To work on Linux I had to add username:100000:65536 to /etc/subuid and /etc/subgid, is there any equavilent on Windows?


Solution

  • Ok I had to move /admin from urls.py to the bottom....