mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(gstfsd): random password salt, timeouts, loopback-only daemon
- Hash the root password with a random SHA-512 salt instead of the fixed "$6$kgPoiREy". - Talk to gstfsd through one helper with a 120 s socket timeout; an unreachable daemon or a bad reply is an error message, not a 500. - gstfsd refuses to listen on a non-loopback address unless GSTFSD_ALLOW_REMOTE=1: it is an unauthenticated root service. - gstfsd: encode replies (sendall(str) raised TypeError on Python 3, so the success path never worked) and use octal chmod modes. - README: what gstfsd does and how to allow it on a remote compute.
This commit is contained in:
parent
7b53493800
commit
7286ba079d
5 changed files with 135 additions and 21 deletions
|
|
@ -3,16 +3,37 @@
|
|||
# gstfsd - WebVirtCloud daemon for managing VM's filesystem
|
||||
#
|
||||
|
||||
import ipaddress
|
||||
import os
|
||||
import socketserver
|
||||
import json
|
||||
import guestfs
|
||||
import re
|
||||
import sys
|
||||
|
||||
PORT = int(os.environ.get("GSTFSD_PORT", 16510))
|
||||
ADDRESS = os.environ.get("GSTFSD_BIND_HOST", "127.0.0.1")
|
||||
|
||||
|
||||
def is_loopback(host):
|
||||
try:
|
||||
return ipaddress.ip_address(host).is_loopback
|
||||
except ValueError:
|
||||
return host == "localhost"
|
||||
|
||||
|
||||
# gstfsd is an unauthenticated root service that rewrites any VM's
|
||||
# /etc/shadow and authorized_keys, so it only listens on loopback unless
|
||||
# explicitly allowed (ROADMAP S-08).
|
||||
if not is_loopback(ADDRESS) and os.environ.get("GSTFSD_ALLOW_REMOTE") != "1":
|
||||
sys.stderr.write(
|
||||
"gstfsd: refusing to listen on %s (unauthenticated root service). "
|
||||
"Set GSTFSD_ALLOW_REMOTE=1 to allow it on a trusted network.\n" % ADDRESS
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
import guestfs # noqa: E402
|
||||
|
||||
|
||||
class MyTCPServer(socketserver.ThreadingTCPServer):
|
||||
allow_reuse_address = True
|
||||
|
||||
|
|
@ -38,15 +59,15 @@ class MyTCPServerHandler(socketserver.BaseRequestHandler):
|
|||
new_root_hash = "root:" + data['passwd'] + ":"
|
||||
file_shadow_new = re.sub('^root:.*?:', new_root_hash, file_shadow)
|
||||
gfs.write('/etc/shadow', file_shadow_new)
|
||||
gfs.chmod(640, '/etc/shadow')
|
||||
self.request.sendall(json.dumps({'return': 'success'}))
|
||||
gfs.chmod(0o640, '/etc/shadow')
|
||||
self.request.sendall(json.dumps({'return': 'success'}).encode())
|
||||
if data['action'] == 'publickey':
|
||||
if not gfs.is_dir('/root/.ssh'):
|
||||
gfs.mkdir('/root/.ssh')
|
||||
gfs.chmod(700, "/root/.ssh")
|
||||
gfs.chmod(0o700, "/root/.ssh")
|
||||
gfs.write('/root/.ssh/authorized_keys', data['key'])
|
||||
gfs.chmod(600, '/root/.ssh/authorized_keys')
|
||||
self.request.sendall(json.dumps({'return': 'success'}))
|
||||
gfs.chmod(0o600, '/root/.ssh/authorized_keys')
|
||||
self.request.sendall(json.dumps({'return': 'success'}).encode())
|
||||
gfs.umount(part)
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue