Skip to content

Commit ebed8de

Browse files
piotr1212deniszh
authored andcommitted
Fix the manhole for Twisted > 16 and Python 3
This probably breaks the manhole for Python 2 and old versions of Twisted.
1 parent d8dbce8 commit ebed8de

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

conf/carbon.conf.example

+7
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,18 @@ WHISPER_FALLOCATE_CREATE = True
294294
# you are familiar with the code. If you are not, please don't
295295
# mess with this, you are asking for trouble :)
296296
#
297+
# You need the bcrypt, cryptography and pyasn1 python modules installed for
298+
# manhole to work.
299+
#
300+
# Generate host keys with:
301+
# `ckeygen -t rsa -f /example/host_keys/ssh_host_key_rsa`
302+
#
297303
# ENABLE_MANHOLE = False
298304
# MANHOLE_INTERFACE = 127.0.0.1
299305
# MANHOLE_PORT = 7222
300306
# MANHOLE_USER = admin
301307
# MANHOLE_PUBLIC_KEY = ssh-rsa AAAAB3NzaC1yc2EAAAABiwAaAIEAoxN0sv/e4eZCPpi3N3KYvyzRaBaMeS2RsOQ/cDuKv11dlNzVeiyc3RFmCv5Rjwn/lQ79y0zyHxw67qLyhQ/kDzINc4cY41ivuQXm2tPmgvexdrBv5nsfEpjs3gLZfJnyvlcVyWK/lId8WUvEWSWHTzsbtmXAF2raJMdgLTbQ8wE=
308+
# MANHOLE_HOST_KEY_DIR = /example/host_keys
302309

303310
# Patterns for all of the metrics this machine will store. Read more at
304311
# http://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol#Bindings

lib/carbon/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
MANHOLE_PORT=7222,
8989
MANHOLE_USER="",
9090
MANHOLE_PUBLIC_KEY="",
91+
MANHOLE_HOST_KEY_DIR="",
9192
RELAY_METHOD='rules',
9293
DYNAMIC_ROUTER=False,
9394
DYNAMIC_ROUTER_MAX_RETRIES=5,

lib/carbon/manhole.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
from twisted.conch.checkers import SSHPublicKeyDatabase
44
from twisted.conch.manhole import Manhole
55
from twisted.conch.manhole_ssh import TerminalRealm, ConchFactory
6+
from twisted.conch.openssh_compat.factory import OpenSSHFactory
67
from twisted.internet import reactor
78
from twisted.application.internet import TCPServer
89

910
from carbon.protocols import CarbonServerProtocol
1011
from carbon.conf import settings
12+
import carbon
1113

14+
from carbon.exceptions import CarbonConfigException
1215

13-
namespace = {}
16+
namespace = {'carbon': carbon}
1417

1518

1619
class PublicKeyChecker(SSHPublicKeyDatabase):
@@ -31,16 +34,27 @@ def createManholeListener():
3134

3235
if settings.MANHOLE_PUBLIC_KEY == 'None':
3336
credChecker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
34-
credChecker.addUser(settings.MANHOLE_USER, '')
37+
credChecker.addUser(settings.MANHOLE_USER.encode('utf-8'),
38+
''.encode('utf-8'))
3539
else:
3640
userKeys = {
37-
settings.MANHOLE_USER: settings.MANHOLE_PUBLIC_KEY,
41+
settings.MANHOLE_USER.encode('utf-8'):
42+
settings.MANHOLE_PUBLIC_KEY.encode('utf-8'),
3843
}
3944
credChecker = PublicKeyChecker(userKeys)
4045

4146
sshPortal = portal.Portal(sshRealm)
4247
sshPortal.registerChecker(credChecker)
4348
sessionFactory = ConchFactory(sshPortal)
49+
50+
# set ssh host keys
51+
if settings.MANHOLE_HOST_KEY_DIR == "":
52+
raise CarbonConfigException("MANHOLE_HOST_KEY_DIR not defined")
53+
openSSHFactory = OpenSSHFactory()
54+
openSSHFactory.dataRoot = settings.MANHOLE_HOST_KEY_DIR
55+
sessionFactory.publicKeys = openSSHFactory.getPublicKeys()
56+
sessionFactory.privateKeys = openSSHFactory.getPrivateKeys()
57+
4458
return sessionFactory
4559

4660

0 commit comments

Comments
 (0)