Difference between revisions of "How to use EPrints with HTTPS"

From EPrints Documentation
Jump to: navigation, search
 
(Fixed files wrong way round for SSLCertificateFile and SSLCertificateKeyFile and added SSL config options that will score A on Qualsys SSL checker.)
(29 intermediate revisions by 9 users not shown)
Line 1: Line 1:
* '''Contributor:''' [[http://www.eprints.org/services/ Tim Miles-Board]]
+
{{manual}}
* '''Eprints version:''' 2.3
 
* '''Purpose:''' Secure EPrints with HTTPS
 
* '''License:''' GNU General Public License
 
  
!!! Add HTTPS Settings
+
[[Category:Authentication]]
  
For each @@ARCHIVEID.xml@@ file, fill in the @@securehost@@ and @@securepath@@ entries.
+
'''This guide is intended for EPrints 3.2 or later.'''
  
Example:
+
'''N.B.''' Setting up your Apache Web server is beyond the scope of this document.  Please see your operating system documentation and the Apache documentation for assistance in setting up Apache in your environment.'''
  
<archive id="demo">
 
    ....
 
    <securehost>secure.mydomain.com</securehost>
 
    <securepath>/demo</securepath>
 
    ....
 
</archive>
 
  
The @@securehost@@ is vhosted on the same server as your EPrints archive(s).
+
== Configuration ==
 +
''' It is assumed that EPrints is installed in the directory <tt>/opt/eprints3/</tt>.  If EPrints is installed elsewhere on your server please substitute as appropriate.'''
  
Secure requests will be of the form https://securehost/securepath.
+
To start setting up your existing archive to work under HTTPS, you must first edit <tt>/opt/eprints3/archives/[repoid]/cfg/cfg.d/10_core.pl</tt>. Initially it will probably look something like the configuration directly below,  which is the basic 10_core.pl configuration file after you have run <tt>/opt/eprints3/bin/epadmin create</tt> to setup your archive.  Alternatively you could run <tt>/opt/eprints3/bin/epadmin config_core [repoid]</tt> that will prompt you for the following information. It is suggested that you make a backup of the 10_core.pl file regardless before proceeding.
  
@@securepath@@ therefore differentiates requests from individual archives.
+
$c->{host} = 'your.dnshostname.org';
 +
$c->{port} = 80;
 +
$c->{aliases} = [];
 +
$c->{securehost} = &#39;&#39;;
 +
$c->{secureport} = 443;
 +
$c->{http_root} = undef;
  
!!! Generate Secure Config
+
Update the file to define the secure host and modify ports as needed.  If your Apache web server is not using the standard ports (80,443) you can adjust the 'port' and 'secureport' parameters in the config file accordingly.
  
  $ bin/generate_apacheconf
+
  $c->{host} = 'your.dnshostname.org';
 +
$c->{port} = 80;
 +
$c->{aliases} = [];
 +
$c->{securehost} = $c->{host};
 +
$c->{secureport} = 443;
 +
$c->{http_root} = undef;
  
As well as the usual apache configuration files, this will generate an @@auto-secure.conf@@ file in each archive's @@cfg@@ directory.
+
Now, you need to create the directory <tt>/opt/eprints3/archives/[repoid]/ssl/</tt> and then edit the file <tt>/opt/eprints3/archives/[repoid]/ssl/securevhost.conf</tt>.  This file should look something like:
  
!!! Set up Secure Host
+
<VirtualHost *:443>
 +
 +
  ServerName your.dnshostname.org:443
 +
 +
  ErrorLog logs/ssl_error_log
 +
  TransferLog logs/ssl_access_log
 +
  LogLevel warn
 +
 +
  SSLEngine on
 +
  SSLProtocol all -SSLv2 -SSLv3
 +
  SSLHonorCipherOrder on
 +
  SSLCipherSuite HIGH:!aNULL:!eNULL:!kECDH:!aDH:!RC4:!3DES:!CAMELLIA:!MD5:!PSK:!SRP:!KRB5:@STRENGTH
 +
 +
  SSLCertificateFile /opt/eprints3/archives/[repoid]/ssl/your.dnshostname.org.crt
 +
  SSLCertificateKeyFile /opt/eprints3/archives/[repoid]/ssl/your.dnshostname.org.key
 +
  SSLCertificateChainFile /opt/eprints3/archives/[repoid]/ssl/your.dnshostname.org.ca-bundle
 +
 +
  SetEnvIf User-Agent ".*MSIE.*" \
 +
    nokeepalive ssl-unclean-shutdown \
 +
    downgrade-1.0 force-response-1.0
 +
 +
  CustomLog logs/ssl_request_log \
 +
    "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
 +
 +
  Include /opt/eprints3/cfg/apache_ssl/[repoid].conf
 +
 +
  PerlTransHandler +EPrints::Apache::Rewrite
 +
 +
</VirtualHost>
  
Under Fedora Core 4, I ran:
+
It is advised that you keep the SSL key, certificate and chain files in the same directory as securevhost.conf, as this will make it easy if you need to migrate you EPrints repository to a new server in the future.
  
  $ yum install mod_ssl
+
== Generate the Apache Configuration File for HTTPS ==
 +
Run <tt>/opt/eprints3/bin/generate_apacheconf --system --replace</tt> to generate the secure Apache configuration files. Depending upon the version of EPrints you are using, it may copy the default template <tt>/opt/eprints3/archives/[repoid]/cfg/lang/en/templates/default.xml</tt> to the template used for HTTPS <tt>/opt/eprints3/archives/[repoid]/cfg/lang/en/templates/secure.xml</tt>.  This will also setup the repository configuration file located in the <tt>/opt/eprints3/cfg/apache_ssl/</tt> directory named [repoid].conf. (N.B. EPrints 3.3 and later now uses default.xml template for both HTTP and HTTPS).
  
This sets up a test SSL server.
 
  
For a production system, you would need to provide the relevant certificates and tweak the mod_ssl config accordingly.
+
== Add the Main Apache Config File to SSL Config ==
 +
Depending upon the version of EPrints you are running there are a couple files that may be involved.  It is recommended to run <tt>/opt/eprints3/bin/generate_apacheconf --man</tt> or view the source of <tt>/opt/eprints3/bin/generate_apacheconf</tt> file to understand what file(s) need to be setup.  In general you will need to place a line like either of the following inside your Apache SSL Virtual Host declaration (most likely found in <tt>/etc/httpd/conf.d/mod_ssl.conf</tt> or <tt>/etc/httpd/conf.d/ssl.conf</tt>).  Make sure that these lines are placed inside the <VirtualHost> Apache directive.
  
http://httpd.apache.org/docs/2.2/mod/mod_ssl.html
+
Include /opt/eprints3/archives/[repoid]/var/auto-secure.conf
  
Include each @@auto-secure.conf@@ file generated by EPrints inside the @@Virtualhost@@ directive.
+
Or
  
For me, this meant editing @@/etc/httpd/conf.d/ssl.conf@@:
+
Include /opt/eprints3/cfg/apache_ssl.conf
  
<VirtualHost _default_:443>
+
=== For Red Hat/Fedora/CentOS Linux ===
    ....
+
Add then add the appropriate Include line above, to the end of <tt>/etc/httpd/conf.d/ssl.conf</tt>
    Include /opt/eprints2/archives/demo/cfg/auto-secure.conf
 
  
  </VirtualHost>
+
=== For Debian/Ubuntu Linux ===
 +
Make sure the SSL Apache module is enabled, by running the following (as root):
 +
  /usr/sbin/a2enmod ssl
 +
Add then add the appropriate <tt>Include</tt> line above, just before the <tt>&lt;/IfModule&gt;</tt> line in <tt>/etc/apache2/mods-enabled/ssl.conf</tt>
  
!!! Create Template for Secure Pages
 
  
I made a copy of @@template-en.xml@@:
+
== Restart Apache to pick up the changes to the Apache configuration ==
 +
Consult your operating system documentation on how to restart service processes but in general you need to run one of the following commands either as <tt>root</tt> or using <tt>sudo</tt>:
  
  $ cp template-en.xml template-secure-en.xml
+
=== For Red Hat/Fedora/CentOS Linux ===
 +
  /sbin/service httpd restart
  
In a multi-language archive, you would need to do this for each language-specific template.
+
=== For Debian/Ubuntu Linux ===
 +
/etc/init.d/apache2 restart
  
It's a good idea to have a visual differentiation between secure and non-secure pages: e.g. I edited @@template-secure-en.xml@@ and added "(SECURE)" to the title of the page.
+
== Confirmation ==
 +
Open your web browser and access your repository via its URL, this should be done over HTTP.  When you click to login you should notice that you will be redirected to an HTTPS connection. N.B. Any tasks that require you to be logged in will be redirected to an HTTPS connection otherwise an HTTP request will be used by default.
  
Some browsers will complain if images/CSS etc. embedded in a secure page are served by the non-secure host. To solve this, I added a new entity to @@ArchiveConfig.pm/sub get_entities@@:
+
EPrints default HTTPS configuration is usually sufficient for most institutions needs, as there is no real need to encrypt the requesting and sending of Open Access research.  However, if you wish to only ever use HTTPS, then follow the instructions for [[HTTPS-only and HSTS]]. HSTS (HTTP Strict Transport Security) ensures that even if the link you click on is for HTTP, your web browser will convert this to HTTPS before making the request.  Meaning you will never send any un-encrypted traffic to EPrints. It also helps reduce the load on your repository's server, as it save it having to do the HTTP to HTTPS redirection.
  
  $entities{ssl_base_url} = "https://" . $archive->get_conf("securehost") . $archive->get_conf("securepath");
+
It is generally a good idea to enable HSTS even on repositories with default HTTPS configuration, in case there are any errant bespoke links that could send private information using HTTP. This can be done by adding the following line to <tt>/opt/eprints3/archives/[repoid]/ssl/securevhost.conf</tt> after the <tt>ServerName<//tt> line and then restarting Apache again:
  
I then replaced image/CSS @@base_url@@s with @@ssl_base_url@@.
+
Header set Strict-Transport-Security "max-age=15780000"

Revision as of 15:30, 20 November 2017

Manual Sections

This guide is intended for EPrints 3.2 or later.

N.B. Setting up your Apache Web server is beyond the scope of this document. Please see your operating system documentation and the Apache documentation for assistance in setting up Apache in your environment.


Configuration

It is assumed that EPrints is installed in the directory /opt/eprints3/. If EPrints is installed elsewhere on your server please substitute as appropriate.

To start setting up your existing archive to work under HTTPS, you must first edit /opt/eprints3/archives/[repoid]/cfg/cfg.d/10_core.pl. Initially it will probably look something like the configuration directly below, which is the basic 10_core.pl configuration file after you have run /opt/eprints3/bin/epadmin create to setup your archive. Alternatively you could run /opt/eprints3/bin/epadmin config_core [repoid] that will prompt you for the following information. It is suggested that you make a backup of the 10_core.pl file regardless before proceeding.

$c->{host} = 'your.dnshostname.org';
$c->{port} = 80;
$c->{aliases} = [];
$c->{securehost} = '';
$c->{secureport} = 443;
$c->{http_root} = undef;

Update the file to define the secure host and modify ports as needed. If your Apache web server is not using the standard ports (80,443) you can adjust the 'port' and 'secureport' parameters in the config file accordingly.

$c->{host} = 'your.dnshostname.org';
$c->{port} = 80;
$c->{aliases} = [];
$c->{securehost} = $c->{host};
$c->{secureport} = 443;
$c->{http_root} = undef;

Now, you need to create the directory /opt/eprints3/archives/[repoid]/ssl/ and then edit the file /opt/eprints3/archives/[repoid]/ssl/securevhost.conf. This file should look something like:

<VirtualHost *:443>

  ServerName your.dnshostname.org:443

  ErrorLog logs/ssl_error_log
  TransferLog logs/ssl_access_log
  LogLevel warn

  SSLEngine on
  SSLProtocol all -SSLv2 -SSLv3
  SSLHonorCipherOrder on
  SSLCipherSuite HIGH:!aNULL:!eNULL:!kECDH:!aDH:!RC4:!3DES:!CAMELLIA:!MD5:!PSK:!SRP:!KRB5:@STRENGTH

  SSLCertificateFile /opt/eprints3/archives/[repoid]/ssl/your.dnshostname.org.crt
  SSLCertificateKeyFile /opt/eprints3/archives/[repoid]/ssl/your.dnshostname.org.key
  SSLCertificateChainFile /opt/eprints3/archives/[repoid]/ssl/your.dnshostname.org.ca-bundle

  SetEnvIf User-Agent ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

  CustomLog logs/ssl_request_log \
    "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

  Include /opt/eprints3/cfg/apache_ssl/[repoid].conf

  PerlTransHandler +EPrints::Apache::Rewrite

</VirtualHost>

It is advised that you keep the SSL key, certificate and chain files in the same directory as securevhost.conf, as this will make it easy if you need to migrate you EPrints repository to a new server in the future.

Generate the Apache Configuration File for HTTPS

Run /opt/eprints3/bin/generate_apacheconf --system --replace to generate the secure Apache configuration files. Depending upon the version of EPrints you are using, it may copy the default template /opt/eprints3/archives/[repoid]/cfg/lang/en/templates/default.xml to the template used for HTTPS /opt/eprints3/archives/[repoid]/cfg/lang/en/templates/secure.xml. This will also setup the repository configuration file located in the /opt/eprints3/cfg/apache_ssl/ directory named [repoid].conf. (N.B. EPrints 3.3 and later now uses default.xml template for both HTTP and HTTPS).


Add the Main Apache Config File to SSL Config

Depending upon the version of EPrints you are running there are a couple files that may be involved. It is recommended to run /opt/eprints3/bin/generate_apacheconf --man or view the source of /opt/eprints3/bin/generate_apacheconf file to understand what file(s) need to be setup. In general you will need to place a line like either of the following inside your Apache SSL Virtual Host declaration (most likely found in /etc/httpd/conf.d/mod_ssl.conf or /etc/httpd/conf.d/ssl.conf). Make sure that these lines are placed inside the <VirtualHost> Apache directive.

Include /opt/eprints3/archives/[repoid]/var/auto-secure.conf

Or

Include /opt/eprints3/cfg/apache_ssl.conf

For Red Hat/Fedora/CentOS Linux

Add then add the appropriate Include line above, to the end of /etc/httpd/conf.d/ssl.conf

For Debian/Ubuntu Linux

Make sure the SSL Apache module is enabled, by running the following (as root):

/usr/sbin/a2enmod ssl

Add then add the appropriate Include line above, just before the </IfModule> line in /etc/apache2/mods-enabled/ssl.conf


Restart Apache to pick up the changes to the Apache configuration

Consult your operating system documentation on how to restart service processes but in general you need to run one of the following commands either as root or using sudo:

For Red Hat/Fedora/CentOS Linux

/sbin/service httpd restart

For Debian/Ubuntu Linux

/etc/init.d/apache2 restart

Confirmation

Open your web browser and access your repository via its URL, this should be done over HTTP. When you click to login you should notice that you will be redirected to an HTTPS connection. N.B. Any tasks that require you to be logged in will be redirected to an HTTPS connection otherwise an HTTP request will be used by default.

EPrints default HTTPS configuration is usually sufficient for most institutions needs, as there is no real need to encrypt the requesting and sending of Open Access research. However, if you wish to only ever use HTTPS, then follow the instructions for HTTPS-only and HSTS. HSTS (HTTP Strict Transport Security) ensures that even if the link you click on is for HTTP, your web browser will convert this to HTTPS before making the request. Meaning you will never send any un-encrypted traffic to EPrints. It also helps reduce the load on your repository's server, as it save it having to do the HTTP to HTTPS redirection.

It is generally a good idea to enable HSTS even on repositories with default HTTPS configuration, in case there are any errant bespoke links that could send private information using HTTP. This can be done by adding the following line to /opt/eprints3/archives/[repoid]/ssl/securevhost.conf after the ServerName<//tt> line and then restarting Apache again:

Header set Strict-Transport-Security "max-age=15780000"