Changes between Initial Version and Version 1 of Iam2023/Agenda/SP-Installation-VHosts


Ignore:
Timestamp:
Mar 30, 2023, 7:52:32 AM (20 months ago)
Author:
admin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Iam2023/Agenda/SP-Installation-VHosts

    v1 v1  
     1= Shibboleth SPv3 Installation on Ubuntu 22.04 LTS =
     2
     3Installation assumes you have already installed Ubuntu Server 22.04 with default configuration and has a public IP connectivity with DNS setup
     4
     5== Install Apache and Web applications ==
     6
     7Once logged in you need to update the Ubuntu package repository.
     8
     9{{{
     10sudo apt update
     11}}}
     12
     13Then install the web server.
     14
     15{{{
     16sudo apt install apache2
     17}}}
     18
     19Check the apache version
     20
     21{{{
     22apache2 -v
     23}}}
     24
     25Now visit your server through the IP address. http://server_ip_address.
     26
     27[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web1.png)]]
     28
     29= PHP Installation =
     30
     31Then install PHP and related modules for apache server and MariaDB.
     32
     33{{{
     34sudo apt install php libapache2-mod-php php-mysql
     35}}}
     36
     37To test that your system is properly configured for PHP, create a PHP script called info.php. Here we will create at the root directory.
     38
     39{{{
     40sudo nano /var/www/html/info.php
     41}}}
     42
     43Insert the following command to show the php information.
     44
     45[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web5.png)]]
     46
     47{{{
     48<?php
     49phpinfo();
     50?>
     51}}}
     52
     53Next go to http://your_IP/info.php URL and you will get page showing the php information,
     54
     55= MariaDB DBMS Installation =
     56
     57Here we will choose MariaDB DBMS as our database application. Install this using below command.
     58
     59{{{
     60sudo apt install mariadb-server mariadb-client
     61}}}
     62
     63Once installed check the version,
     64
     65{{{
     66mysql --version
     67}}}
     68
     69For mysql there is a script that strengthen the mariaDB server security. It is a series of yes no questions which removes initial weaknesses of the server.
     70
     71To execute the scripts,
     72
     73{{{
     74sudo mysql_secure_installation
     75}}}
     76
     77{{{
     78
     79
     80NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
     81      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
     82
     83In order to log into MariaDB to secure it, we'll need the current
     84password for the root user. If you've just installed MariaDB, and
     85haven't set the root password yet, you should just press enter here.
     86
     87Enter current password for root (enter for none):
     88OK, successfully used password, moving on...
     89
     90Setting the root password or using the unix_socket ensures that nobody
     91can log into the MariaDB root user without the proper authorisation.
     92
     93You already have your root account protected, so you can safely answer 'n'.
     94
     95Switch to unix_socket authentication [Y/n] n
     96 ... skipping.
     97
     98You already have your root account protected, so you can safely answer 'n'.
     99
     100Change the root password? [Y/n] y
     101New password:
     102Re-enter new password:
     103Password updated successfully!
     104Reloading privilege tables..
     105 ... Success!
     106
     107
     108By default, a MariaDB installation has an anonymous user, allowing anyone
     109to log into MariaDB without having to have a user account created for
     110them.  This is intended only for testing, and to make the installation
     111go a bit smoother.  You should remove them before moving into a
     112production environment.
     113
     114Remove anonymous users? [Y/n] y
     115 ... Success!
     116
     117Normally, root should only be allowed to connect from 'localhost'.  This
     118ensures that someone cannot guess at the root password from the network.
     119
     120Disallow root login remotely? [Y/n] y
     121 ... Success!
     122
     123By default, MariaDB comes with a database named 'test' that anyone can
     124access.  This is also intended only for testing, and should be removed
     125before moving into a production environment.
     126
     127Remove test database and access to it? [Y/n] y
     128 - Dropping test database...
     129 ... Success!
     130 - Removing privileges on test database...
     131 ... Success!
     132
     133Reloading the privilege tables will ensure that all changes made so far
     134will take effect immediately.
     135
     136Reload privilege tables now? [Y/n] y
     137 ... Success!
     138
     139Cleaning up...
     140
     141All done!  If you've completed all of the above steps, your MariaDB
     142installation should now be secure.
     143
     144Thanks for using MariaDB!
     145}}}
     146
     147To login MariaDB enter below command and use the password entered above.
     148
     149{{{
     150mysql -u root -p
     151}}}
     152
     153[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web3.png)]]
     154
     155To exit type,
     156
     157{{{
     158exit
     159}}}
     160
     161== Apache Virtual Host Configuration ==
     162
     163First we are going to install Moodle LMS and enable Shibboleth login for that. now let's make a directory for hosting Moodle web site.
     164
     165sudo mkdir -p /var/www/lms.your_domain.com/public_html
     166
     167We are going to host a moodle site too. Add a configuration file as below.
     168
     169{{{
     170sudo nano /etc/apache2/sites-available/lms.your_domain.com.conf
     171}}}
     172
     173{{{
     174<VirtualHost *:80>
     175    ServerName lms.your_domain.com
     176    ServerAlias lms.your_domain.com
     177    ServerAdmin webmaster@lms.your_domain.com
     178    DocumentRoot /var/www/lms.your_domain.com/public_html
     179
     180    <Directory /var/www/lms.your_domain.com/public_html>
     181        Options -Indexes +FollowSymLinks
     182    </Directory>
     183
     184    ErrorLog ${APACHE_LOG_DIR}/lms.your_domain.com-error.log
     185    CustomLog ${APACHE_LOG_DIR}/lms.your_domain.com-access.log combined
     186</VirtualHost>
     187}}}
     188
     189Once we do the configurations we have to enable the created sites as below,
     190
     191{{{
     192sudo a2ensite lms.your_domain.com
     193}}}
     194
     195Once done, test the configuration for any syntax errors with.
     196{{{
     197sudo apachectl configtest
     198}}}
     199
     200Restart the Apache service for the changes to take effect.
     201{{{
     202sudo systemctl restart apache2
     203}}}
     204
     205Now we are done with configurations of apache virtual hosting.
     206
     207
     208Here we have to create SSL certificates and assign them to the virtual hosts created. We can create SSL certificates using three methods.
     2091. Generate a self-signed certificates (Steps 5 to 9)
     2102. Create certificates using Let's Encrypt free SSL service. (Steps 10 to )
     2113. Receiving certificates from a Commercial Certificate Authority.
     212
     213As below you can use any of the above methods. Follow the steps as you prefer.
     214
     215
     21610. Let'sencrypt setup (Skip this step if you already configured SSL with self signed or CA provided certificates)
     217
     218
     219Install Letsencypt and enable https
     220{{{
     221apt install certbot python3-certbot-apache
     222certbot --apache
     223}}}
     224
     225Go through the interactive prompt and include your server details. Make sure you select redirect option when asked.
     226
     227Let's forward http traffic to https
     228
     229        RewriteEngine on
     230        RewriteCond %{SERVER_NAME} =lms.YOUR-DOMAIN
     231        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] # port 80 -- > 443 redirection
     232
     233Then enable the Apache rewrite module.
     234
     235sudo a2enmod rewrite
     236
     237
     238== Install Shibboleth Service Provider ==
     239
     2403. Install Shibboleth SP:
     241
     242{{{
     243apt install libapache2-mod-shib ntp --no-install-recommends
     244}}}
     245
     246From this point the location of the SP directory is: /etc/shibboleth
     247
     248
     249== Configure Shibboleth SP ==
     250
     25111. Download Federation Metadata Signing Certificate:
     252{{{
     253cd /etc/shibboleth/
     254wget https://fr.ac.lk/signedmetadata/metadata-signer -O federation-cert.pem
     255}}}
     256
     25712. Edit shibboleth2.xml opportunely:
     258
     259{{{
     260nano /etc/shibboleth/shibboleth2.xml
     261}}}
     262
     263{{{
     264...
     265<ApplicationDefaults entityID="https://sp.YOUR-DOMAIN/shibboleth"
     266        REMOTE_USER="eppn subject-id pairwise-id persistent-id"
     267        cipherSuites="DEFAULT:!EXP:!LOW:!aNULL:!eNULL:!DES:!IDEA:!SEED:!RC4:!3DES:!kRSA:!SSLv2:!SSLv3:!TLSv1:!TLSv1.1">
     268...
     269<Sessions lifetime="28800" timeout="3600" relayState="ss:mem" checkAddress="false" handlerSSL="true" cookieProps="https">
     270...
     271<SSO discoveryProtocol="SAMLDS" discoveryURL="https://fds.ac.lk">
     272   SAML2
     273</SSO>
     274...
     275<MetadataProvider type="XML" url="https://fr.ac.lk/signedmetadata/metadata.xml" legacyOrgName="true" backingFilePath="test-metadata.xml" maxRefreshDelay="7200">
     276     
     277      <MetadataFilter type="Signature" certificate="federation-cert.pem" verifyBackup="false"/>
     278     
     279      <MetadataFilter type="RequireValidUntil" maxValidityInterval="864000" />
     280</MetadataProvider>
     281<!-- Simple file-based resolvers for separate signing/encryption keys. -->
     282<CredentialResolver type="File" use="signing"
     283      key="sp-signing-key.pem" certificate="sp-signing-cert.pem"/>
     284<CredentialResolver type="File" use="encryption"
     285      key="sp-encrypt-key.pem" certificate="sp-encrypt-cert.pem"/>
     286}}}
     287
     28813. Create SP metadata credentials:
     289{{{
     290
     291    /usr/sbin/shib-keygen -n sp-signing -e https://sp.YOUR-DOMAIN/shibboleth
     292    /usr/sbin/shib-keygen -n sp-encrypt -e https://sp.YOUR-DOMAIN/shibboleth
     293    shibd -t /etc/shibboleth/shibboleth2.xml (Check Shibboleth configuration)
     294
     295}}}
     296
     29714. Enable Shibboleth Apache2 configuration:
     298{{{
     299
     300    a2enmod shib
     301    systemctl reload apache2.service
     302}}}
     303
     30415. Now you are able to reach your Shibboleth SP Metadata on:
     305{{{
     306https://sp.YOUR-DOMAIN/Shibboleth.sso/Metadata (change sp.YOUR-DOMAIN to you SP full qualified domain name)
     307}}}
     308
     30916. Register your SP on LEARN test federation:
     310
     311Go to https://liaf.ac.lk/#join and follow the Service provider registration. Once the federation operator approves your request, you will be asked to use the content of your metadata file on federation registry registration.
     312
     313You may have to answer several questions describing your service to the federation provider.
     314
     315== Configure Moodle as an Federated Resource ==
     316
     317Here as a prerequisite you need a working moodle installation at the path https://sp.YOUR-DOMAIN/moodle. For this please refer to the link [https://ws.learn.ac.lk/wiki/Csle2022/Agenda/databaseandweb here].
     318
     319
     32017. Create the Apache2 configuration for Moodle:
     321
     322{{{
     323nano /etc/apache2/sites-available/moodle.conf
     324}}}
     325
     326{{{
     327<Location /moodle>
     328        #ShibRequestSetting applicationId mdl
     329</Location>
     330
     331<Directory /var/www/html/moodle/auth/shibboleth/index.php>
     332        AuthType shibboleth
     333        #ShibRequestSetting applicationId mdl
     334        ShibRequireSession On
     335        require valid-user
     336</Directory>
     337}}}
     338
     33918. Then enable the site and restart the apache and shibboleth daemon to make changes to effect.
     340
     341{{{
     342a2ensite mooodle
     343
     344systemctl restart shibd
     345
     346systemctl restart apache2
     347}}}
     348
     349Now you may browse to https://sp.YOUR-DOMAIN/moodle and select your IDP to log in.