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

Bug report: SAML Source Stack Trace For "duplicate key value violates unique constraint" #12556

Open
4d62 opened this issue Jan 4, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@4d62
Copy link
Contributor

4d62 commented Jan 4, 2025

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Navigate to the admin Interface
  2. Go to Directory -> Federation and Social login and create a new SAML source
  3. Set User matching mode to the second option, the SSO URL to https://company.cloudflareaccess.com/cdn-cgi/access/sso/saml/<unique string>, set the Issuer to https://company.cloudflareaccess.com/<unique id>, leave the rest of the values as default.
  4. Expand the "Flow settings" section and set all 3 to existing flows. The default "Pre authentication", the "Welcome to authentik!", and an enrollment flow created with the Cooptonian tutorial.
  5. Log out and attempt to log back in

NB:

  • The user has a password (set by default admin)
  • The user has a webauthn key set
  • The account is already connected under https://authentik.company/if/user/#/settings;%7B%22page%22%3A%22page-sources%22%7D (It worked before)
  • Before selecting all flows in step 4, the ACS url returned a bad request with the message "Configured flow doesn't exist" (Suddenly) <- When setting "Authentication flow" to "----"
  • Issue didn't happen when using a OpenID source instead of SAML
  • When setting the Authentication Flow to the other "Welcome to authentik!", it performs as expected and redirects the user back to the login page. Isn't an issue with the source.
  • Setting "User matching mode" to the first option resolves the issue

Expected behavior
A "pretty error" appears instead of a stack trace.

Screenshots
If applicable, add screenshots to help explain your problem.

Logs
Log context:

{"http_request": {"args": {}, "method": "GET", "path": "/api/v3/flows/executor/id-sdko-authentication-src/", "request_id": "56c56d01e5a64dcdbb3855650bf77986", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"}, "message": "Traceback (most recent call last):\n  File \"/authentik/flows/views/executor.py\", line 287, in get\n    stage_response = self.current_stage_view.dispatch(request)\n                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/authentik/core/sources/stage.py\", line 25, in dispatch\n    connection.save()\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/models/base.py\", line 822, in save\n    self.save_base(\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/models/base.py\", line 906, in save_base\n    parent_inserted = self._save_parents(\n                      ^^^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/models/base.py\", line 959, in _save_parents\n    updated = self._save_table(\n              ^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/models/base.py\", line 1071, in _save_table\n    results = self._do_insert(\n              ^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/models/base.py\", line 1112, in _do_insert\n    return manager._insert(\n           ^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/models/manager.py\", line 87, in manager_method\n    return getattr(self.get_queryset(), name)(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/models/query.py\", line 1847, in _insert\n    return query.get_compiler(using=using).execute_sql(returning_fields)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/models/sql/compiler.py\", line 1823, in execute_sql\n    cursor.execute(sql, params)\n  File \"/ak-root/venv/lib/python3.12/site-packages/sentry_sdk/utils.py\", line 1860, in runner\n    return sentry_patched_function(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/sentry_sdk/integrations/django/__init__.py\", line 653, in execute\n    result = real_execute(self, sql, params)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/backends/utils.py\", line 79, in execute\n    return self._execute_with_wrappers(\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/backends/utils.py\", line 92, in _execute_with_wrappers\n    return executor(sql, params, many, context)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/backends/utils.py\", line 100, in _execute\n    with self.db.wrap_database_errors:\n         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/utils.py\", line 91, in __exit__\n    raise dj_exc_value.with_traceback(traceback) from exc_value\n  File \"/ak-root/venv/lib/python3.12/site-packages/django/db/backends/utils.py\", line 105, in _execute\n    return self.cursor.execute(sql, params)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/django_prometheus/db/common.py\", line 69, in execute\n    return super().execute(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/ak-root/venv/lib/python3.12/site-packages/psycopg/cursor.py\", line 97, in execute\n    raise ex.with_traceback(None)\ndjango.db.utils.IntegrityError: duplicate key value violates unique constraint \"authentik_core_usersourc_user_id_source_id_ad1f5aa7_uniq\"\nDETAIL:  Key (user_id, source_id)=(7, 0cdc3c07-6067-436b-b226-b88c899ab917) already exists."}

Version and Deployment (please complete the following information):

  • authentik version:2024.12.1
  • Deployment: docker compose

Additional context
Add any other context about the problem here.

@4d62 4d62 added the bug Something isn't working label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant