Skip to content

lib: avoid DNS resolution in fqdn_rand - #25728

Merged
BeryJu merged 1 commit into
goauthentik:mainfrom
joaocfernandes:jfernandes/dl-fqdn-rand-main
Sep 4, 2026
Merged

BeryJu merged 1 commit into
goauthentik:mainfrom
joaocfernandes:jfernandes/dl-fqdn-rand-main

Conversation

@joaocfernandes

@joaocfernandes joaocfernandes commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

Replaces socket.getfqdn() with non-resolving socket.gethostname() in fqdn_rand() and adds regression tests.

Why is this change needed?

DNS resolution could block during startup reconciliation while a database row lock was held, causing a cross-worker lock.

Detail

A DNS failure does not create the database lock; the lock has already been acquired. However, a DNS lookup that stalls or hangs prevents the transaction from completing and releasing that lock.
The synchronous call chain:

  1. embedded_outpost() calls Outpost.objects.update_or_create().
  2. Django enters transaction.atomic() and locks the existing row with select_for_update().
  3. Django calls obj.save() before leaving the transaction.
  4. save() synchronously sends post_save.
  5. authentik’s receiver evaluates instance.schedule_specs.
  6. Outpost.schedule_specs calls fqdn_rand().

Therefore, fqdn_rand() runs while the row lock is held. If its DNS resolution hangs, update_or_create() cannot finish, the transaction remains open, and other workers attempting to update the same row block behind it.

How was this tested?

Added tests for deterministic output, range behavior, and ensuring DNS resolver functions are never called. Black, Ruff, and all six targeted tests pass.


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.

AI was used to determine the issue.
AI wrote all tests.

@netlify

netlify Bot commented Sep 3, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit c283b57
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a99a0f23485930008511a9a
😎 Deploy Preview https://deploy-preview-25728--authentik-integrations.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.

@netlify

netlify Bot commented Sep 3, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit c283b57
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a99a0f20c181a00084f2643
😎 Deploy Preview https://deploy-preview-25728--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.

@joaocfernandes
joaocfernandes marked this pull request as ready for review September 3, 2026 16:37
@joaocfernandes
joaocfernandes requested a review from a team as a code owner September 3, 2026 16:37
@codecov

codecov Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.68%. Comparing base (c8bd1f1) to head (c283b57).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25728      +/-   ##
==========================================
- Coverage   91.71%   91.68%   -0.04%     
==========================================
  Files        1154     1154              
  Lines       73568    73585      +17     
  Branches     4054     4054              
==========================================
- Hits        67474    67466       -8     
- Misses       6052     6077      +25     
  Partials       42       42              
Flag Coverage Δ
conformance 34.36% <10.00%> (-0.01%) ⬇️
e2e 39.00% <10.00%> (-0.01%) ⬇️
integration 30.51% <5.00%> (-0.46%) ⬇️
rust 42.92% <ø> (ø)
unit 91.94% <100.00%> (-1.32%) ⬇️
unit-migrate 93.29% <100.00%> (+2.95%) ⬆️

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.

@BeryJu BeryJu added backport/version-2026.2 Add this label to PRs to backport changes to version-2026.2 backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5 backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 labels Sep 3, 2026
@BeryJu
BeryJu merged commit 85549b0 into goauthentik:main Sep 4, 2026
137 checks passed
@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.8 created: #25758

@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.2 created: #25759

@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.5 created: #25760

BeryJu pushed a commit that referenced this pull request Sep 4, 2026
…-2026.5) (#25760)

lib: avoid DNS resolution in fqdn_rand (#25728)

Co-authored-by: João C. Fernandes <[email protected]>
BeryJu pushed a commit that referenced this pull request Sep 4, 2026
…-2026.2) (#25759)

lib: avoid DNS resolution in fqdn_rand (#25728)

Co-authored-by: João C. Fernandes <[email protected]>
BeryJu pushed a commit that referenced this pull request Sep 4, 2026
…-2026.8) (#25758)

lib: avoid DNS resolution in fqdn_rand (#25728)

Co-authored-by: João C. Fernandes <[email protected]>
kensternberg-authentik added a commit that referenced this pull request Sep 8, 2026
* main: (45 commits)
  enterprise/providers/ws_federation: fix SAML Version casing (#25764)
  web/admin: oauth provider: explain what happens when no signing key is selected (#25756)
  lib/expression: fix PickleError due to resolver match when using ak_call_policy (#25763)
  website/docs: correct authenticator stage deletion behavior (#25070)
  ci: bump docker/setup-qemu-action from 4.2.0 to 4.3.0 (#25749)
  core: bump selenium from 4.47.0 to 4.48.0 (#25745)
  core: bump library/nginx from `db3099a` to `05b8cb6` in /website (#25747)
  admin/files: make file search case-insensitive (#25736)
  core: explicitly check is_active in auth backends (#25729)
  ci: bump helm/kind-action from 1.14.0 to 1.15.0 (#25750)
  core: bump aws-cdk-lib from 2.266.0 to 2.267.0 (#25748)
  lib: avoid DNS resolution in fqdn_rand (#25728)
  website/docs: add instructions on how to collect user attributes during enrollment (#25717)
  core: bump rust-toolchain from 1.98.0 to 1.98.1 (#25740)
  core: bump tower-http from 0.7.0 to 0.7.1 (#25753)
  core: bump cachetools from 7.1.7 to 7.1.8 (#25742)
  core: bump the types group with 2 updates (#25739)
  core: bump psycopg[c,pool] from 3.3.4 to 3.3.5 (#25741)
  website/docs: document ForceAuthn and typed AKQL JSON values (#25079)
  web: fix switches in table toolbars (#25730)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/version-2026.2 Add this label to PRs to backport changes to version-2026.2 backport/version-2026.5 Add this label to PRs to backport changes to version-2026.5 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.

3 participants