Skip to content

outposts: close docker client connection on exit - #28067

Merged
BeryJu merged 1 commit into
goauthentik:mainfrom
bate:outposts/docker-client-close
Nov 24, 2026
Merged

BeryJu merged 1 commit into
goauthentik:mainfrom
bate:outposts/docker-client-close

Conversation

@bate

@bate bate commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

DockerClient.__exit__ now calls self.close() before it removes its temporary TLS and SSH files.

Why is this change needed?

authentik.outposts.controllers.docker.DockerClient overrides docker.DockerClient.__exit__, which is where docker-py closes the connection. For ssh:// service connections, every run of outpost_service_connection_monitor, and of outpost_controller via BaseController.__exit__, leaves a paramiko session and its transport thread open. On my 2026.8.5 instance the worker had 363 threads and 350 established SSH sessions to the outpost host after 3.5 days, and it used 60–90% CPU while it had almost nothing to do.

How was this tested?

I added test_client_exit_closes_connection. Against the 2026.8.5 image it fails without the change and passes with it. I haven't run the full make all locally.

I've also run the same change in production on 2026.8.6 since 2026-11-24 (patched at worker start). After nine monitor runs the worker had 14 threads, used about 1.4% CPU, and had one SSH session open per outpost host. Its local port changed between runs, so the earlier sessions had been closed.

Not in this PR: DockerInlineSSH.cleanup() never removes a block at the top of ~/.ssh/config, because start = 0 doubles as "not found". On my instance the file had grown to 636 blocks. I can send a separate PR for that.

Linked issues

closes #16747

AI usage

I used Claude Code to trace the leak on my server, write the change and the test, and draft this description. I reviewed the diff and checked the behaviour on my own instance.


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.

DockerClient overrides docker.DockerClient.__exit__ to clean up its
temporary TLS and SSH files, but never calls close(), which is what the
upstream __exit__ does. For ssh:// service connections every
outpost_service_connection_monitor and outpost_controller run therefore
leaves a paramiko session and its transport thread behind. On my
instance the worker held 363 threads and 350 SSH sessions to the outpost
host after 3.5 days and used 60-90% CPU while idle.

closes goauthentik#16747
@bate
bate requested a review from a team as a code owner November 24, 2026 10:04
@netlify

netlify Bot commented Nov 24, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 833c891
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6b05613ffe8fa86976566086
😎 Deploy Preview https://deploy-preview-28067--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 Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.30%. Comparing base (542da4f) to head (833c891).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #28067      +/-   ##
==========================================
- Coverage   93.34%   93.30%   -0.05%     
==========================================
  Files        1251     1251              
  Lines       89809    89819      +10     
  Branches     4967     4967              
==========================================
- Hits        83833    83806      -27     
- Misses       5911     5948      +37     
  Partials       65       65              
Flag Coverage Δ
conformance 29.52% <0.00%> (-0.01%) ⬇️
e2e 33.81% <0.00%> (-0.20%) ⬇️
integration 26.85% <9.09%> (-0.33%) ⬇️
rust 52.04% <ø> (ø)
unit 94.80% <100.00%> (+<0.01%) ⬆️
unit-migrate 94.81% <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.

@BeryJu
BeryJu merged commit 86d581c into goauthentik:main Nov 24, 2026
162 of 164 checks passed
kensternberg-authentik added a commit that referenced this pull request Nov 25, 2026
* main: (132 commits)
  Web/bugs/icon maintenance 2 (#27889)
  Web/spike/icon identification (#27888)
  root: tidy the generated release changelog (#28079)
  ci: leave rust build-warnings setting default (#28080)
  outposts: close docker client connection on exit (#28067)
  core: bump goauthentik/fips-debian from `7c0cb03` to `137514c` in /lifecycle/container (#28043)
  ci: bump the codeql group across 1 directory with 3 updates (#28045)
  core: bump coverage[toml] from 7.17.3 to 7.17.4 (#28047)
  core: bump pyyaml from 6.0.3 to 6.0.4 (#28048)
  web: bump styleframe from 3.9.1 to 3.9.2 (#28055)
  web: bump @styleframe/theme from 3.8.1 to 3.10.0 (#28058)
  web: bump launch-editor from 2.14.1 to 2.14.2 (#28070)
  web: bump launch-editor from 2.14.1 to 2.14.2 in /website (#28072)
  web: bump uuid from 14.0.1 to 14.0.3 in /website (#28073)
  web: bump fast-uri from 3.1.6 to 3.1.9 in /website (#28074)
  core: bump goauthentik/fips-python from `6d01ed9` to `35f881a` in /lifecycle/container (#28044)
  root: bump version to 2027.2.0-rc1 (#28065)
  web: bump the website-build group across 1 directory with 3 updates (#28054)
  core: bump cachetools from 8.0.0 to 8.0.2 (#28049)
  stages/authenticator_webauthn: Update FIDO MDS3 & Passkey aaguid blobs (#28041)
  ...
kensternberg-authentik added a commit that referenced this pull request Nov 25, 2026
…s-is-not-a-component' into web/bugs/form-errors-is-not-a-component

* refs/remotes/origin/web/bugs/form-errors-is-not-a-component: (136 commits)
  web/maintenance: rename ak-field-errors to renderFormErrors
  Web/bugs/icon maintenance 4 (#28030)
  web/maintenance/icons: Debug, Permissions, Table,
  web/maintenance/icons: ApplicationWizard: replace the cogs with the spinner
  Web/bugs/icon maintenance 2 (#27889)
  Web/spike/icon identification (#27888)
  root: tidy the generated release changelog (#28079)
  ci: leave rust build-warnings setting default (#28080)
  outposts: close docker client connection on exit (#28067)
  core: bump goauthentik/fips-debian from `7c0cb03` to `137514c` in /lifecycle/container (#28043)
  ci: bump the codeql group across 1 directory with 3 updates (#28045)
  core: bump coverage[toml] from 7.17.3 to 7.17.4 (#28047)
  core: bump pyyaml from 6.0.3 to 6.0.4 (#28048)
  web: bump styleframe from 3.9.1 to 3.9.2 (#28055)
  web: bump @styleframe/theme from 3.8.1 to 3.10.0 (#28058)
  web: bump launch-editor from 2.14.1 to 2.14.2 (#28070)
  web: bump launch-editor from 2.14.1 to 2.14.2 in /website (#28072)
  web: bump uuid from 14.0.1 to 14.0.3 in /website (#28073)
  web: bump fast-uri from 3.1.6 to 3.1.9 in /website (#28074)
  core: bump goauthentik/fips-python from `6d01ed9` to `35f881a` in /lifecycle/container (#28044)
  ...
kensternberg-authentik added a commit that referenced this pull request Nov 25, 2026
* main: (194 commits)
  Web/bugs/icon maintenance 2 (#27889)
  Web/spike/icon identification (#27888)
  root: tidy the generated release changelog (#28079)
  ci: leave rust build-warnings setting default (#28080)
  outposts: close docker client connection on exit (#28067)
  core: bump goauthentik/fips-debian from `7c0cb03` to `137514c` in /lifecycle/container (#28043)
  ci: bump the codeql group across 1 directory with 3 updates (#28045)
  core: bump coverage[toml] from 7.17.3 to 7.17.4 (#28047)
  core: bump pyyaml from 6.0.3 to 6.0.4 (#28048)
  web: bump styleframe from 3.9.1 to 3.9.2 (#28055)
  web: bump @styleframe/theme from 3.8.1 to 3.10.0 (#28058)
  web: bump launch-editor from 2.14.1 to 2.14.2 (#28070)
  web: bump launch-editor from 2.14.1 to 2.14.2 in /website (#28072)
  web: bump uuid from 14.0.1 to 14.0.3 in /website (#28073)
  web: bump fast-uri from 3.1.6 to 3.1.9 in /website (#28074)
  core: bump goauthentik/fips-python from `6d01ed9` to `35f881a` in /lifecycle/container (#28044)
  root: bump version to 2027.2.0-rc1 (#28065)
  web: bump the website-build group across 1 directory with 3 updates (#28054)
  core: bump cachetools from 8.0.0 to 8.0.2 (#28049)
  stages/authenticator_webauthn: Update FIDO MDS3 & Passkey aaguid blobs (#28041)
  ...
kensternberg-authentik added a commit that referenced this pull request Nov 25, 2026
* main: (152 commits)
  Web/bugs/icon maintenance 2 (#27889)
  Web/spike/icon identification (#27888)
  root: tidy the generated release changelog (#28079)
  ci: leave rust build-warnings setting default (#28080)
  outposts: close docker client connection on exit (#28067)
  core: bump goauthentik/fips-debian from `7c0cb03` to `137514c` in /lifecycle/container (#28043)
  ci: bump the codeql group across 1 directory with 3 updates (#28045)
  core: bump coverage[toml] from 7.17.3 to 7.17.4 (#28047)
  core: bump pyyaml from 6.0.3 to 6.0.4 (#28048)
  web: bump styleframe from 3.9.1 to 3.9.2 (#28055)
  web: bump @styleframe/theme from 3.8.1 to 3.10.0 (#28058)
  web: bump launch-editor from 2.14.1 to 2.14.2 (#28070)
  web: bump launch-editor from 2.14.1 to 2.14.2 in /website (#28072)
  web: bump uuid from 14.0.1 to 14.0.3 in /website (#28073)
  web: bump fast-uri from 3.1.6 to 3.1.9 in /website (#28074)
  core: bump goauthentik/fips-python from `6d01ed9` to `35f881a` in /lifecycle/container (#28044)
  root: bump version to 2027.2.0-rc1 (#28065)
  web: bump the website-build group across 1 directory with 3 updates (#28054)
  core: bump cachetools from 8.0.0 to 8.0.2 (#28049)
  stages/authenticator_webauthn: Update FIDO MDS3 & Passkey aaguid blobs (#28041)
  ...
kensternberg-authentik added a commit that referenced this pull request Nov 25, 2026
* main: (283 commits)
  Web/bugs/icon maintenance 2 (#27889)
  Web/spike/icon identification (#27888)
  root: tidy the generated release changelog (#28079)
  ci: leave rust build-warnings setting default (#28080)
  outposts: close docker client connection on exit (#28067)
  core: bump goauthentik/fips-debian from `7c0cb03` to `137514c` in /lifecycle/container (#28043)
  ci: bump the codeql group across 1 directory with 3 updates (#28045)
  core: bump coverage[toml] from 7.17.3 to 7.17.4 (#28047)
  core: bump pyyaml from 6.0.3 to 6.0.4 (#28048)
  web: bump styleframe from 3.9.1 to 3.9.2 (#28055)
  web: bump @styleframe/theme from 3.8.1 to 3.10.0 (#28058)
  web: bump launch-editor from 2.14.1 to 2.14.2 (#28070)
  web: bump launch-editor from 2.14.1 to 2.14.2 in /website (#28072)
  web: bump uuid from 14.0.1 to 14.0.3 in /website (#28073)
  web: bump fast-uri from 3.1.6 to 3.1.9 in /website (#28074)
  core: bump goauthentik/fips-python from `6d01ed9` to `35f881a` in /lifecycle/container (#28044)
  root: bump version to 2027.2.0-rc1 (#28065)
  web: bump the website-build group across 1 directory with 3 updates (#28054)
  core: bump cachetools from 8.0.0 to 8.0.2 (#28049)
  stages/authenticator_webauthn: Update FIDO MDS3 & Passkey aaguid blobs (#28041)
  ...
kensternberg-authentik added a commit that referenced this pull request Nov 25, 2026
* web/maint/ak-label: (285 commits)
  Editorial decision: Removed a brand ('optin-monster') from the collection of Icons we support.  I'm not even sure who these people are or if we care: https://optinmonster.com/.  The icon definition was blocking the merge because 'optin' is too close to 'option'.
  Editorial decision: Removed a brand ('optin-monster') from the collection of Icons we support.  I'm not even sure who these people are or if we care: https://optinmonster.com/
  Web/bugs/icon maintenance 2 (#27889)
  Web/spike/icon identification (#27888)
  root: tidy the generated release changelog (#28079)
  ci: leave rust build-warnings setting default (#28080)
  outposts: close docker client connection on exit (#28067)
  core: bump goauthentik/fips-debian from `7c0cb03` to `137514c` in /lifecycle/container (#28043)
  ci: bump the codeql group across 1 directory with 3 updates (#28045)
  core: bump coverage[toml] from 7.17.3 to 7.17.4 (#28047)
  core: bump pyyaml from 6.0.3 to 6.0.4 (#28048)
  web: bump styleframe from 3.9.1 to 3.9.2 (#28055)
  web: bump @styleframe/theme from 3.8.1 to 3.10.0 (#28058)
  web: bump launch-editor from 2.14.1 to 2.14.2 (#28070)
  web: bump launch-editor from 2.14.1 to 2.14.2 in /website (#28072)
  web: bump uuid from 14.0.1 to 14.0.3 in /website (#28073)
  web: bump fast-uri from 3.1.6 to 3.1.9 in /website (#28074)
  core: bump goauthentik/fips-python from `6d01ed9` to `35f881a` in /lifecycle/container (#28044)
  root: bump version to 2027.2.0-rc1 (#28065)
  web: bump the website-build group across 1 directory with 3 updates (#28054)
  ...
kensternberg-authentik added a commit that referenced this pull request Nov 25, 2026
* main: (157 commits)
  web/maint: upgrade ak-label (#24265)
  web: bump jquery from 3.7.1 to 3.8.0 in /web (#28106)
  core: bump goauthentik/selenium from 155.0-ak-0.73.0 to 156.0-ak-0.73.1 in /tests/e2e (#28092)
  core: bump goauthentik/fips-python from `35f881a` to `bd582ea` in /lifecycle/container (#28096)
  core: bump goauthentik/fips-debian from `137514c` to `afdcf15` in /lifecycle/container (#28093)
  web/maintenance: remove Patternfly background-image CSS (#27760)
  Web/bugs/icon maintenance 2 (#27889)
  Web/spike/icon identification (#27888)
  root: tidy the generated release changelog (#28079)
  ci: leave rust build-warnings setting default (#28080)
  outposts: close docker client connection on exit (#28067)
  core: bump goauthentik/fips-debian from `7c0cb03` to `137514c` in /lifecycle/container (#28043)
  ci: bump the codeql group across 1 directory with 3 updates (#28045)
  core: bump coverage[toml] from 7.17.3 to 7.17.4 (#28047)
  core: bump pyyaml from 6.0.3 to 6.0.4 (#28048)
  web: bump styleframe from 3.9.1 to 3.9.2 (#28055)
  web: bump @styleframe/theme from 3.8.1 to 3.10.0 (#28058)
  web: bump launch-editor from 2.14.1 to 2.14.2 (#28070)
  web: bump launch-editor from 2.14.1 to 2.14.2 in /website (#28072)
  web: bump uuid from 14.0.1 to 14.0.3 in /website (#28073)
  ...
kensternberg-authentik added a commit that referenced this pull request Nov 25, 2026
* main: (148 commits)
  website/docs: add release notes for 2026.5.9 (#28148)
  website/docs: add release notes for 2026.8.7 (#28150)
  web/components: clean up ak-event info (#27753)
  web/elements: ak-tooltip (#24418)
  web/maint: upgrade ak-label (#24265)
  web: bump jquery from 3.7.1 to 3.8.0 in /web (#28106)
  core: bump goauthentik/selenium from 155.0-ak-0.73.0 to 156.0-ak-0.73.1 in /tests/e2e (#28092)
  core: bump goauthentik/fips-python from `35f881a` to `bd582ea` in /lifecycle/container (#28096)
  core: bump goauthentik/fips-debian from `137514c` to `afdcf15` in /lifecycle/container (#28093)
  web/maintenance: remove Patternfly background-image CSS (#27760)
  Web/bugs/icon maintenance 2 (#27889)
  Web/spike/icon identification (#27888)
  root: tidy the generated release changelog (#28079)
  ci: leave rust build-warnings setting default (#28080)
  outposts: close docker client connection on exit (#28067)
  core: bump goauthentik/fips-debian from `7c0cb03` to `137514c` in /lifecycle/container (#28043)
  ci: bump the codeql group across 1 directory with 3 updates (#28045)
  core: bump coverage[toml] from 7.17.3 to 7.17.4 (#28047)
  core: bump pyyaml from 6.0.3 to 6.0.4 (#28048)
  web: bump styleframe from 3.9.1 to 3.9.2 (#28055)
  ...
kensternberg-authentik added a commit that referenced this pull request Nov 25, 2026
* main: (232 commits)
  website/docs: add release notes for 2026.5.9 (#28148)
  website/docs: add release notes for 2026.8.7 (#28150)
  web/components: clean up ak-event info (#27753)
  web/elements: ak-tooltip (#24418)
  web/maint: upgrade ak-label (#24265)
  web: bump jquery from 3.7.1 to 3.8.0 in /web (#28106)
  core: bump goauthentik/selenium from 155.0-ak-0.73.0 to 156.0-ak-0.73.1 in /tests/e2e (#28092)
  core: bump goauthentik/fips-python from `35f881a` to `bd582ea` in /lifecycle/container (#28096)
  core: bump goauthentik/fips-debian from `137514c` to `afdcf15` in /lifecycle/container (#28093)
  web/maintenance: remove Patternfly background-image CSS (#27760)
  Web/bugs/icon maintenance 2 (#27889)
  Web/spike/icon identification (#27888)
  root: tidy the generated release changelog (#28079)
  ci: leave rust build-warnings setting default (#28080)
  outposts: close docker client connection on exit (#28067)
  core: bump goauthentik/fips-debian from `7c0cb03` to `137514c` in /lifecycle/container (#28043)
  ci: bump the codeql group across 1 directory with 3 updates (#28045)
  core: bump coverage[toml] from 7.17.3 to 7.17.4 (#28047)
  core: bump pyyaml from 6.0.3 to 6.0.4 (#28048)
  web: bump styleframe from 3.9.1 to 3.9.2 (#28055)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

outpost_service_connection_monitor leaking threads and ssh sessions

2 participants