| 1 | = Shibboleth SPv3 Installation on Ubuntu 22.04 LTS = |
| 2 | |
| 3 | Installation 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 | |
| 7 | Once logged in you need to update the Ubuntu package repository. |
| 8 | |
| 9 | {{{ |
| 10 | sudo apt update |
| 11 | }}} |
| 12 | |
| 13 | Then install the web server. |
| 14 | |
| 15 | {{{ |
| 16 | sudo apt install apache2 |
| 17 | }}} |
| 18 | |
| 19 | Check the apache version |
| 20 | |
| 21 | {{{ |
| 22 | apache2 -v |
| 23 | }}} |
| 24 | |
| 25 | Now 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 | |
| 31 | Then install PHP and related modules for apache server and MariaDB. |
| 32 | |
| 33 | {{{ |
| 34 | sudo apt install php libapache2-mod-php php-mysql |
| 35 | }}} |
| 36 | |
| 37 | To 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 | {{{ |
| 40 | sudo nano /var/www/html/info.php |
| 41 | }}} |
| 42 | |
| 43 | Insert 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 |
| 49 | phpinfo(); |
| 50 | ?> |
| 51 | }}} |
| 52 | |
| 53 | Next go to http://your_IP/info.php URL and you will get page showing the php information, |
| 54 | |
| 55 | = MariaDB DBMS Installation = |
| 56 | |
| 57 | Here we will choose MariaDB DBMS as our database application. Install this using below command. |
| 58 | |
| 59 | {{{ |
| 60 | sudo apt install mariadb-server mariadb-client |
| 61 | }}} |
| 62 | |
| 63 | Once installed check the version, |
| 64 | |
| 65 | {{{ |
| 66 | mysql --version |
| 67 | }}} |
| 68 | |
| 69 | For 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 | |
| 71 | To execute the scripts, |
| 72 | |
| 73 | {{{ |
| 74 | sudo mysql_secure_installation |
| 75 | }}} |
| 76 | |
| 77 | {{{ |
| 78 | |
| 79 | |
| 80 | NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB |
| 81 | SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! |
| 82 | |
| 83 | In order to log into MariaDB to secure it, we'll need the current |
| 84 | password for the root user. If you've just installed MariaDB, and |
| 85 | haven't set the root password yet, you should just press enter here. |
| 86 | |
| 87 | Enter current password for root (enter for none): |
| 88 | OK, successfully used password, moving on... |
| 89 | |
| 90 | Setting the root password or using the unix_socket ensures that nobody |
| 91 | can log into the MariaDB root user without the proper authorisation. |
| 92 | |
| 93 | You already have your root account protected, so you can safely answer 'n'. |
| 94 | |
| 95 | Switch to unix_socket authentication [Y/n] n |
| 96 | ... skipping. |
| 97 | |
| 98 | You already have your root account protected, so you can safely answer 'n'. |
| 99 | |
| 100 | Change the root password? [Y/n] y |
| 101 | New password: |
| 102 | Re-enter new password: |
| 103 | Password updated successfully! |
| 104 | Reloading privilege tables.. |
| 105 | ... Success! |
| 106 | |
| 107 | |
| 108 | By default, a MariaDB installation has an anonymous user, allowing anyone |
| 109 | to log into MariaDB without having to have a user account created for |
| 110 | them. This is intended only for testing, and to make the installation |
| 111 | go a bit smoother. You should remove them before moving into a |
| 112 | production environment. |
| 113 | |
| 114 | Remove anonymous users? [Y/n] y |
| 115 | ... Success! |
| 116 | |
| 117 | Normally, root should only be allowed to connect from 'localhost'. This |
| 118 | ensures that someone cannot guess at the root password from the network. |
| 119 | |
| 120 | Disallow root login remotely? [Y/n] y |
| 121 | ... Success! |
| 122 | |
| 123 | By default, MariaDB comes with a database named 'test' that anyone can |
| 124 | access. This is also intended only for testing, and should be removed |
| 125 | before moving into a production environment. |
| 126 | |
| 127 | Remove test database and access to it? [Y/n] y |
| 128 | - Dropping test database... |
| 129 | ... Success! |
| 130 | - Removing privileges on test database... |
| 131 | ... Success! |
| 132 | |
| 133 | Reloading the privilege tables will ensure that all changes made so far |
| 134 | will take effect immediately. |
| 135 | |
| 136 | Reload privilege tables now? [Y/n] y |
| 137 | ... Success! |
| 138 | |
| 139 | Cleaning up... |
| 140 | |
| 141 | All done! If you've completed all of the above steps, your MariaDB |
| 142 | installation should now be secure. |
| 143 | |
| 144 | Thanks for using MariaDB! |
| 145 | }}} |
| 146 | |
| 147 | To login MariaDB enter below command and use the password entered above. |
| 148 | |
| 149 | {{{ |
| 150 | mysql -u root -p |
| 151 | }}} |
| 152 | |
| 153 | [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web3.png)]] |
| 154 | |
| 155 | To exit type, |
| 156 | |
| 157 | {{{ |
| 158 | exit |
| 159 | }}} |
| 160 | |
| 161 | == Apache Virtual Host Configuration == |
| 162 | |
| 163 | First 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 | |
| 165 | sudo mkdir -p /var/www/lms.your_domain.com/public_html |
| 166 | |
| 167 | We are going to host a moodle site too. Add a configuration file as below. |
| 168 | |
| 169 | {{{ |
| 170 | sudo 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 | |
| 189 | Once we do the configurations we have to enable the created sites as below, |
| 190 | |
| 191 | {{{ |
| 192 | sudo a2ensite lms.your_domain.com |
| 193 | }}} |
| 194 | |
| 195 | Once done, test the configuration for any syntax errors with. |
| 196 | {{{ |
| 197 | sudo apachectl configtest |
| 198 | }}} |
| 199 | |
| 200 | Restart the Apache service for the changes to take effect. |
| 201 | {{{ |
| 202 | sudo systemctl restart apache2 |
| 203 | }}} |
| 204 | |
| 205 | Now we are done with configurations of apache virtual hosting. |
| 206 | |
| 207 | |
| 208 | Here we have to create SSL certificates and assign them to the virtual hosts created. We can create SSL certificates using three methods. |
| 209 | 1. Generate a self-signed certificates (Steps 5 to 9) |
| 210 | 2. Create certificates using Let's Encrypt free SSL service. (Steps 10 to ) |
| 211 | 3. Receiving certificates from a Commercial Certificate Authority. |
| 212 | |
| 213 | As below you can use any of the above methods. Follow the steps as you prefer. |
| 214 | |
| 215 | |
| 216 | 10. Let'sencrypt setup (Skip this step if you already configured SSL with self signed or CA provided certificates) |
| 217 | |
| 218 | |
| 219 | Install Letsencypt and enable https |
| 220 | {{{ |
| 221 | apt install certbot python3-certbot-apache |
| 222 | certbot --apache |
| 223 | }}} |
| 224 | |
| 225 | Go through the interactive prompt and include your server details. Make sure you select redirect option when asked. |
| 226 | |
| 227 | Let'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 | |
| 233 | Then enable the Apache rewrite module. |
| 234 | |
| 235 | sudo a2enmod rewrite |
| 236 | |
| 237 | |
| 238 | == Install Shibboleth Service Provider == |
| 239 | |
| 240 | 3. Install Shibboleth SP: |
| 241 | |
| 242 | {{{ |
| 243 | apt install libapache2-mod-shib ntp --no-install-recommends |
| 244 | }}} |
| 245 | |
| 246 | From this point the location of the SP directory is: /etc/shibboleth |
| 247 | |
| 248 | |
| 249 | == Configure Shibboleth SP == |
| 250 | |
| 251 | 11. Download Federation Metadata Signing Certificate: |
| 252 | {{{ |
| 253 | cd /etc/shibboleth/ |
| 254 | wget https://fr.ac.lk/signedmetadata/metadata-signer -O federation-cert.pem |
| 255 | }}} |
| 256 | |
| 257 | 12. Edit shibboleth2.xml opportunely: |
| 258 | |
| 259 | {{{ |
| 260 | nano /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 | |
| 288 | 13. 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 | |
| 297 | 14. Enable Shibboleth Apache2 configuration: |
| 298 | {{{ |
| 299 | |
| 300 | a2enmod shib |
| 301 | systemctl reload apache2.service |
| 302 | }}} |
| 303 | |
| 304 | 15. Now you are able to reach your Shibboleth SP Metadata on: |
| 305 | {{{ |
| 306 | https://sp.YOUR-DOMAIN/Shibboleth.sso/Metadata (change sp.YOUR-DOMAIN to you SP full qualified domain name) |
| 307 | }}} |
| 308 | |
| 309 | 16. Register your SP on LEARN test federation: |
| 310 | |
| 311 | Go 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 | |
| 313 | You may have to answer several questions describing your service to the federation provider. |
| 314 | |
| 315 | == Configure Moodle as an Federated Resource == |
| 316 | |
| 317 | Here 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 | |
| 320 | 17. Create the Apache2 configuration for Moodle: |
| 321 | |
| 322 | {{{ |
| 323 | nano /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 | |
| 339 | 18. Then enable the site and restart the apache and shibboleth daemon to make changes to effect. |
| 340 | |
| 341 | {{{ |
| 342 | a2ensite mooodle |
| 343 | |
| 344 | systemctl restart shibd |
| 345 | |
| 346 | systemctl restart apache2 |
| 347 | }}} |
| 348 | |
| 349 | Now you may browse to https://sp.YOUR-DOMAIN/moodle and select your IDP to log in. |