Difference between revisions of "Secure App Access"

From Amahi Wiki
Jump to: navigation, search
Line 4: Line 4:
 
heading =WARNING|
 
heading =WARNING|
 
message = This is recommended only for advanced users, proceed with caution.}}
 
message = This is recommended only for advanced users, proceed with caution.}}
 
+
= HTTPS in Amahi 6 and earlier =
 
'''NOTE:''' This has not been tested with Amahi 7. Following this guidance is at your own risk and could break your HDA.  
 
'''NOTE:''' This has not been tested with Amahi 7. Following this guidance is at your own risk and could break your HDA.  
  
Line 55: Line 55:
 
  service httpd restart
 
  service httpd restart
 
* And that's all, you now have 128 bit encryption for AjaXplorer.  Note that when you uninstall the app, you will need to manually remove the '''1026-ajaxplorerhttp.conf''' file you created.
 
* And that's all, you now have 128 bit encryption for AjaXplorer.  Note that when you uninstall the app, you will need to manually remove the '''1026-ajaxplorerhttp.conf''' file you created.
 +
 +
= HTTPS for Amahi 7 apps =
 +
These instructions are for advanced users that wish to set up https access to apps on Amahi 7 (Fedora 19).  Use at your own risk.
 +
 +
== 1. Install prerequisite packages and set up certificates ==
 +
As a root user, run:
 +
<pre>yum install -y openssl mod_ssl
 +
cd /etc/pki/tls/certs
 +
make server.key</pre>
 +
You should get prompts to enter and confirm a passphrase.  Now we want to remove the passphrase from the private key:
 +
<pre>openssl rsa -in server.key -out server.key </pre>
 +
You'll be prompted to add the passphrase again to confirm.  Now we make a certificate server request file
 +
<pre>make server.csr</pre>
 +
You'll now enter the information that will appear on the certificate request.  Make sure that the "Common Name" matches your server domain.
 +
Once you've entered these, you want to generate your private key:
 +
<pre>openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650</pre>
 +
You should get a message saying Signature ok, with the details for the certificate that you just entered, followed by "Getting private key".
 +
 +
==2. Configure your httpd install for ssl==
 +
Still as root, edit /etc/httpd/conf.d/ssl.conf as follows:
 +
<pre>#Line 59: uncomment
 +
DocumentRoot "/var/www/html"
 +
 +
#Line 60: uncomment and specify server name (use your server name)
 +
ServerName www.exampleserver.com:443
 +
 +
#Line 100: specify certificate
 +
SSLCertificateFile /etc/pki/tls/certs/server.crt
 +
 +
#Line 107: specify certification key
 +
SSLCertificateKeyFile /etc/pki/tls/certs/server.key</pre>
 +
 +
==3. Configure the web apps you want to make accessible by SSL==
 +
Go to /etc/httpd/conf.d and edit the conf file for the app you want to move to ssl.  For this example I will use owncloud.  On my HDA the owncloud conf was 1005-owncould8.conf; the number may differ for you.  Remember to back up the original in case you make an error.
 +
<pre>cd /etc/httpd/conf.d
 +
ls -l #check the filename of the relevant conf file.
 +
cp 1005-owncloud8.conf 1006-owncloud8.conf.old
 +
vi 1005-owncloud.conf</pre>
 +
Edit your file to change the virtualhost to port 443, and turn on SSL encryption.  Your files should look something like the following, with appropriate edits to suit your internal and external server names:
 +
<pre><VirtualHost *:443>
 +
 +
        ServerName owncloud8
 +
        ServerAlias owncloud8.home.com
 +
        ServerAlias owncloud8.exampleserver.com
 +
 +
        SSLEngine On
 +
        SSLCertificateFile /etc/pki/tls/certs/server.crt
 +
        SSLCertificateKeyFile /etc/pki/tls/certs/server.key
 +
 +
        DocumentRoot /var/hda/web-apps/owncloud8/html
 +
 +
        <Directory "/var/hda/web-apps/owncloud8/html">
 +
                Options Indexes FollowSymLinks MultiViews
 +
AllowOverride All
 +
Require all granted
 +
        </Directory>
 +
 +
        ErrorLog  /var/hda/web-apps/owncloud8/logs/error_log
 +
        CustomLog /var/hda/web-apps/owncloud8/logs/access_log combined env=!dontlog
 +
 +
</VirtualHost></pre>
 +
 +
Now we need to redirect http requests to the new https instance.  Create a new conf file for the redirect:
 +
<pre>vi 1006-owncloud8http.conf (number may be different for you) and add this code (change the example server to match yours):
 +
<VirtualHost *:80>
 +
        ServerName ajaxplorer
 +
        ServerAlias owncloud8.home.com
 +
        ServerAlias owncloud8.exampleserver.com
 +
        RewriteEngine On
 +
        RewriteCond  %{SERVER_PORT} !^443$
 +
        RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
 +
 +
        ExpiresDefault "access plus 10 years"
 +
 +
        AddOutputFilterByType DEFLATE text/html text/plain text/xml
 +
 +
    </VirtualHost></pre>
 +
 +
Now you need to restart apache:
 +
<pre>systemctl restart httpd.service</pre>
 +
 +
==4. Test==
 +
Direct a browser to the app link and you should now get a https link.  Note that your browsers will all give a warning that the certificate is not trusted because it has not been issued by a proper authority. Once you've accepted the warning, you should have an https connection to your app.
  
 
==== See also ====
 
==== See also ====
 
[[Access HDA over SSL]]
 
[[Access HDA over SSL]]

Revision as of 11:58, 2 May 2015

Warning.png WARNING
This is recommended only for advanced users, proceed with caution.


HTTPS in Amahi 6 and earlier

NOTE: This has not been tested with Amahi 7. Following this guidance is at your own risk and could break your HDA.

This is an example of how to force web app access via HTTPS. For this example, AjaXplorer will be used but this will work with any web app.

  • Go to your config file for apache:
cd /etc/httpd/conf
  • Now it is time to create a key and a crt. It will ask you a few questions, just make sure that the Common Name is the domain name:
openssl genrsa -out filename.key 1024
openssl req -new -key filename.key -x509 -days 1000 -out filename.crt
  • Next open up /etc/httpd/conf/httpd.conf and add the following to the end (skip if you implemented Access HDA over SSL):
NameVirtualHost *:443
yum -y install mod_ssl
  • Find the file that has ajaxplorer in its name (i.e. 1026-ajaxplorer.conf):
cd /etc/httpd/conf.d
  • Edit it to like this (change username.yourhda.com):
<VirtualHost *:443>
        ServerName ajaxplorer
        ServerAlias username.yourhda.com
        SSLEngine On
        SSLCertificateFile /etc/httpd/conf/filename.crt
        SSLCertificateKeyFile /etc/httpd/conf/filename.key

        DocumentRoot /var/hda/web-apps/ajaxplorer/html

        <Directory "/var/hda/web-apps/ajaxplorer/html">
                Options Indexes FollowSymLinks +ExecCGI
                AddHandler fcgid-script .fcg
                AllowOverride AuthConfig
                Order allow,deny
                Allow from all
        </Directory>

    </VirtualHost>
  • Finally create a file called 1026-ajaxplorerhttp.conf (number may be different for you) and add this code (change username.hda.com):
<VirtualHost *:80>
        ServerName ajaxplorer
        ServerAlias username.yourhda.com
        RewriteEngine On
        RewriteCond  %{SERVER_PORT} !^443$
        RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

        ExpiresDefault "access plus 10 years"

        AddOutputFilterByType DEFLATE text/html text/plain text/xml

    </VirtualHost>
  • Now you need to restart apache:
service httpd restart
  • And that's all, you now have 128 bit encryption for AjaXplorer. Note that when you uninstall the app, you will need to manually remove the 1026-ajaxplorerhttp.conf file you created.

HTTPS for Amahi 7 apps

These instructions are for advanced users that wish to set up https access to apps on Amahi 7 (Fedora 19). Use at your own risk.

1. Install prerequisite packages and set up certificates

As a root user, run:

yum install -y openssl mod_ssl
cd /etc/pki/tls/certs 
make server.key

You should get prompts to enter and confirm a passphrase. Now we want to remove the passphrase from the private key:

openssl rsa -in server.key -out server.key 

You'll be prompted to add the passphrase again to confirm. Now we make a certificate server request file

make server.csr

You'll now enter the information that will appear on the certificate request. Make sure that the "Common Name" matches your server domain. Once you've entered these, you want to generate your private key:

openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650

You should get a message saying Signature ok, with the details for the certificate that you just entered, followed by "Getting private key".

2. Configure your httpd install for ssl

Still as root, edit /etc/httpd/conf.d/ssl.conf as follows:

#Line 59: uncomment
DocumentRoot "/var/www/html"

#Line 60: uncomment and specify server name (use your server name)
ServerName www.exampleserver.com:443

#Line 100: specify certificate
SSLCertificateFile /etc/pki/tls/certs/server.crt

#Line 107: specify certification key
SSLCertificateKeyFile /etc/pki/tls/certs/server.key

3. Configure the web apps you want to make accessible by SSL

Go to /etc/httpd/conf.d and edit the conf file for the app you want to move to ssl. For this example I will use owncloud. On my HDA the owncloud conf was 1005-owncould8.conf; the number may differ for you. Remember to back up the original in case you make an error.

cd /etc/httpd/conf.d
ls -l #check the filename of the relevant conf file.
cp 1005-owncloud8.conf 1006-owncloud8.conf.old
vi 1005-owncloud.conf

Edit your file to change the virtualhost to port 443, and turn on SSL encryption. Your files should look something like the following, with appropriate edits to suit your internal and external server names:

<VirtualHost *:443>

        ServerName owncloud8
        ServerAlias owncloud8.home.com 
        ServerAlias owncloud8.exampleserver.com

        SSLEngine On
        SSLCertificateFile /etc/pki/tls/certs/server.crt
        SSLCertificateKeyFile /etc/pki/tls/certs/server.key

        DocumentRoot /var/hda/web-apps/owncloud8/html

        <Directory "/var/hda/web-apps/owncloud8/html">
                Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
        </Directory>

        ErrorLog  /var/hda/web-apps/owncloud8/logs/error_log
        CustomLog /var/hda/web-apps/owncloud8/logs/access_log combined env=!dontlog

</VirtualHost>

Now we need to redirect http requests to the new https instance. Create a new conf file for the redirect:

vi 1006-owncloud8http.conf (number may be different for you) and add this code (change the example server to match yours):
<VirtualHost *:80>
        ServerName ajaxplorer
        ServerAlias owncloud8.home.com 
        ServerAlias owncloud8.exampleserver.com
        RewriteEngine On
        RewriteCond  %{SERVER_PORT} !^443$
        RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

        ExpiresDefault "access plus 10 years"

        AddOutputFilterByType DEFLATE text/html text/plain text/xml

    </VirtualHost>

Now you need to restart apache:

systemctl restart httpd.service

4. Test

Direct a browser to the app link and you should now get a https link. Note that your browsers will all give a warning that the certificate is not trusted because it has not been issued by a proper authority. Once you've accepted the warning, you should have an https connection to your app.

See also

Access HDA over SSL