Skip to content

Commit f9c6287

Browse files
authored
enable lanching vnc with a user account (#5)
* remove unnecessary sed alias * enable launching vnc with --user and --home * isolate vnc content from home directory in case it's mounted * remove unnecessary support file generation * enforce lxqt-session otherwise if gnome-session is installed it will try to use that by default * force lxqt * prefix arguments with space to avoid collisions * leverage username override
1 parent cc402aa commit f9c6287

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

novnc_rocker/novnc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_snippet(self, cli_args):
4545
return em.expand(snippet, self._env_subs)
4646

4747
def get_docker_args(self, cli_args):
48-
return '-p %s:%s' % (cli_args['novnc_port'], cli_args['novnc_port'])
48+
return ' -p %s:%s' % (cli_args['novnc_port'], cli_args['novnc_port'])
4949

5050
@staticmethod
5151
def register_arguments(parser, defaults={}):

novnc_rocker/templates/turbovnc.conf

-3
This file was deleted.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[program:turbovnc]
2+
command=/opt/TurboVNC/bin/vncserver -SecurityTypes None -fg -nohttpd -geometry 1280x720
3+
autorestart=true
4+
user=@(vnc_user)
5+
environment=USER="@(vnc_user)",HOME="@(vnc_user_home)",TVNC_WM="x-session-manager"

novnc_rocker/templates/turbovnc_snippet.Dockerfile.em

+24-5
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,34 @@ RUN cd /tmp && \
1515
curl -fsSL -O ${SOURCEFORGE}/turbovnc/files/${TURBOVNC_VERSION}/turbovnc_${TURBOVNC_VERSION}_amd64.deb \
1616
-O ${SOURCEFORGE}/virtualgl/files/${VIRTUALGL_VERSION}/virtualgl_${VIRTUALGL_VERSION}_amd64.deb \
1717
&& dpkg -i *.deb \
18-
&& rm -f /tmp/*.deb \
19-
&& sed -i 's/$host:/unix:/g' /opt/TurboVNC/bin/vncserver
18+
&& rm -f /tmp/*.deb
2019

21-
RUN mkdir -p /root/.vnc
22-
RUN echo testpass | /opt/TurboVNC/bin/vncpasswd -f > /root/.vnc/passwd && chmod 600 /root/.vnc/passwd
20+
# Keep vnc content out of
21+
RUN echo '$vncUserDir = "/tmp/@(vnc_user)-vnc";' >> /etc/turbovncserver.conf
22+
# One less file in home to avoid cluttering the home directory
23+
ENV XAUTHORITY "/tmp/@(vnc_user)-vnc/.Xauthority"
24+
# RUN echo '$xstartup = "/tmp/@(vnc_user)-vnc/xstartup.turbovnc;' >> /etc/turbovncserver.conf
25+
26+
# TODO(tfoote) authentication
27+
# RUN echo testpass | /opt/TurboVNC/bin/vncpasswd -f > ~/@(vnc_user)-vnc/passwd && chmod -R 600 ~/@(vnc_user)-vnc/passwd
28+
# TODO(tfoote) needed maybe too? && chown -R @(vnc_user) /tmp/@(vnc_user)-vnc/passwd
2329

2430
RUN mkdir -p /root/.supervisor/conf.d
2531

2632
COPY supervisor.conf /root/.supervisor
2733
COPY turbovnc.conf /root/.supervisor/conf.d
2834

29-
CMD /usr/bin/supervisord -c /root/.supervisor/supervisor.conf
35+
## Make sure we're in lxqt. gnome-session will win if it's installed in the image.
36+
RUN update-alternatives --set x-session-manager /usr/bin/startlxqt
37+
38+
# TODO(tfoote) avoid selecting mutter vs openbox windows manager
39+
40+
# Disable unneeded modules
41+
42+
RUN echo 'Hidden=True' >> /etc/xdg/autostart/lxqt-xscreensaver-autostart.desktop
43+
RUN echo 'Hidden=True' >> /etc/xdg/autostart/lxqt-powermanagement.desktop
44+
RUN echo 'Hidden=True' >> /etc/xdg/autostart/upg-notifier-autostart.desktop
45+
RUN echo 'Hidden=True' >> /etc/xdg/autostart/nm-tray-autostart.desktop
46+
RUN echo 'Hidden=True' >> /etc/xdg/autostart/nm-applet.desktop
47+
48+
CMD @(vnc_user != 'root' ? 'sudo ' ! '')@ /usr/bin/supervisord -c /root/.supervisor/supervisor.conf

novnc_rocker/turbovnc.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import em
2+
import getpass
3+
import os
24
import pkgutil
35
import sys
46
from rocker.extensions import RockerExtension, name_to_argument
@@ -15,6 +17,19 @@ def __init__(self):
1517
self.name = TurboVNC.get_name()
1618
self.SUPPORTED_CODENAMES = ['focal']
1719

20+
def compute_env_subs(self, cli_args):
21+
# TODO(tfoote) this caches cli_args implicitly
22+
if not self._env_subs:
23+
# default case
24+
# Todo evaluate elsewhere?
25+
self._env_subs['vnc_user'] = 'root'
26+
self._env_subs['vnc_user_home'] = '/root'
27+
if 'user' in cli_args:
28+
if cli_args['user']:
29+
self._env_subs['vnc_user'] = cli_args['user_override_name'] if cli_args['user_override_name'] else getpass.getuser()
30+
self._env_subs['vnc_user_home'] = os.path.join('/home/', cli_args['user_override_name']) if cli_args['user_override_name'] else os.path.expanduser('~')
31+
return self._env_subs
32+
1833
def precondition_environment(self, cli_args):
1934
detected_os = detect_os(cli_args['base_image'], print, nocache=cli_args.get('nocache', False))
2035
if detected_os is None:
@@ -32,19 +47,35 @@ def get_preamble(self, cli_args):
3247
return ''
3348

3449
def get_files(self, cli_args):
35-
file_list = ['supervisor.conf', 'turbovnc.conf']
50+
file_list = ['supervisor.conf']
3651
files = {}
3752
for f in file_list:
3853
files['%s' % f] = pkgutil.get_data(
3954
'novnc_rocker',
4055
'templates/%s' % f).decode('utf-8')
56+
template_list = ['turbovnc.conf']
57+
self.compute_env_subs(cli_args)
58+
for f in template_list:
59+
try:
60+
files['%s' % f] = em.expand(
61+
pkgutil.get_data(
62+
'novnc_rocker',
63+
'templates/%s.em' % f).decode('utf-8'),
64+
self._env_subs)
65+
except (NameError, TypeError) as ex:
66+
raise NameError("Failed to evaluate template %s: %s \args are: %s" % (f, ex, self._env_subs))
4167
return files
4268

4369
def get_snippet(self, cli_args):
70+
self.compute_env_subs(cli_args)
4471
snippet = pkgutil.get_data(
4572
'novnc_rocker',
4673
'templates/%s_snippet.Dockerfile.em' % self.name).decode('utf-8')
47-
return em.expand(snippet, self._env_subs)
74+
try:
75+
result = em.expand(snippet, self._env_subs)
76+
except (NameError, TypeError) as ex:
77+
raise NameError("Failed to evaluate snippet for %s: %s. \nargs are: %s" % (self.name, ex, self._env_subs))
78+
return result
4879

4980
def get_docker_args(self, cli_args):
5081
return ''

0 commit comments

Comments
 (0)