[Feature Request] Dynamically grant Superuser/Staff status to OIDC/SSO users based on group claims #13038
Replies: 3 comments 1 reply
|
I think the general feature makes sense, but I would implement it in the existing social group sync path rather than only in Right now Paperless already centralizes OIDC group syncing in The important detail is deprovisioning. The implementation should not only grant flags when a claim is present; it should also remove flags when the IdP group is removed, unless the user is protected by some explicit local override. Otherwise a temporary IdP admin group assignment becomes permanent local superuser access. The settings shape seems reasonable, but I would suggest tests for at least these cases:
Security-wise, it may also be worth documenting that these flags fully trust the IdP group claim. For deployments where the IdP is the source of truth, that is fine; for mixed local/SSO deployments, a local override/protection mechanism would prevent accidentally stripping the only local admin. |
|
Since there were no objections, I've started drafting a Pull Request implementing the signal-based approach we discussed above. I'll link it here as soon as it's ready for review. |
|
I have opened a draft Pull Request containing the signal-based implementation we discussed. You can find it here: #13060 |
Uh oh!
There was an error while loading. Please reload this page.
Description
Use Case / Problem Description
Currently, when setting up OpenID Connect (OIDC) or SSO authentication in Paperless-ngx via
django-allauth, automatically provisioned users are created as standard, unprivileged accounts.In declarative, containerized, or GitOps environments (such as Kubernetes, automated Docker Compose deployments or sophisticated private users), this creates a bootstrapping challenge:
PAPERLESS_ADMIN_USERandPAPERLESS_ADMIN_PASSWORD), which exposes credentials indocker inspector process lists.createsuperuserinside the container shell, which prevents fully automated deployments.superuserorstaffstatus in the UI or database.While Paperless-ngx supports syncing user groups from OIDC claims via
SOCIAL_ACCOUNT_SYNC_GROUPS, it does not support mapping these groups to the Django-internal database flagsis_superuserandis_staff.Proposed Solution
I propose introducing new configuration settings (exposed as environment variables) to dynamically assign administrative privileges based on synced group claims:
PAPERLESS_SOCIAL_ACCOUNT_SUPERUSER_GROUPS: A comma-separated list of OIDC groups (e.g.,admins,devops) that will automatically grant the useris_superuser = True(and implicitlyis_staff = True) upon login.PAPERLESS_SOCIAL_ACCOUNT_STAFF_GROUPS: A comma-separated list of OIDC groups (e.g.,staff,moderators) that will grantis_staff = True(access to django-admin, but no full superuser rights).Other
Proposed Technical Implementation
Configuration (
src/paperless/config.py&settings.py):Parse the comma-separated environment variables into Python lists/sets and expose them in the Django settings (e.g.,
settings.SOCIAL_ACCOUNT_SUPERUSER_GROUPSandsettings. SOCIAL_ACCOUNT_STAFF_GROUPS).Adapter Logic (
src/paperless/adapter.py):Extend the existing
CustomSocialAccountAdapter'ssave_usermethod to read OIDC claims (sociallogin.account.extra_data), resolve the group claim name (usingSOCIAL_ACCOUNT_SYNC_GROUPS_CLAIM),and toggle the user database flags accordingly:
This implementation remains fully backward-compatible. If the variables are not set, the behavior remains unchanged.
I am happy to implement this!
I have analyzed the codebase and am prepared to implement this change and open a Pull Request.
Please let me know if the maintainers are open to this contribution and if the proposed configuration design aligns with the project guidelines.
All reactions