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)
m (linking/formatting improved)
 
(9 intermediate revisions by one other user not shown)
Line 3: Line 3:
 
[[Category:Authentication]]
 
[[Category:Authentication]]
  
'''This guide is intended for EPrints 3.2 or later.'''
+
'''This guide is intended for EPrints 3.3 or later,<br/> but the [[Simplified_HTTPS_Configuration | Update]] may be more appropriate for the current version!'''
  
 
'''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.'''
 
'''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 ==
 
== 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.'''
+
Below is a list of variable names described in these instructions and example values of what they might be in a real-world configuration.
 +
{| border="1" cellpadding="10" cellspacing="0"
 +
!Variable
 +
!Example
 +
|-
 +
|EPRINTS_PATH
 +
|/opt/eprints3
 +
|-
 +
|YOUR-REPOSITORY-DOMAIN
 +
|example.eprints.org
 +
|-
 +
|REPOID
 +
|example
 +
|-
 +
|}
  
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.
+
To start setting up your existing archive to work under HTTPS, you must first edit <code>EPRINTS_PATH/archives/REPOID/cfg/cfg.d/10_core.pl</code>. Initially it will probably look something like the configuration directly below,  which is the basic <code>10_core.pl</code> configuration file after you have run <code>EPRINTS_PATH/bin/epadmin create</code> to set up your archive.  Alternatively you could run <code>/opt/eprints3/bin/epadmin config_core REPOID</code> that will prompt you for the following information. It is suggested that you make a backup of the <code>10_core.pl</code> file regardless before proceeding.
  
  $c->{host} = 'your.dnshostname.org';
+
  $c->{host} = 'YOUR-REPOSITORY-DOMAIN';
 
  $c->{port} = 80;
 
  $c->{port} = 80;
 
  $c->{aliases} = [];
 
  $c->{aliases} = [];
Line 20: Line 33:
 
  $c->{http_root} = undef;
 
  $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.
+
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 <code>port</code> and <code>secureport</code> parameters in the config file accordingly.
  
  $c->{host} = 'your.dnshostname.org';
+
  $c->{host} = 'YOUR-REPOSITORY-DOMAIN';
 
  $c->{port} = 80;
 
  $c->{port} = 80;
 
  $c->{aliases} = [];
 
  $c->{aliases} = [];
Line 29: Line 42:
 
  $c->{http_root} = undef;
 
  $c->{http_root} = undef;
  
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:
+
Now, you need to create the directory <code>EPRINTS_PATH/archives/REPOID/ssl/</code> and then edit the file <code>REPOID/ssl/securevhost.conf</code>.  This file should look something like below.  If you are installing EPrints on Debian/Ubuntu based systems you will need to create a symlink <code>logs</code> in <code>/etc/apache2/</code> to point at <code>/var/log/apache2/</code>.
 +
{{Securevhost.conf}}
  
<VirtualHost *:443>
+
It is advised that you keep the SSL key, certificate and chain files in the same directory as <code>securevhost.conf</code>, as this will make it easy if you need to migrate you EPrints repository to a new server in the future.
+
  ServerName your.dnshostname.org:443
+
+
  ErrorLog logs/ssl_error_log
+
  TransferLog logs/ssl_access_log
+
  LogLevel warn
+
+
  SSLEngine on
+
  SSLProtocol all -SSLv2
+
  SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
+
+
  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 ==
 
== 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).
+
Run <code>EPRINTS_PATH/bin/generate_apacheconf --system --replace</code> to generate the secure Apache configuration files.  This will set up the repository configuration file located in the <code>EPRINTS_PATH/cfg/apache_ssl/</code> directory named <code>REPOID.conf</code>.  
  
  
 
== Add the Main Apache Config File to SSL Config ==
 
== 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 setupIn 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.
+
Depending upon the version of EPrints you are running there are a couple files that may be involved.  It is recommended to run <code>EPRINTS_PATH/bin/generate_apacheconf --man</code> or view the source of <code>EPRINTS_PATH/bin/generate_apacheconf</code> file to understand what file(s) need to be set upApache will not yet have been set up to include <code>EPRINTS_PATH/archives/REPOID/ssl/securevhost.conf</code>.   
  
Include /opt/eprints3/archives/[repoid]/var/auto-secure.conf
+
To include this, you will need to find the file that already includes <code>cfg/apache.conf</code>. (For Red Hat/Fedora/CentOS Linux you will need to look in <code>/etc/httpd/</code>For Debian/Ubuntu Linux you will need to look in <code>/etc/apache2/</code>).  Then add the following line afterwards
 
+
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 <tt>/etc/httpd/conf.d/ssl.conf</tt>
+
 
+
=== 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>
+
  
 +
Include EPRINTS_PATH/archives/*/ssl/securevhost.conf
  
 
== Restart Apache to pick up the changes to the Apache configuration ==
 
== 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>:
+
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 <code>root</code> or using <code>sudo</code>:
  
 
=== For Red Hat/Fedora/CentOS Linux ===
 
=== For Red Hat/Fedora/CentOS Linux ===
Line 91: Line 65:
  
 
=== For Debian/Ubuntu Linux ===
 
=== For Debian/Ubuntu Linux ===
 +
Before restarting Apache make sure <code>mod_ssl</code> is enabled:
 +
a2enmod ssl
 +
Then restart Apache:
 
  /etc/init.d/apache2 restart
 
  /etc/init.d/apache2 restart
  
 
== Confirmation ==
 
== 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.
+
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.<br/>N.B. Any task 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.   
+
== HTTPS Only ==
 +
EPrints default HTTPS configuration is usually sufficient for most institutions needs, as there is no absolute 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 <tt>/opt/eprints3/archives/[repoid]/ssl/securevhost.conf</tt> after the <tt>ServerName<//tt> line and then restarting Apache again:
+
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 <code>EPRINTS_PATH/archives/REPOID/ssl/securevhost.conf</code> after the <code>ServerName</code> line and then restarting Apache again:
  
 
  Header set Strict-Transport-Security "max-age=15780000"
 
  Header set Strict-Transport-Security "max-age=15780000"

Latest revision as of 13:31, 6 August 2019

Manual Sections

This guide is intended for EPrints 3.3 or later,
but the Update may be more appropriate for the current version!

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

Below is a list of variable names described in these instructions and example values of what they might be in a real-world configuration.

Variable Example
EPRINTS_PATH /opt/eprints3
YOUR-REPOSITORY-DOMAIN example.eprints.org
REPOID example

To start setting up your existing archive to work under HTTPS, you must first edit EPRINTS_PATH/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 EPRINTS_PATH/bin/epadmin create to set up 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-REPOSITORY-DOMAIN';
$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-REPOSITORY-DOMAIN';
$c->{port} = 80;
$c->{aliases} = [];
$c->{securehost} = $c->{host};
$c->{secureport} = 443;
$c->{http_root} = undef;

Now, you need to create the directory EPRINTS_PATH/archives/REPOID/ssl/ and then edit the file REPOID/ssl/securevhost.conf. This file should look something like below. If you are installing EPrints on Debian/Ubuntu based systems you will need to create a symlink logs in /etc/apache2/ to point at /var/log/apache2/.

<VirtualHost *:443>

  ServerName YOUR-REPOSITORY-DOMAIN: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 EPRINTS_PATH/archives/REPOID/ssl/YOUR-REPOSITORY-DOMAIN.crt
  SSLCertificateKeyFile EPRINTS_PATH/archives/REPOID/ssl/YOUR-REPOSITORY-DOMAIN.key
  SSLCertificateChainFile EPRINTS_PATH/archives/REPOID/ssl/YOUR-REPOSITORY-DOMAIN.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 EPRINTS_PATH/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 EPRINTS_PATH/bin/generate_apacheconf --system --replace to generate the secure Apache configuration files. This will set up the repository configuration file located in the EPRINTS_PATH/cfg/apache_ssl/ directory named REPOID.conf.


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 EPRINTS_PATH/bin/generate_apacheconf --man or view the source of EPRINTS_PATH/bin/generate_apacheconf file to understand what file(s) need to be set up. Apache will not yet have been set up to include EPRINTS_PATH/archives/REPOID/ssl/securevhost.conf.

To include this, you will need to find the file that already includes cfg/apache.conf. (For Red Hat/Fedora/CentOS Linux you will need to look in /etc/httpd/. For Debian/Ubuntu Linux you will need to look in /etc/apache2/). Then add the following line afterwards

Include EPRINTS_PATH/archives/*/ssl/securevhost.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

Before restarting Apache make sure mod_ssl is enabled:

a2enmod ssl

Then restart Apache:

/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 task that require you to be logged in will be redirected to an HTTPS connection otherwise an HTTP request will be used by default.

HTTPS Only

EPrints default HTTPS configuration is usually sufficient for most institutions needs, as there is no absolute 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 EPRINTS_PATH/archives/REPOID/ssl/securevhost.conf after the ServerName line and then restarting Apache again:

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