Fix manhole auth logic: or → and in Twisted version check#978
Merged
Conversation
Agent-Logs-Url: https://github.com/graphite-project/carbon/sessions/46d004ca-48c0-4184-90eb-31f86efbe2ce Co-authored-by: deniszh <1227222+deniszh@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
deniszh
May 8, 2026 08:23
View session
There was a problem hiding this comment.
Pull request overview
Fixes the manhole authentication gating logic so that password-based auth is only selected when both no public key is configured and the running Twisted version supports that auth path, preventing configured public keys from being ignored on Twisted ≥ 16.1.0.
Changes:
- Update the manhole auth selection condition from
ortoandto avoid bypassing public key auth on newer Twisted.
Comments suppressed due to low confidence (2)
lib/carbon/manhole.py:42
MANHOLE_PUBLIC_KEYdefaults to an empty string (seecarbon.conf.defaults), but this condition only treats the literal string'None'as “unset”. IfENABLE_MANHOLEis enabled without settingMANHOLE_PUBLIC_KEY, this falls into the public-key branch and attemptskeys.Key.fromString(data=b''), which will raise and prevent startup. Consider treating empty/whitespace as unset (and/or normalizing'None') and raising aCarbonConfigExceptionwith a clear message when no key is provided but public-key auth is required (e.g., on older Twisted).
if (settings.MANHOLE_PUBLIC_KEY == 'None' and
twisted.version >= versions.Version('twisted', 16, 1, 0)):
credChecker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
credChecker.addUser(settings.MANHOLE_USER.encode('utf-8'),
''.encode('utf-8'))
else:
lib/carbon/manhole.py:41
- The password-auth branch registers an in-memory user with an empty password (
addUser(..., b'')). Even with the corrected condition, this effectively enables passwordless SSH login forMANHOLE_USERwhenever this branch is selected. Please require an explicit non-empty password (e.g., add a config setting) or enforce that the manhole only binds to loopback when password auth is enabled.
credChecker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
credChecker.addUser(settings.MANHOLE_USER.encode('utf-8'),
''.encode('utf-8'))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The condition gating password-based auth used
or, causing it to bypass public key auth whenever the Twisted version was ≥ 16.1.0 — regardless of whether a public key was configured.Change
lib/carbon/manhole.pylines 37–38: Replaceorwithandso that in-memory password auth is only selected when bothMANHOLE_PUBLIC_KEYis unset and the Twisted version supports it.With the old logic, a configured public key was silently ignored on Twisted ≥ 16.1.0, falling back to unauthenticated password login.