-
Notifications
You must be signed in to change notification settings - Fork 111
feat: add SSH support for remote Docker connections #982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implements secure SSH tunneling to connect to remote Docker hosts using the ssh:// URL scheme. Features enterprise-grade security with mandatory host key verification and comprehensive error handling. Key features: - SSH connector with asyncssh backend - Automatic ~/.ssh/known_hosts detection - SSH config file integration via paramiko - Secure credential handling and environment sanitization - Connection pooling with proper resource cleanup - Comprehensive documentation and examples Security measures: - Enforced host key verification (no bypass options) - Password cleared from memory after connection - Error message sanitization to prevent credential leakage - Dangerous environment variables filtered - Secure temporary socket files with restricted permissions Installation: pip install aiodocker[ssh] Usage: Docker(url="ssh://user@host:port") Includes extensive test coverage and both basic and advanced usage examples.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
- Add types-paramiko to lint dependencies for proper type checking - Fix SSHConfig type annotation for import fallback - Correct connect method return type to match parent class (Connection) - Add proper import for aiohttp.connector.Connection
- Add type ignore for container variable assignment in SSH example - Fix close method signature compatibility with type ignore override - Ensure compatibility across different aiohttp versions
- Add asyncssh>=2.14.0 and paramiko>=2.9.0 to test dependencies - Ensures SSH tests can run in CI without import errors - Tests all SSH functionality including SSHConnector validation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #982 +/- ##
==========================================
- Coverage 81.57% 76.82% -4.75%
==========================================
Files 24 25 +1
Lines 1422 1575 +153
Branches 190 214 +24
==========================================
+ Hits 1160 1210 +50
- Misses 186 289 +103
Partials 76 76 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinion holds no weight in this project. I added some comments below since I also think this feature is useful and would be interested in having something like this in the project.
I tested this on my Macbook SSH'ing into an external Linux device and this worked with no issues, I also tried changing a few options like removing the known_hosts etc and found the logging output helpful for showing issues.
I assume this PR was written assisted by AI, looking over the code, there are a few instances which feel slightly unnatural. IMO some of the error handling that re-raises a bare Exception could be reworked and this PR does a lot of logging compared to the other areas of the library (not necessarily a bad thing).
As I say, my opinion holds no weight in this project and my views may not align with your personal or the coding styles of the rest of the project, but you may find something useful in the comments :).
| log.warning( | ||
| "Password provided in SSH URL. Consider using SSH key authentication " | ||
| "for better security. Passwords may be exposed in logs or memory dumps." | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can some of these comments be removed, they're clearly AI written and don't really provide much value, I don't think anybody looking at
if not (1 <= self._ssh_port <= 65535):
raise ValueError(f"Invalid SSH port: {self._ssh_port}")would be confused unless they read a comment that says # Validate port range.
There are also a bunch of comments which say things along the lines of ... (like docker-py) which are again pretty clearly left from an AI responding to prompting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the comment itself is AI assisted, the motivation was not.
Using password in SSH url is supported, but discouraged for security reasons, and documented as is. I thought we could warn users about it when a password in url is detected.
docker-py references, well, this implementation was inspired in docker-py's ssh implementation. Thought it'll justify why these code blocks were there. I'm ok with removing it if it is irrelevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re validating port range, I had a second thought motivated by your comment and it is indeed not the responsibility of this library to validate the port. Removed the block.
Co-authored-by: Harry <[email protected]>
for more information, see https://pre-commit.ci
What do these changes do?
This PR adds comprehensive SSH support to aiodocker, enabling secure connections to remote Docker hosts using the
ssh://URL scheme. The implementation includes:Core Features
SSHConnectorclass built onasyncsshfor secure tunnelingssh://user@host:port)paramikofor seamless integration with existing SSH setupsSecurity Features
~/.ssh/known_hostsDeveloper Experience
Are there changes in behavior for the user?
New functionality only - no breaking changes:
ssh://user@host:portURLspip install aiodocker[ssh]for SSH supportfrom aiodocker.ssh import SSHConnectorfor advanced usageUsage examples:
Related issue number
This implements a new feature request for SSH connectivity. No specific issue number - this is a proactive enhancement to support remote Docker management use cases.
Checklist
CONTRIBUTORS.txtchangesfolder<issue_id>.<type>for example (588.bug)issue_idchange it to the pr id after creating the pr.feature: Signifying a new feature..bugfix: Signifying a bug fix..doc: Signifying a documentation improvement..removal: Signifying a deprecation or removal of public API..misc: A ticket has been closed, but it is not of interest to users.Implementation Details
Files Added:
aiodocker/ssh.py- Core SSH connector implementation (300+ lines)docs/ssh.rst- Comprehensive SSH documentationexamples/ssh_example.py- Basic usage exampleexamples/ssh_example_advanced.py- Advanced CLI example with comprehensive operationstests/test_ssh.py- Complete test suite for SSH functionalityFiles Modified:
aiodocker/docker.py- Added SSH URL scheme support in Docker class constructordocs/index.rst- Added SSH documentation to navigationpyproject.toml- Added optional SSH dependencies (asyncssh>=2.14.0,paramiko>=2.9.0)CONTRIBUTORS.txt- Added Darwin MonroySecurity Considerations:
Testing:
News Fragment:
changes/982.feature