Skip to content

lib/sync/outgoing: report conflicting objects instead of failing sync - #27287

Merged
dominic-r merged 2 commits into
mainfrom
dominic/outgoing-sync-report-conflicts
Oct 29, 2026
Merged

dominic-r merged 2 commits into
mainfrom
dominic/outgoing-sync-report-conflicts

Conversation

@dominic-r

Copy link
Copy Markdown
Member

Details

What does this PR change?

When an outgoing sync provider (SCIM, Google Workspace, Entra ID) can't sync a user or group, the task log now says which object it was and includes the remote system's response, and the sync continues with the next object. For a conflict, the message also says what to change: delete or rename the conflicting object in the remote system, or change the property mappings so the values the remote system requires to be unique are different. This applies to full, direct, delete, and membership sync. Errors that don't belong to one object, from discovery or cleanup, end the full sync with a task error, as StopSync already did.

Behind that, per provider:

  • SCIM: the search after a 409 no longer crashes when the response isn't a ListResponse, reports the conflict when the search itself fails, and only links an object whose userName or displayName matches. Groups are searched by their mapped displayName, not the authentik group name.
  • Google Workspace: 400 responses no longer raise TypeError, and errors carry Google's message. After a conflict, authentik only links the user or group whose primary address it is, so an address held by another kind of object or an alias is reported instead of linked to the wrong object.
  • Entra ID: Graph errors are mapped by status (400, 404, 409) like the other providers, and keep Graph's error message. Before, every Graph error became StopSync before the status checks, so the existing conflict linking and re-create-after-404 handling never ran. That conflict linking compared odata_count, which Graph only returns when a count is requested, so it would have raised TypeError. It now reports the conflict when nothing is found instead of skipping the object silently.
  • Removing a member who is already gone from the remote group counts as done (Google Workspace, Entra ID).
  • StopSync can be printed again. Since lib: update error logging #18628 its str() raised AttributeError, which also broke task.error(exc) in LDAP and Kerberos source sync.

Why is this change needed?

In #26904 a SCIM remote answered 409, and the sync failed with AttributeError: 'list' object has no attribute 'items' chained to ObjectExistsSyncException, without naming the object or saying what to do. Two problems combined. The SCIM search after the conflict assumed a ListResponse, and the sync tasks didn't handle ObjectExistsSyncException at all. Even with a valid search response, a conflict that couldn't be linked escaped the task. The rest of the page wasn't synced, the full sync failed before syncing groups and cleaning up, and the task log only said Object exists: ….

The same gap existed in the other sync paths and providers. Direct sync failed on BadRequestSyncException, and StopSync in direct and membership sync only reached the server log. Google Workspace passed two arguments to exceptions that take one. Entra ID's status checks were unreachable.

The sync exceptions are ignored by the task middleware's event creation, so an escaping conflict never created a system_task_exception event unless, as in #26904, it crashed with an unrelated error. The failures now show as task warnings, which mark the task as a warning on the System Tasks page.

How was this tested?

I reproduced the issue first. A full sync where the remote answers 409 and the search returns a JSON array failed with the same AttributeError and system_task_exception event as the report.

I added tests for each provider: an unresolved conflict in full and direct sync, a remote that ignores the filter, a failed search, linking an existing user or group, a Google Workspace address held by a user or alias, a user and a membership change that the remote rejects, removing a member who is already gone, an Entra ID user created again after a 404, a cleanup and a delete that the remote rejects, and StopSync in direct sync and LDAP sync. All of them fail without the change, except the one that links an existing Google Workspace group, which passes before and after and checks that the new address check still links it. I did not test against a real SCIM server, Google Workspace, or an Entra ID tenant. The Entra ID tests raise the same ODataError that the Graph SDK raises.

The change doesn't cherry-pick cleanly onto version-2026.8, because the sync tasks and one test file differ there, so the backport needs its conflicts resolved by hand.

Linked issues

Closes #26904


Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)
  • I have read the AI usage policy.

When a remote system answered 409 and the provider couldn't link the
existing object, ObjectExistsSyncException escaped the sync task. The
task failed with an error that named no object and said nothing about
how to resolve it, the rest of the page was never synced, and the full
sync failed before it synced groups and cleaned up. SCIM made it worse:
a search response that wasn't a ListResponse raised AttributeError and
hid the conflict.

Full, direct, delete, and membership sync now log a warning with the
object and the remote system's response, and continue. A conflict also
says what to change. Errors that don't belong to one object, from
discovery or cleanup, end the full sync with a task error, as StopSync
already did.

Several errors could not reach that log. StopSync never set the
response that str() reads, so printing it raised AttributeError, and
Google Workspace passed two arguments to exceptions that take one, so
every 400 raised TypeError. Entra ID turned every Graph error into
StopSync before checking its status, so its conflict and re-create
handling never ran. It now maps 400, 404, and 409 like the other
providers, keeps Graph's error message, and no longer compares
odata_count, which Graph only returns when a count is requested.

Linking after a conflict now only links the matching object. SCIM
checks the returned userName or displayName, since some servers ignore
the filter, and Google Workspace checks the primary address, so an
address held by another kind of object or an alias is reported instead
of linked. Removing a member who is already gone counts as done.

Closes: #26904
@dominic-r dominic-r added area:backend backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 labels Oct 27, 2026
@dominic-r
dominic-r requested a review from a team as a code owner October 27, 2026 23:22
@dominic-r dominic-r self-assigned this Oct 27, 2026
@netlify

netlify Bot commented Oct 27, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit db1915b
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6ae132488a77aa886182ca78
😎 Deploy Preview https://deploy-preview-27287--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.40000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.58%. Comparing base (98c4b28) to head (fb5fdae).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rprise/providers/google_workspace/clients/users.py 71.42% 2 Missing ⚠️
...erprise/providers/google_workspace/clients/base.py 83.33% 1 Missing ⚠️
...prise/providers/google_workspace/clients/groups.py 90.00% 1 Missing ⚠️
...terprise/providers/microsoft_entra/clients/base.py 85.71% 1 Missing ⚠️
...rprise/providers/microsoft_entra/clients/groups.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #27287      +/-   ##
==========================================
+ Coverage   92.48%   92.58%   +0.10%     
==========================================
  Files        1197     1197              
  Lines       81116    81450     +334     
  Branches     4497     4497              
==========================================
+ Hits        75017    75413     +396     
+ Misses       6033     5971      -62     
  Partials       66       66              
Flag Coverage Δ
conformance 31.05% <0.72%> (-0.10%) ⬇️
e2e 35.90% <0.72%> (-0.11%) ⬇️
integration 28.53% <0.72%> (-0.09%) ⬇️
rust 45.98% <ø> (ø)
unit 94.23% <98.40%> (+0.10%) ⬆️
unit-migrate 94.23% <98.40%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Playwright e2e

Download this run's HTML report and traces, then open the report:

gh run download 40803273453 -D playwright-artifacts
npx playwright show-report playwright-artifacts/playwright-report

Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-fb5fdaeea00fe0a6dbcfb63228c6f41515c142d2
# Distroless image: AUTHENTIK_TAG=gh-fb5fdaeea00fe0a6dbcfb63228c6f41515c142d2-distroless
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
    image:
        repository: ghcr.io/goauthentik/dev-server
        tag: gh-fb5fdaeea00fe0a6dbcfb63228c6f41515c142d2
        # Distroless image: tag: gh-fb5fdaeea00fe0a6dbcfb63228c6f41515c142d2-distroless

Afterwards, run the upgrade commands from the latest release notes.

@dominic-r
dominic-r merged commit a96ef0e into main Oct 29, 2026
171 checks passed
@dominic-r
dominic-r deleted the dominic/outgoing-sync-report-conflicts branch October 29, 2026 15:29
@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

⚠️ Cherry-pick to version-2026.8 has conflicts: #27348

@johnkeates

Copy link
Copy Markdown

Thanks a ton 💯 !

dominic-r added a commit that referenced this pull request Nov 23, 2026
… (cherry-pick #27287 to version-2026.8) (#27348)

* Cherry-pick #27287 to version-2026.8 (with conflicts)

This cherry-pick has conflicts that need manual resolution.

Original PR: #27287
Original commit: a96ef0e

* lib/sync/outgoing: resolve conflicts in the 2026.8 backport

version-2026.8 still uses Tenant in these tests and has no SCIM
discovery helpers, so keep the Tenant import, drop the QuerySet import
the discovery code needed on main, and drop urlencode, which moved to
the SCIM base client. test_account_expiration.py only exists on main
with the LDAP accountExpires change, so it is not part of this backport.

---------

Co-authored-by: Dominic Roy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCIM ObjectExistsSyncException does not provide context or remediation

3 participants