Let op: Tweakers stopt per 2023 met Tweakblogs. In dit artikel leggen we uit waarom we hiervoor hebben gekozen.

No more logmein Free? OpenSource to the rescue! Part 2:Securing Guacamole and exposing it to the Web

Door Tomba op donderdag 6 februari 2014 09:35
Categorieën: Guacamole, Linux, Systeembeheer, Views: 24.017

Don't forget to check out Part 3!

In part 1 of my series on Guacamole we learned how to install Guacamole on an Ubuntu machine. As Guacamole is still being developed it can not be guaranteed that is 100% safe so extra security measures are advisable before opening Guacamole to the big bad internet. This guide shows you how to use Apache2 as a frontend. In a later guide I will also look into securing Apache with ModSecurity and Mod-Spamhaus but this is beyond the scope of this guide. I also have a VPN between my VPS and my internal server (so I don't need to expose my internal network to the internet), this is also out of the scope of this guide. To use this guide you must have succesfully installed Guacamole inside your own network.

As I own a VPS I used the VPS as a frontend proxy (connected through a VPN to my internal Guacamole server) but Apache2 can also run on the same machine as Guacamole. If you want to use this guide in this scenario there is less configuration. In both scenarios I will be using AJP as a communication protocol between Tomcat7 and Apache2.

1. First we need to install mod-proxy to allow Apache to act as a Frontend (proxy) to Tomcat7
apt-get install libapache2-mod-proxy-html

2. Secondly Tomcat7 (on the Guacamole server) needs to be configured for AJP.
To allow AJP connections to Tomcat, you must add a connector to Tomcat's server.xml. There may already be an example connector in your server.xml, in which case all you need to do is uncomment it, editing the port number as desired (in this guide we love it at the default 8009):

vi /etc/tomcat7/server.xml
<Connector port="8009" protocol="AJP/1.3"
redirectPort="8443" />

The URIEncoding="UTF-8" attribute above ensures that connection names, user names, etc. which contain non-latin characters are properly received. If you will be creating connections that have Cyrillic, Chinese, Japanese, etc. characters in the names or parameter values, you should be sure to set this attribute.

Tomcat must be restarted after the connector is added.
service tomcat7 restart

3. Once the connector is open, and Tomcat is listening on the port specified, you can edit your Apache configuration, adding a location which will proxy the Guacamole web application served via AJP by Tomcat:

<Location /guacamole/>
Order allow,deny
Allow from all
ProxyPass ajp://HOSTNAME:8009/guacamole/ max=20 flushpackets=on
ProxyPassReverse ajp://HOSTNAME:8009/guacamole/

The most important thing in this entire section is the option flushpackets=on. Most proxies, including mod_proxy, will buffer all data sent over the connection, waiting until the connection is closed before sending that data to the client. As Guacamole's tunnel will stream data to the client over an open connection, buffering this stream breaks Guacamole's communication.

If the option flushpackets=on is not specified, Guacamole will not work.

4. As AJP does not encrypt and it doesn't use authentication I enabled ufw on my Guacamole machine to only allow communication from the correct host. Don't forget to add exclusions for your SSH access before enabling it though!
ufw allow from [internalLAN] to [internalIP] port 22
ufw allow from [apache-VPN-IP] to [Guacamole-VPN-IP] port 8009
ufw enable

So if your VPN address are (Guacamole) and (Apache2), your internal Guacamole address is and your LAN is the commands are:
ufw allow from to port 22
ufw allow from to port 8009
ufw enable

5. Now it's time to finish configuring Apache2 by adding Apache authentication and HTTPS. To use HTTPS you can either use a selfsigned certificate (causing errors to pop up in your browser), buy a web certificate or use StartSSL to get a free one. This guide assumes you have both the key and the crt available, if you need help with this you can check here.

First create a DocumentRoot folder for the website (in this guide /var/guacamole.example.com)
mkdir /var/guacamole.example.com

Now we will create an Apache2 password file we will be using later to add an extra layer of authentication. Go to http://www.htaccesstools.com/htpasswd-generator/ and generate as many user/password combinations as you see fit and put these in /var/guacamole.example.com/.htpasswd. In this example I used user test with password 123
vi /var/guacamole.example.com/.htpasswd

Next we add a new website to Apache2 by adding a file to /etc/apache2/sites-available. In this example I am working with the domainname guacamole.example.com and a free SSL certificate from StartSSL, change this to the domainname of your server (you can also use the IP address of course) To make sure we always go to HTTPS a permanent redirect is specified on port 80 (HTTP)
The ' Allow from [YOU]' allows the machine with IP address [YOU] to continue without authentication, so if you have a non-dynamic IP address you can use this command to log in just a bit faster. If you have a dynamic IP address just delete that line.
vi /etc/apache2/sites-available/guacamole
<VirtualHost guacamole.example.com:80>
ServerName guacamole.example.com
Redirect permanent / https://guacamole.example.com/
Redirect permanent /guacamole https://guacamole.example.com/guacamole


<VirtualHost guacamole.example.com:443>
NameVirtualHost guacamole.example.com
ServerName guacamole.example.com
DocumentRoot /var/guacamole.example.com

SSLEngine on
SSLCertificateFile /etc/ssl/cert/guacamole.example.com.crt
SSLCertificateKeyFile /etc/ssl/cert/guacamole.example.com.key
SSLCertificateChainFile /etc/ssl/cert/ca.pem
SSLCertificateChainFile /etc/ssl/cert/sub.class1.server.ca.pem

<Location /guacamole/>
ProxyPass ajp:// max=20 flushpackets=on
ProxyPassReverse ajp://
AuthName "Password Protected Area"
AuthUserFile /var/guacamole.example.com/.htpasswd
AuthType Basic
Order deny,allow
Deny from all
require valid-user
Allow from [YOU]
Satisfy Any


Now enable the website by running
a2ensite guacamole.example.com
and restart Apache2 by running
service apache2 restart

You should now be able to open the website https://guacamole.example.com/guacamole and after entering the correct Apache2 username/password see your Guacamole server!

Note: To achieve real end to end encryption you should only use Remote Desktop (which is encrypted by default) or buy a personal license to RealVNC which allows encrypting the communication between Guacamole and VNC. In this example encryption between client and Apache2 server is achieved by HTTPS and encryption between Apache2 and Tomcat7 by using a VPN.

Volgende: No more logmein Free? OpenSource to the rescue! Part 3:Upgrading Guacamole 04-'14 No more logmein Free? OpenSource to the rescue! Part 3:Upgrading Guacamole
Volgende: No more logmein Free? OpenSource to the rescue! Part 1: Installing and configuring Guacamole 01-'14 No more logmein Free? OpenSource to the rescue! Part 1: Installing and configuring Guacamole


Reageren is niet meer mogelijk