Pulp3 content migration - pulpcore admin is_superuser

Fighting with the woes of the content migration to pulp3 I ran into the issue with

Response body: {"detail":"You do not have permission to perform this action."}

during my very first content prepare run. I think it is related to the missing superuser flag for the pulp admin user:

[root@foreman ~]# sudo -u postgres psql pulpcore -c 'select id,username,is_superuser from auth_user;'
 id |   username    | is_superuser 
----+---------------+--------------
  1 | admin         | f
  2 | AnonymousUser | f
(2 rows)

I know I can set it manually in the database but I wonder why this isn’t set by the foreman-installer?

I must admit that we don’t really do a great job of documenting how it’s supposed to work. So I’m going to refer to how we create the data initially:

The reset command has a side effect of creating the user:

There you can see it should indeed be a superuser. I don’t know how the user could have changed to false.

To change it, I’d suggest to open a console with PULP_SETTINGS=/etc/pulp/settings.py pulpcore-manager shell and then run:

from django.contrib.auth import get_user_model
user = user_model.objects.get(username='admin')
user.is_superuser = True
user.save()

(Yes, that you need to set the env var is kind of stupid but upstream hasn’t been very open to prescribing a default layout and at least for now we ship pure upstream code)

When I try that I get:

>>> from django.contrib.auth import get_user_model
>>> user = user_model.objects.get(username='admin')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'user_model' is not defined

I don’t mind changing it directly in the database. I know my SQL. Or is the pulp shell doing more than changing the database?

Oh, I missed a user_model = get_user_model() in there. I may need more caffeine.

I honestly don’t know exactly. Django does implement signals so it is possible to hook into changes on models. If Pulp is using those, you may miss them. That’s why I suggested the Python approach.

So the full call is:

# PULP_SETTINGS=/etc/pulp/settings.py pulpcore-manager shell
from django.contrib.auth import get_user_model
user_model = get_user_model()
user = user_model.objects.get(username='admin')
user.is_superuser = True
user.save()
2 Likes

Exactly. Given you’ve marked it as a solution I take it that it fixed your problem.