Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Can't get to the admin panel using pip-installed khoj #1123

Closed
3 of 14 tasks
raphaelventura opened this issue Feb 19, 2025 · 6 comments
Closed
3 of 14 tasks

[FIX] Can't get to the admin panel using pip-installed khoj #1123

raphaelventura opened this issue Feb 19, 2025 · 6 comments
Labels
fix Fix something that isn't working as expected

Comments

@raphaelventura
Copy link

raphaelventura commented Feb 19, 2025

Describe the bug

I'm trying to access the admin panel, but I get the CSRF bug mentioned in the docs, although I'm using localhost to access it.

Note that:

  • I deleted and re-created the pgsql database in order to go through the initial configuration again and ensure my login/password were set as expected.
  • Same behavior from chromium and firefox, although if I try using an empty firefox profile, I don't have this error, but instead I get a 302 code and I'm stuck on the login page!
  • I had tried to use the docker images at first so maybe there is still something messing with the python install?
  • I removed my firefox navigation data + cache just in case

To Reproduce

Platform

  • Server:
    • Cloud-Hosted (https://app.khoj.dev)
    • Self-Hosted Docker
    • Self-Hosted Python package
    • Self-Hosted source code
  • Client:
    • Obsidian
    • Emacs
    • Desktop app
    • Web browser
    • WhatsApp
  • OS:
    • Windows
    • macOS
    • Linux
    • Android
    • iOS

If self-hosted

  • Server Version [e.g. 1.0.1]: 1.36.6
@raphaelventura raphaelventura added the fix Fix something that isn't working as expected label Feb 19, 2025
@clickbrain
Copy link

I am getting the CSRF error using the Docker install and I am using the localhost URL. Has anyone found any other fixes for this?

@fivejjs
Copy link

fivejjs commented Feb 25, 2025

same here

@lumisoft
Copy link

I was able to remove the CSFR error with a Docker install setting KHOJ_NO_HTTPS=false and KHOJ_DOMAIN and KHOJ_ALLOWED_DOMAIN with my local IP. However, I still can not log in, admin account always not valid even having changed KHOJ_ADMIN_EMAIL and KHOJ_ADMIN_PASSWORD in docker-compose.yml

@CHANTXU64
Copy link

Same here with Docker. Fixed by deleting container and volumes, redeploying, and reconfiguring. Works now!

@debanjum
Copy link
Member

debanjum commented Apr 7, 2025

Hi folks, this issue has turned into a mix of multiple issues. So I'm going to break it down.

Original Issue

I found an issue in 5a3c7b1 that was (incorrectly) requiring folks to set KHOJ_DOMAIN or KHOJ_DEBUG=True. Otherwise the login to admin panel would fail with the CSRF issue. These environment variables are not (expected to be) set by default.

I've pushed a fix for that issue to the mainline. If you're using the khoj docker image you can try it out by using the pre-release docker image (i.e ghcr.io/khoj-ai/khoj:pre) or wait for the next release (by end of this week) or set KHOJ_DEBUG=True in the docker-compose.yml as a mitigation until then.

Issue 2

@lumisoft, if admin username, password is showing as invalid, you'd need to do something similar to @CHANTXU64. That is,

  1. Delete your Khoj docker volume (i.e docker volume rm khoj_khoj_db)
  2. Set the KHOJ_ADMIN_EMAIL and KHOJ_ADMIN_PASSWORD set in your docker-compose.yml to whatever you like
  3. Redeploy your Khoj service
  4. Try login to the admin panel using the credentials set in step 2.

Admin email, password should only be set before the first (ever) run of khoj. It can only be changed by deleting the khoj db (i.e delete the khoj_khoj_db docker volume when setup khoj via docker) and redeploying the service with the new KHOJ_ADMIN_EMAIL and KHOJ_ADMIN_PASSWORD environment variables set before.

Thanks for the detailed bug report @raphaelventura. I'm marking this issue as resolved for now. Reopen it if the original issue persists.

For folks facing the invalid admin username, password issue, feel free to open a new issue to track that if you still cannot login to your admin panel after following the suggestions above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fix something that isn't working as expected
Projects
None yet
Development

No branches or pull requests

6 participants