I'm setting up a manhole with twisted.conch.manhole, and it works, but gives
this warning:
Can't handle environment variables for SSH avatar
<twisted.conch.manhole_ssh.TerminalUser object at 0x7fef33174f60>:
<twisted.conch.manhole_ssh.TerminalSession object at
0x7fef33174fd0> does not provide ISessionSetEnv interface. It
should be decorated with @implementer(ISession, ISessionSetEnv) to
support env variables.
I've looked at the release notes about #9315
<https://twistedmatrix.com/trac/ticket/9315>, but can't see where in my code to
add @implementer. Here's the code:
def create_shell_server(inputs):
import pwd
# The manhole service
from twisted.conch import manhole, manhole_ssh
from twisted.conch.checkers import IAuthorizedKeysDB, SSHPublicKeyChecker,
readAuthorizedKeyFile
from twisted.conch.ssh import keys
from twisted.cred import portal
from twisted.python.filepath import FilePath
from zope.interface import implementer
# pylint: disable=no-name-in-module
from twisted.application.internet import TCPServer
# pylint: enable=no-name-in-module
@implementer(IAuthorizedKeysDB)
class RunbenchAuthorizedKeysFiles(object):
"""Object that provides SSH public keys.
There is a central file readable only by services that run as
users who have permissions to read it, and users are allowed
to provide their own file for use during development. The
files have fixed names and are not overrideable by inputs or
the environment, because that would make it harder to see
which files a service was actually using.
"""
def getAuthorizedKeys(self, username):
try:
passwd = pwd.getpwnam(bytes_to_native_str(username))
except KeyError:
return ()
def read_keys(filepaths):
for fp in filepaths:
if fp.exists():
try:
with fp.open() as f:
for key in readAuthorizedKeyFile(f,
keys.Key.fromString):
yield key
except (IOError, OSError):
pass
return read_keys([
FilePath(passwd.pw_dir).child('.ssh').child(b'runbench_manhole.pub'),
FilePath(rb_site.runbench.keydir).child(b'manhole_authkeys')
])
checker = SSHPublicKeyChecker(RunbenchAuthorizedKeysFiles())
import gc
from pprint import pprint
namespace = {'sys': sys, 'time': time, 'datetime': datetime,
'gc': gc, 'os': os, 'reactor': reactor,
'runbench': runbench, 'execute': execute,
'pprint': pprint, 'inputs': inputs}
class PF(ServerProtocol):
# pylint: disable=E0202
def protocolFactory(self, *a, **kw):
return manhole.Manhole(namespace)
realm = manhole_ssh.TerminalRealm()
realm.chainedProtocolFactory = PF
mh_portal = portal.Portal(realm)
mh_portal.registerChecker(checker)
cf = manhole_ssh.ConchFactory(mh_portal)
public, private = get_rsa_keys(os.path.join(os.path.dirname(__file__),
'rb_host_rsa'))
cf.publicKeys = {b'ssh-rsa': public}
cf.privateKeys = {b'ssh-rsa': private}
manhole_service = TCPServer(0, cf)
manhole_service.startService()
print('Started manhole service on port',
manhole_service._port._realPortNumber)
What do I need to change to make this work?
Peter.
_______________________________________________
Twisted mailing list -- twisted@python.org
To unsubscribe send an email to twisted-le...@python.org
https://mail.python.org/mailman3/lists/twisted.python.org/
Message archived at
https://mail.python.org/archives/list/twisted@python.org/message/HKQ2RZAU7NCADHUTNOHFSBS24QMYWACM/
Code of Conduct: https://twisted.org/conduct