Skip to content

outposts: only write changed permissions, add endpoint to rebuild them - #26928

Merged
dominic-r merged 9 commits into
mainfrom
dominic/blueprint-apply-deadlock
Oct 29, 2026
Merged

dominic-r merged 9 commits into
mainfrom
dominic/blueprint-apply-deadlock

Conversation

@dominic-r

@dominic-r dominic-r commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

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 with ignore_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?

  • Added a test that saves a provider twice and checks that the outpost's permission rows are kept rather than recreated, and that a permission the outpost doesn't need is removed.
  • Added a test that saves 30 proxy providers of one outpost from four threads, each in its own transactions, as parallel blueprint applies do. Without the fix it fails with deadlock detected; with the fix it passes and the outpost has the expected permissions.
  • Added API tests that the rebuild endpoint removes an extra permission and recreates the needed ones as new rows, that a user without permission to change the outpost is denied, and that an object permission on the outpost is enough. The first test fails when the rebuild doesn't delete the existing rows.
  • Ran the outposts, proxy, LDAP, RADIUS, RAC provider, blueprints and RBAC tests locally; they all pass.
  • I did not apply a large set of real blueprints against a running instance, and I didn't call the rebuild endpoint against a running instance.

Linked issues

closes #26924


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.

@dominic-r
dominic-r requested a review from a team as a code owner October 14, 2026 18:38
@netlify

netlify Bot commented Oct 14, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 8ba6d3c
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6acfcc2e76a037dce71c50df
😎 Deploy Preview https://deploy-preview-26928--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 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.68%. Comparing base (aeed272) to head (8f18a0a).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

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     
Flag Coverage Δ
conformance 31.02% <30.32%> (-0.02%) ⬇️
e2e 35.85% <30.32%> (+0.43%) ⬆️
integration 28.48% <30.32%> (-0.03%) ⬇️
rust 48.61% <ø> (+2.27%) ⬆️
unit 94.25% <100.00%> (+0.01%) ⬆️
unit-migrate 94.25% <100.00%> (+0.01%) ⬆️

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 14, 2026 •

Copy link
Copy Markdown
Contributor

Playwright e2e

Download 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-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-8f18a0a428a2ea606235df1d50ab753c2e1cae29
# Distroless image: AUTHENTIK_TAG=gh-8f18a0a428a2ea606235df1d50ab753c2e1cae29-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-8f18a0a428a2ea606235df1d50ab753c2e1cae29
        # Distroless image: tag: gh-8f18a0a428a2ea606235df1d50ab753c2e1cae29-distroless

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

@BeryJu BeryJu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@dominic-r
dominic-r requested a review from a team as a code owner October 15, 2026 15:43
@dominic-r dominic-r changed the title outposts: only write changed service account permissions outposts: only write changed permissions, add endpoint to rebuild them Oct 15, 2026
Comment thread authentik/outposts/models.py Outdated
"permission_id", flat=True
)
)
existing_obj = {

@BeryJu BeryJu Oct 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typing please

maybe also rename to existing_obj_permissions

@BeryJu BeryJu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit otherwise lgtm

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in authentik Core Oct 29, 2026
@dominic-r
dominic-r enabled auto-merge (squash) October 29, 2026 16:17
@dominic-r
dominic-r merged commit 358eaba into main Oct 29, 2026
171 checks passed
@dominic-r
dominic-r deleted the dominic/blueprint-apply-deadlock branch October 29, 2026 16:45
@github-project-automation github-project-automation Bot moved this from In Progress to Done in authentik Core Oct 29, 2026
kensternberg-authentik added a commit that referenced this pull request Oct 30, 2026
* 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)
  ...
kensternberg-authentik added a commit that referenced this pull request Oct 30, 2026
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Parallel blueprint applies deadlock when they save providers of the same outpost

2 participants