Can't log into a commandline created superuser using Django but account gets created

828 views Asked by At

I have created a superuser that i can't log into, using the docker-compose.yml commands:

sh -c "sleep 5 &&
#<snip>
 echo A-fj... create superuser acct... &&
 echo DJANGO_SUPERUSER_PASSWORD=$DJANGO_SUPERUSER_PASSWORD &&
 echo DJANGO_SUPERUSER_EMAIL=$DJANGO_SUPERUSER_EMAIL &&
 echo DJANGO_SUPERUSER_USERNAME=$DJANGO_SUPERUSER_USERNAME && 
 python manage.py createsuperuser --noinput --username $DJANGO_SUPERUSER_USERNAME  --email $DJANGO_SUPERUSER_EMAIL &&
 echo Z-fj... create superuser acct... done. &&
#<snip>
sleep 5 "

The environment variables display perfectly, and an account gets created that i can see in the db using dBeaver.

When i manually add a second user via "$python manage.py createsuperuser" dialog, i end up with an account that i can log into.

When i copy the password from User2 to User1, i can then log into User1 using User2 password, so it seems to be a password thing.

When i compare the passwords from User1(orig) and User2(new), they look to be different formats...

I'm not sure, but thinking it may be a clue to the problem... Password1 is shorter and has no sections where Password2 is longer...

Password1:

!GSU8f8hmNOl1oJBfe1Epk7ocJiXXWQQp3G0mh9TC

Password2: pbkdf2_sha256$120000$IAkHkB3ME9aB$p0hrZPkLeSWK0IafqVQ1dEtR5kgBol7WnU7QELoo6KE=

I've tried a few different passwords, just in case, but no go

Screenshot comparing 2 passwords in dBeaver

3

There are 3 answers

1
iklinac On

You should set DJANGO_SUPERUSER_PASSWORD environment variable in non interactive mode otherwise the password would not be set (Django password would be set to unusable string in this case)

as documentation states

In non-interactive mode, the USERNAME_FIELD and required fields (listed in REQUIRED_FIELDS) fall back to DJANGO_SUPERUSER_<uppercase_field_name> environment variables, unless they are overridden by a command line argument. For example, to provide an email field, you can use DJANGO_SUPERUSER_EMAIL environment variable.

1
Michele On

Are you attempting to set the env vars with the lines that look like

...
echo DJANGO_SUPERUSER_PASSWORD=$DJANGO_SUPERUSER_PASSWORD
...

Because I think that is just echoing that string which is why the superuser is being created without a password.

If you're not sure if the vars are being set before you invoke createsuperuser, dump your env vars right before that command.

Try removing the echo.

0
Fred On

No, the echo is just echoing. Just there for troubleshooting