Εισαγωγή
Βήμα 1 - Προετοιμασία του συστήματος
Βήμα 2 - Εγκατάσταση Guacamole
Βήμα 3 - Βελτιστοποίηση και καθαρισμός
Βήμα 4 (επιλογή Α) - Εκτέλεση μόνο σε HTTP
Βήμα 5 (επιλογή Β) - Ρύθμιση του Nginx
Βήμα 6 - Δοκιμάστε τα όλα
συμπέρασμα
Εισαγωγή
Ο στόχος αυτού του σεμιναρίου είναι να απαλλαγούμε από τις δημόσιες συνδέσεις SSH και τις δημόσιες συνδέσεις RDP. Τοποθετώντας όλα αυτά πίσω από έναν πολύ βολικό πελάτη HTML5, μπορούμε να προσθέσουμε ένα επίπεδο ασφάλειας για την πρόσβαση στο cloud μας.
Το Guacamole καταγράφει επίσης οποιαδήποτε απομακρυσμένη πρόσβαση, επομένως η μη εξουσιοδοτημένη πρόσβαση γίνεται πολύ πιο ανιχνεύσιμη.
Σημείωση: Για το Let's encrypt (επιλογή Β) χρειαζόμαστε ένα όνομα τομέα. Εάν δεν έχετε, μπορείτε να παραλείψετε αυτό το βήμα και απλώς να εκτελέσετε την επιλογή A .
Βήμα 1 - Προετοιμασία του συστήματος
Ξεκινήστε περιστρέφοντας ένα VPS στην επιθυμητή ζώνη Vultr. Ένα 1024 MBVPS θα είναι αρκετό, καθώς το Guacamole δεν είναι τόσο απαιτητικό.
Ενεργοποίηση της ιδιωτικής IP
Ξεκινήστε ενεργοποιώντας το ιδιωτικό δίκτυο στο VPS. Αυτό είναι καλά τεκμηριωμένο εδώ
Προετοιμασία του τείχους προστασίας
Πρώτα ας σκληρύνουμε λίγο την εικόνα. Και ας ελέγξουμε αν έχει ufwενεργοποιηθεί η εικόνα που έχει παρασχεθεί .
root@vultr:~# ufw status
Status: inactive
Από προεπιλογή είναι απενεργοποιημένο, επομένως θα χρειαστεί να προσθέσουμε μερικούς κανόνες.
- Κανόνας 1: ssh: Θύρα TCP 22
- Κανόνας 2: http: Θύρα TCP 8080 (προσωρινός κανόνας δοκιμής για το Guacamole)
Ας ξεκινήσουμε με τη διαμόρφωση αυτών των θυρών.
ufw allow 22/tcp
ufw allow 8080/tcp
Στη συνέχεια ενεργοποιήστε το τείχος προστασίας.
ufw enable
Μην ανησυχείτε εάν λάβετε μια προειδοποίηση. Εάν προσθέσατε θύρα 22, δεν θα αντιμετωπίσετε κανένα πρόβλημα.
root@vultr:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
Μόλις ενεργοποιηθεί, ζητήστε την κατάσταση του τείχους προστασίας και θα δούμε τη διαμόρφωση της θύρας μας.
ufw status
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
8080/tcp ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
8080/tcp (v6) ALLOW Anywhere (v6)
Βήμα 2 - Εγκατάσταση Guacamole
Εγκατάσταση όλων των εξαρτήσεων
Πριν ξεκινήσουμε την εγκατάσταση, πρέπει να ενημερώσουμε και να αναβαθμίσουμε το repo. Με πακέτα όπως το Tomcat, το οποίο βασίζεται σε Java, υπάρχει μια συνεχής ροή σφαλμάτων που ανακαλύφθηκαν και των σχετικών διορθώσεων σφαλμάτων. Συνήθως είναι καλή ιδέα να το κάνετε αυτό πρώτα αντί να βιαστείτε απευθείας στην εγκατάστασή μας.
apt-get update
apt-get -y upgrade
Ακολουθούν όλες οι εξαρτήσεις. Το Guacamole έχει αρκετά από αυτά. (Μια πλήρης λίστα με τις εξαρτήσεις και τη λειτουργία τους μπορείτε να βρείτε εδώ ). Ας συνεχίσουμε εγκαθιστώντας τα όλα.
apt-get -y install build-essential tomcat8 freerdp libcairo2-dev libjpeg-turbo8-dev libpng12-dev libossp-uuid-dev libavcodec-dev libavutil-dev libfreerdp-dev libpango1.0-dev libssh2-1-dev libtelnet-dev libvorbis-dev libwebp-dev mysql-server mysql-client mysql-common mysql-utilities libswscale-dev libvncserver-dev libpulse-dev libssl-dev
Όταν το πρόγραμμα εγκατάστασης ζητά έναν κωδικό πρόσβασης root MySQL, δώστε έναν και φροντίστε να τον σημειώσετε. Θα χρησιμοποιήσουμε αυτόν τον κωδικό πρόσβασης αργότερα για να δημιουργήσουμε τη βάση δεδομένων Guacamole.
Λήψη του Guacamole
Τώρα που έχουμε όλες τις εξαρτήσεις μας, μπορούμε να συνεχίσουμε με τη λήψη του Guacamole. Το ίδιο το Guacamole έρχεται κυρίως σε μορφή πηγής και όχι δυαδική. Πρώτα θα μεταφερθούμε στον /tmpφάκελο για να αποφύγουμε την ακαταστασία σε άλλα μέρη του δίσκου. Στη συνέχεια, κατεβάστε όλο τον πηγαίο κώδικα.
Υπάρχουν τέσσερα αρχεία πηγής/δυαδικά για λήψη:
guacamole-0.9.13-incubating.war: Αυτή είναι η διαδικτυακή εφαρμογή. Ένα WARαρχείο είναι ένα συμπιεσμένο πακέτο Ιστού που παρέχει έναν ενιαίο ιστότοπο που φιλοξενείται σε έναν ιστότοπο Tomcat
guacamole-server-0.9.13-incubating.tar.gz: Αυτό το αρχείο θα παρέχει την guacdεφαρμογή υποστήριξης . Αυτό δημιουργεί τις ροές μέσω RDP και SSH.
guacamole-auth-jdbc-0.9.13-incubating.tar.gz: Θα χρησιμοποιήσουμε μια τοπική βάση δεδομένων MySQL, επομένως χρειαζόμαστε τη σχετική εφαρμογή JDBCσύνδεσης.
mysql-connector-java-5.1.43.tar.gz: Χωρίς πρόγραμμα οδήγησης βάσης δεδομένων, η σύνδεση JDBC δεν κάνει τίποτα. Αυτό το αρχείο παρέχεται από την ίδια την ομάδα της MySQL.
Σημείωση: οι λήψεις επιλύθηκαν στον πλησιέστερο διακομιστή .
cd /tmp
wget http://apache.belnet.be/incubator/guacamole/0.9.13-incubating/binary/guacamole-0.9.13-incubating.war
wget http://apache.cu.be/incubator/guacamole/0.9.13-incubating/source/guacamole-server-0.9.13-incubating.tar.gz
wget http://apache.cu.be/incubator/guacamole/0.9.13-incubating/binary/guacamole-auth-jdbc-0.9.13-incubating.tar.gz
wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.43.tar.gz
Μόλις κατεβάσουμε όλα αυτά τα αρχεία, εξαγάγουμε τα tar.gz's.
tar -xzvf guacamole-server-0.9.13-incubating.tar.gz
tar -xzvf guacamole-auth-jdbc-0.9.13-incubating.tar.gz
tar -xzvf mysql-connector-java-5.1.43.tar.gz
Σύνταξη Guacamole
Τώρα που έχουμε εξαγάγει όλο τον πηγαίο κώδικα, ας φτιάξουμε μερικούς guacamoleφακέλους, αυτοί θα χρησιμοποιηθούν από την εφαρμογή guacamole και τις εξαρτήσεις της.
mkdir -p /etc/guacamole/lib
mkdir -p /etc/guacamole/extensions
Όλα είναι έτοιμα για τα νέα μας δυαδικά Guacamole. Μπορούμε τώρα να ξεκινήσουμε τη διαδικασία μεταγλώττισης και εγκατάστασης. Μεταβείτε στον εξαγόμενο φάκελο Guacamole Server.
cd /tmp/guacamole-server-0.9.13-incubating
Ρυθμίστε τις παραμέτρους της εφαρμογής ώστε να δημιουργήσει επίσης ένα init.dαρχείο για την εκτέλεση της ως υπηρεσία αργότερα.
./configure --with-init-dir=/etc/init.d
Η εντολή πρέπει να τελειώνει με ένα «ναι» σε όλες τις βιβλιοθήκες και τα πρωτόκολλα. Εάν όχι, επιστρέψτε και ελέγξτε την εντολή apt-get για να βεβαιωθείτε ότι δεν χάσατε κανένα πακέτο.
------------------------------------------------
guacamole-server version 0.9.13-incubating
------------------------------------------------
Library status:
freerdp ............. yes
pango ............... yes
libavcodec .......... yes
libavutil ........... yes
libssh2 ............. yes
libssl .............. yes
libswscale .......... yes
libtelnet ........... yes
libVNCServer ........ yes
libvorbis ........... yes
libpulse ............ yes
libwebp ............. yes
Protocol support:
RDP ....... yes
SSH ....... yes
Telnet .... yes
VNC ....... yes
Services / tools:
guacd ...... yes
guacenc .... yes
Init scripts: /etc/init.d
Type "make" to compile guacamole-server.
Στη συνέχεια, μεταγλωττίστε και εγκαταστήστε τον διακομιστή Gucamole.
make && make install
Μόλις ολοκληρωθούν όλα αυτά, τρέξτε ldconfigγια να δημιουργήσετε ξανά τη διαδρομή αναζήτησης για βιβλιοθήκες που έχουν προστεθεί.
ldconfig
Συνεχίστε χρησιμοποιώντας systemctlτη ρύθμιση guacd(Guacamole Daemon) για να ξεκινήσετε κατά την εκκίνηση.
systemctl enable guacd
Τα δυαδικά αρχεία Guacamole έχουν πλέον εγκατασταθεί. Τώρα θα ετοιμάσουμε την εφαρμογή web για το Tomcat.
Ξεκινήστε μετακινώντας το warαρχείο στον guacamoleφάκελο που μόλις δημιουργήσαμε, μόλις γίνει αυτό δημιουργήστε έναν λογικό σύνδεσμο στον κατάλογο tomcat για να οδηγείτε στο warαρχείο μας .
cd /tmp
mv guacamole-0.9.13-incubating.war /etc/guacamole/guacamole.war
ln -s /etc/guacamole/guacamole.war /var/lib/tomcat8/webapps/
Τότε χρειαζόμαστε τον σύνδεσμο mysql και το JDBC. Το πρόγραμμα οδήγησης JDBC χρειάζεται στο extensionsφάκελο, η υποδοχή στο libφάκελο.
cp mysql-connector-java-5.1.43/mysql-connector-java-5.1.43-bin.jar /etc/guacamole/lib/
cp guacamole-auth-jdbc-0.9.13-incubating/mysql/guacamole-auth-jdbc-mysql-0.9.13-incubating.jar /etc/guacamole/extensions/
Διαμόρφωση Guacamole και Tomcat
Once the connector and JDBC are in place, we need to edit the tocamt8 file. This file contains a lot of tomcat8 settings, and in our case we need to add the GUACAMOLE_HOME variable at the end of the file.
nano /etc/default/tomcat8
Append with the following.
GUACAMOLE_HOME=/etc/guacamole
Creating the database
Next up is creating the database. Guacamole stores its connection configuration in a database, not inside a file.
Login with the root password you used during the installation.
mysql -u root -p
The first step is to create a database called 'guacamole_db'.
create database guacamole_db;
Then run the create user command. This will create a user with a password mysupersecretpassword, this user will only be able to connect from localhost.
create user 'guacamole_user'@'localhost' identified by "mysupersecretpassword";
Grant CRUD operations to this user for the database guacamole_db.
GRANT SELECT,INSERT,UPDATE,DELETE ON guacamole_db.* TO 'guacamole_user'@'localhost';
Flush privileges and exit the shell.
flush privileges;
exit
Finish up by adding the Guacamole schema to our newly created database.
cat /tmp/guacamole-auth-jdbc-0.9.13-incubating/mysql/schema/*.sql | mysql -u root -p guacamole_db
Once this is done, we need to edit the guacamole.properties file. This file contains our recently created MySQL server configuration.
nano /etc/guacamole/guacamole.properties
Append the MySQL connection details and credentials.
mysql-hostname: localhost
mysql-port: 3306
mysql-database: guacamole_db
mysql-username: guacamole_user
mysql-password: mysupersecretpassword
Finish up by creating a symbolic link to the tomcat share folder, as this is where the WAR file will search these properties.
ln -s /etc/guacamole /usr/share/tomcat8/.guacamole
Testing the setup
End by restarting the tomcat8 server and start the guacd server daemon.
service tomcat8 restart
service guacd start
You can verify by using the status command.
service tomcat8 status
service guacd status
Now you can browse to your VPS on port 8080
http://<yourpublicip>:8080/guacamole/
Use the username guacadmin and the same password guacadmin. This will grant you access to an empty Guacamole server.
Click in the top right corner on your username guacadmin and select Settings. Once you are in the settings page go to the Users tab and select the user guacadmin.
Now change your password to something else or create a new admin user and delete the default guacadmin one.
Step 3 - Fine tuning and cleanup
These are the final steps: cleaning up after you are done.
Delete the downloaded source code and binaries from the /tmp folder.
rm -rf /tmp/guacamole-*
rm -rf /tmp/mysql-connector-java-*
Also, make the Guacamole web application the default one. In the tomcat ecosystem the application that gets the ROOT folder is the one that is started by default when you access the website.
Delete the old ROOT placeholder.
rm -rf /var/lib/tomcat8/webapps/ROOT
And make a symbolic link for the guacamole server to be the ROOT one.
ln -s /var/lib/tomcat8/webapps/guacamole /var/lib/tomcat8/webapps/ROOT
This requires a tomcat restart.
service tomcat8 restart
Step 4 (option A) - Running on HTTP only
- If you are not going to use Let's Encrypt certificates and not use a DNS, execute the actions in this step and afterwards go directly to Step 6. - Option A
- If you want to create a more secure site and you have a DNS ready, you can skip this and go straight to option B (Step 5).
Edit the tomcat8/server.xml file and change the connector port.
nano /etc/tomcat8/server.xml
Search for the Connector port.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443" />
And replace 8080 with 80.
By default, tomcat doesn't allow the binding of ports below 1024. To enable this we need to tell tomcat8 to create authenticated binds.
Edit the default file of tomcat8 and uncomment the AUTHBIND line and use the option yes
nano /etc/default/tomcat8
AUTHBIND=yes
Once this is done, intall authbind.
apt-get install authbind
Configure it so that port 80 can be claimed by tomcat8.
touch /etc/authbind/byport/80
chmod 500 /etc/authbind/byport/80
chown tomcat8 /etc/authbind/byport/80
Allow port 80 through the firewall and delete the rule for 8080.
ufw allow 80/tcp
ufw delete allow 8080/tcp
Restart tomcat.
service tomcat8 restart
That's it, now Guacamole should be running on port 80.
Step 5 (option B) - Setting up Nginx
Installation and configuration of Nginx
Tomcat really isn't one of the best and most robust applications to use with certbot. Luckily Nginx is. We will just to proxy tomcat to Nginx. It uses the out-of-the-box functionality of certbot at the cost of sacrificing a little bit of RAM.
apt-get install nginx
Once installed, edit the default configuration.
nano /etc/nginx/sites-available/default
Delete all example configurations and add the following configuration.
server {
listen 0.0.0.0:80;
proxy_request_buffering off;
proxy_buffering off;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
This will create a proxy for the website running at 8080. Restart Nginx, and enable it at boot.
systemctl restart nginx
systemctl enable nginx
Check if everything is working.
systemctl status nginx
Disable the testing port 8080 and allow traffic on port 80.
ufw allow 80/tcp
ufw delete allow 8080/tcp
Installing Let's Encrypt
Before we can use certbot, we need to add the correct ppa to the system containing our certbot packages.
add-apt-repository ppa:certbot/certbot
Press "ENTER" to accept the configuration change.
Update apt to gather the new packages.
apt-get update
Finally, install the Nginx module for assigning the certificates.
apt-get -y install python-certbot-nginx
Configure Nginx to use certificates
Configure the firewall to allow HTTPS.
ufw allow 443/tcp
Before we can request new certificates, we need a DNS name.
nano /etc/nginx/sites-available/default
Add the following server_name setting.
server_name rdp.example.com;
Change the configuration to reflect this new setting.
server {
server_name rdp.example.com;
listen 0.0.0.0:80;
proxy_request_buffering off;
proxy_buffering off;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
Check if all is working and restart Nginx.
nginx -t
service nginx restart
Now request a certificate with certbot.
certbot --nginx -d rdp.example.com
Δώστε το email σας και συμφωνήστε με τις ερωτήσεις του προγράμματος εγκατάστασης. (Μπορείτε να επιλέξετε με ασφάλεια Noνα μοιραστείτε το email σας.) Το Certbot θα ρωτήσει αυτόματα τι πρέπει να κάνει με HTTPS. Θα χρησιμοποιήσουμε την επιλογή 2: redirect to HTTPS.
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Το τελευταίο πράγμα που θα κάνουμε είναι να ενημερώσουμε τις DHπαραμέτρους. Αυτά είναι, από προεπιλογή, λίγο αδύναμα για τα πρότυπα του 2017.
Δημιουργήστε μερικά νέα.
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
Στη συνέχεια, προσθέστε τα στον προεπιλεγμένο ιστότοπο στο Nginx.
nano /etc/nginx/sites-available/default
Προσθέστε τα στη διαμόρφωση του διακομιστή.
server {
server_name rdp.example.com;
listen 0.0.0.0:80;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
proxy_request_buffering off;
proxy_buffering off;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
Ελέγξτε για σφάλματα.
nginx -t
Εφαρμόστε τις αλλαγές επανεκκινώντας τον διακομιστή.
service nginx restart
Καθαρίστε τον παλιό 8080κανόνα
ufw delete allow 8080/tcp
Σημείωση: εάν λάβετε ένα "502 Bad Gateway", θα χρειαστεί επανεκκίνηση του tomcat8 .
service tomcat8 restart
Αυτόματη ανανέωση πιστοποιητικών
Τα πιστοποιητικά Let's Encrypt απαιτούν ανανέωση. Μπορούμε να δημιουργήσουμε μια θέση εργασίας για αυτό. Ξεκινήστε με την επεξεργασία του crontab.
crontab -e
Προσθέστε την ακόλουθη γραμμή.
00 2 * * * /usr/bin/certbot renew --quiet
Αυτό θα ελέγξει στις 2:00 π.μ. εάν κάποιο πιστοποιητικό χρειάζεται ανανέωση και θα ανανεώσει εάν χρειάζεται.
Βήμα 6 - Δοκιμάστε τα όλα
Μεταβείτε στον διακομιστή σας Guacamole (είτε http://<ip>/ή https://rdp.example.com)).
Για αυτήν τη δοκιμή, θα χρειαστείτε δύο ακόμη περιπτώσεις: ένα Linux VM και ένα άλλο Windows Server 2012 R2 με ενεργοποιημένη ιδιωτική IP και στα δύο.
Προσθήκη της σύνδεσης RDP των Windows
Κάντε κλικ στο " username" στην επάνω δεξιά γωνία και μεταβείτε στο " Settings". Στη συνέχεια, μεταβείτε στο " Connections" και επιλέξτε " New Connection".
Συμπληρώστε τις παρακάτω ρυθμίσεις (μπορείτε να αφήσετε τις υπόλοιπες προεπιλογές).
Name: Windows Server 2012 R2
Location: ROOT
Protocol: RDP
Maximum number of connections: 1
Maximum number of connections per user: 1
Parameters > Hostname: 10.99.0.12
Parameters > Port: 3389
Username: Administrator
Password: <password> (provided by Vultr)
Security mode: Any
Ignore server certificate: <checked>
Πατήστε " save" και επιστρέψτε στην αρχική οθόνη. Τώρα μπορείτε να κάνετε κλικ στη Windows Server 2012 R2σύνδεση και θα γίνει RDP σε αυτό το μηχάνημα.
Προσθήκη της σύνδεσης Linux SSH
Πατήστε " Ctrl+Shift+Alt". Αυτό θα εμφανίσει το μενού στο πλάι. Εδώ μπορείτε να αποσυνδεθείτε ή να εκτελέσετε άλλες διοικητικές εργασίες για το Guacamole.
Κάντε κλικ στο usernameεπάνω μέρος του μενού και μεταβείτε στο " Settings". Στη συνέχεια, μεταβείτε στην Connectionsκαρτέλα " " και επιλέξτε " New Connection".
Συμπληρώστε τις παρακάτω ρυθμίσεις (μπορείτε να αφήσετε τις υπόλοιπες προεπιλογές).
Name: Linux
Location: ROOT
Protocol: SSH
Maximum number of connections: 5
Maximum number of connections per user: 2
Parameters > Hostname: 10.99.0.11
Parameters > Port: 22
Username: root
Password: <password> (provided by Vultr)
Πατήστε " save" και επιστρέψτε στην αρχική οθόνη. Τώρα μπορείτε να κάνετε κλικ σε αυτήν τη σύνδεση που δημιουργήθηκε πρόσφατα και να συνδεθείτε στον διακομιστή σας Linux μέσω SSH.
συμπέρασμα
Τώρα έχετε μια πύλη web RDP/SSH HTML5. Τώρα μπορείτε να τείχος προστασίας στη δημόσια πρόσβαση RDP και SSH της πλατφόρμας σας και να αποκτήσετε πρόσβαση στο περιβάλλον σας από οποιοδήποτε σύγχρονο πρόγραμμα περιήγησης. Για περισσότερες πληροφορίες σχετικά με το τι μπορεί να προσφέρει το Guacamole, υπάρχει ένα υπέροχο βίντεο που δείχνει όλες τις δυνατότητες της πλατφόρμας εδώ .