Repository navigation
outposts: only write changed permissions, add endpoint to rebuild them - #26928
Conversation
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #26928 +/- ##
==========================================
+ Coverage 92.46% 92.68% +0.21%
==========================================
Files 1197 1197
Lines 81648 81816 +168
Branches 4568 4628 +60
==========================================
+ Hits 75497 75830 +333
+ Misses 6085 5910 -175
- Partials 66 76 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Playwright e2eDownload this run's HTML report and traces, then open the report: gh run download 40910001154 -D playwright-artifacts
npx playwright show-report playwright-artifacts/playwright-reportInstallation instructionsInstructions for docker-composeAdd the following block to your AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-8f18a0a428a2ea606235df1d50ab753c2e1cae29
# Distroless image: AUTHENTIK_TAG=gh-8f18a0a428a2ea606235df1d50ab753c2e1cae29-distroless
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)sAfterwards, run the upgrade commands from the latest release notes. Instructions for KubernetesAdd the following block to your 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-8f18a0a428a2ea606235df1d50ab753c2e1cae29
# Distroless image: tag: gh-8f18a0a428a2ea606235df1d50ab753c2e1cae29-distrolessAfterwards, run the upgrade commands from the latest release notes. |
BeryJu
left a comment
There was a problem hiding this comment.
I'd prefer to have an additional management command (or API endpoint) to fully rebuild the perms if some sort of desync happens, as currently we use saving an outpost for this, and its quite helpful for troubleshooting
Saving an outpost no longer deletes and recreates every permission of
its service account, which was useful when troubleshooting a desync.
POST /outposts/instances/{uuid}/rebuild_permissions/ does that full
rebuild explicitly and requires permission to change the outpost.
| "permission_id", flat=True | ||
| ) | ||
| ) | ||
| existing_obj = { |
There was a problem hiding this comment.
typing please
maybe also rename to existing_obj_permissions
# Conflicts: # authentik/outposts/tests/test_api.py
* main: (114 commits) website/integrations: add planka sso requirement note (#27376) core: bump ruff from 0.17.2 to 0.17.3 (#27370) core: bump cachetools from 7.2.5 to 7.2.6 (#27372) core: bump coverage[toml] from 7.16.2 to 7.17.0 (#27373) core: bump django from 5.2.17 to 5.2.18 (#27369) core: bump google-api-core from 2.36.0 to v2.43.0 (#27214) core: bump boto3 from 1.43.90 to v1.43.119 (#27208) core: bump googleapis-common-protos from 1.75.3 to v1.76.0 (#27217) core: bump msgpack from 1.2.3 to v1.2.4 (#27235) packages/django-dramatiq-postgres: limit task fetching (#27197) web/admin: make flow execute links base-path aware (#27314) lib: fix capture_logs not thread safe (#27355) web/user: keep configure URL query strings when adding next (#27313) web/flow: refresh WebAuthn challenge on authentication retry (#26616) server, lifecycle: drop idle upstream connections before uvicorn does (#27192) outposts: only write changed permissions, add endpoint to rebuild them (#26928) flows: fix planner not resolving stages causing extra queries (#27320) outposts/proxy: honor X-Forwarded-Host in envoy forward auth (#26888) website/docs: Update wording for internal and external users (#27345) server: strip hop-by-hop headers before forwarding to the application (#27191) ...
* main: (115 commits) lib/tracing: use BatchSpanProcessor (#27387) website/integrations: add planka sso requirement note (#27376) core: bump ruff from 0.17.2 to 0.17.3 (#27370) core: bump cachetools from 7.2.5 to 7.2.6 (#27372) core: bump coverage[toml] from 7.16.2 to 7.17.0 (#27373) core: bump django from 5.2.17 to 5.2.18 (#27369) core: bump google-api-core from 2.36.0 to v2.43.0 (#27214) core: bump boto3 from 1.43.90 to v1.43.119 (#27208) core: bump googleapis-common-protos from 1.75.3 to v1.76.0 (#27217) core: bump msgpack from 1.2.3 to v1.2.4 (#27235) packages/django-dramatiq-postgres: limit task fetching (#27197) web/admin: make flow execute links base-path aware (#27314) lib: fix capture_logs not thread safe (#27355) web/user: keep configure URL query strings when adding next (#27313) web/flow: refresh WebAuthn challenge on authentication retry (#26616) server, lifecycle: drop idle upstream connections before uvicorn does (#27192) outposts: only write changed permissions, add endpoint to rebuild them (#26928) flows: fix planner not resolving stages causing extra queries (#27320) outposts/proxy: honor X-Forwarded-Host in envoy forward auth (#26888) website/docs: Update wording for internal and external users (#27345) ...
Details
What does this PR change?
Outpost.build_user_permissions()now compares the permissions the outpost's service account needs with the ones its managed role already has, deletes only the stale ones and creates only the missing ones. Missing rows are inserted in a sorted order withignore_conflicts, so two transactions adding the same row don't fail.It also adds
POST /outposts/instances/{uuid}/rebuild_permissions/, which deletes every permission of the outpost's service account and recreates them. It requires permission to change the outpost. The delete only happens after every required permission has been found, so a missing permission doesn't leave the outpost without any.Why is this change needed?
Every save of an outpost provider calls
build_user_permissions()for each of its outposts, which deleted every permission of the outpost's role and recreated them, even when nothing had changed. For an outpost with a few dozen providers, that is more than a thousand row deletes and inserts per provider save.Blueprint applies run in one long transaction (plus a rolled-back validation transaction that does the same saves), so these row locks stay held until the apply ends. When discovery queues many blueprints that touch providers of the same outpost, the parallel applies lock the same permission rows in different orders and PostgreSQL aborts some of them with
deadlock detected.With this change, saving a provider whose required objects didn't change doesn't write to the permission tables at all, so parallel applies no longer contend on those rows. I didn't serialize blueprint applies instead: they would wait on each other's worker threads, and it wouldn't help other parallel saves, such as API clients updating several providers at once.
Saving an outpost still corrects permission rows that drifted from what the outpost needs, but it no longer recreates all of them. The new endpoint keeps that full rebuild available for troubleshooting.
How was this tested?
deadlock detected; with the fix it passes and the outpost has the expected permissions.Linked issues
closes #26924
Checklist
make all)make docs)