Changes between Version 4 and Version 5 of Iam2023/Agenda/SP-Installation-VHosts
- Timestamp:
- Mar 30, 2023, 11:57:18 PM (20 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Iam2023/Agenda/SP-Installation-VHosts
v4 v5 2 2 3 3 In this lab we are going to enable shibboleth login for Moodle and Wordpress web applications. Installation assumes you have already installed Ubuntu Server 22.04 with default configuration and has a public IP connectivity. 4 5 Here we will install applications under below sub domains. 6 7 Moodle => lms.YOUR-DOMAIN 8 Wordpress => wp.YOUR-DOMAIN 9 4 10 5 11 == Install Apache Web Server == … … 175 181 [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web30.png)]] 176 182 177 Now as below edit the hosts file and add you domains with the IP address of your guest VM. 178 179 [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web31.png)]] 183 Now edit the hosts file. 184 185 [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Iam2023/Agenda/SP-Installation-VHosts/web31.png)]] 186 187 Add the below entries to the end of the file. IP is your SP virtual machine public IP given for the lab. 188 189 192.248.6.X wp.YOUR-DOMAIN 190 192.248.6.X lms.YOUR-DOMAIN 180 191 181 192 == Add domains to the hosts file in Linux == … … 208 219 209 220 For Moodle, 221 {{{ 210 222 sudo mkdir -p /var/www/lms.YOUR-DOMAIN/public_html 223 }}} 211 224 212 225 For Wordpress, 226 {{{ 213 227 sudo mkdir -p /var/www/wp.YOUR-DOMAIN/public_html 214 228 }}} 215 229 216 230 Then add relevant apache configuration file for Moodle as below. … … 240 254 }}} 241 255 256 {{{ 242 257 <VirtualHost *:80> 243 258 ServerName wp.YOUR-DOMAIN … … 249 264 CustomLog ${APACHE_LOG_DIR}/wp.YOUR-DOMAIN-access.log combined 250 265 </VirtualHost> 266 }}} 251 267 252 268 Once we do the configurations we have to enable the created sites as below, … … 269 285 Now we should be able to enter above URLs on the browser to check whether they are working. You may get empty web pages since we haven't yet installed our web sites. 270 286 271 287 == Securing Web Sites == 272 288 273 289 Here we have to create SSL certificates and assign them to the virtual hosts created. We can create SSL certificates using three methods. 274 1. Generate a self-signed certificates (Steps 5 to 9)275 2. Create certificates using Let's Encrypt free SSL service. (Steps 10 to )290 1. Generate a self-signed certificates 291 2. Create certificates using Let's Encrypt free SSL service. 276 292 3. Receiving certificates from a Commercial Certificate Authority. 277 293 278 As below you can use any of the above methods. Follow the steps as you prefer. 279 294 Here we will the method 1 and generate self-signed certificates for the domains. 295 296 To generate self signed certificates for the Moodle LMS enter below command. 297 298 {{{ 280 299 openssl req -x509 -newkey rsa:4096 -keyout /etc/ssl/private/ssl-lms.key -out /etc/ssl/certs/ssl-lms.crt -nodes -days 1095 281 282 300 }}} 301 302 Here you will be prompted for some domain related informations and enter them as appropriately. 303 304 {{{ 283 305 You are about to be asked to enter information that will be incorporated 284 306 into your certificate request. … … 295 317 Common Name (e.g. server FQDN or YOUR name) []:lms.dhammikalalantha.com 296 318 Email Address []:lalantha@learn.ac.lk 297 319 }}} 320 321 After generating certificates you have to enable ssl module and restart apache. 322 {{{ 298 323 sudo a2enmod ssl 299 324 300 325 sudo systemctl restart apache2 301 326 }}} 327 328 Since we have now SSL certificates we will use them to enable SSL on our created web sites/domains. 329 330 Go to the directory below and create the SSL configuration file, 331 332 {{{ 333 cd /etc/apache2/sites-available 302 334 nano lms.YOUR-DOMAIN-ssl.conf 303 335 }}} 336 337 {{{ 304 338 <IfModule mod_ssl.c> 305 339 <VirtualHost *:443> … … 312 346 CustomLog ${APACHE_LOG_DIR}/lms-access.log combined 313 347 314 315 348 SSLCertificateFile /etc/ssl/certs/ssl-lms.crt 316 349 SSLCertificateKeyFile /etc/ssl/private/ssl-lms.key 317 350 318 RewriteEngine on319 RewriteCond %{SERVER_NAME} =lms.YOUR-DOMAIN320 RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] # port 80 -- > 443 redirection321 351 </VirtualHost> 322 352 </IfModule> 323 353 }}} 354 355 Then to enable the site 356 357 {{{ 324 358 a2ensite lms.YOUR-DOMAIN-ssl.conf 359 }}} 325 360 326 361 Also create SSL site configuration file for Wordpress site too. 327 362 363 {{{ 328 364 nano wp.YOUR-DOMAIN-ssl.conf 329 365 }}} 366 367 {{{ 330 368 <IfModule mod_ssl.c> 331 369 <VirtualHost *:443> … … 338 376 CustomLog ${APACHE_LOG_DIR}/wp-access.log combined 339 377 340 341 378 SSLCertificateFile /etc/ssl/certs/ssl-lms.crt 342 379 SSLCertificateKeyFile /etc/ssl/private/ssl-lms.key 343 344 RewriteEngine on345 RewriteCond %{SERVER_NAME} =wp.YOUR-DOMAIN346 RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] # port 80 -- > 443 redirection347 380 </VirtualHost> 348 381 </IfModule> 349 382 }}} 383 384 Enable SSL site, 385 386 {{{ 350 387 a2ensite wp.YOUR-DOMAIN-ssl.conf 351 352 10. Let'sencrypt setup (Skip this step if you already configured SSL with self signed or CA provided certificates) 353 354 355 Install Letsencypt and enable https 356 {{{ 357 apt install certbot python3-certbot-apache 358 certbot --apache 359 }}} 360 361 Go through the interactive prompt and include your server details. Make sure you select redirect option when asked. 362 363 Let's forward http traffic to https 364 365 RewriteEngine on 366 RewriteCond %{SERVER_NAME} =lms.YOUR-DOMAIN 367 RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] # port 80 -- > 443 redirection 368 369 Then enable the Apache rewrite module. 370 371 sudo a2enmod rewrite 388 }}} 389 390 Now check whether you can browse the SSL sites in your web browser 391 392 https://lms.YOUR-DOMAIN/ 393 https://wp.YOUR-DOMAIN/ 372 394 373 395 374 396 == Install Shibboleth Service Provider == 375 397 376 3. Install Shibboleth SP: 398 Now we will install Shibboleth SP software. 377 399 378 400 {{{ … … 380 402 }}} 381 403 382 From this point the location of the SP directory is:/etc/shibboleth404 SP configuration directory should be created at /etc/shibboleth 383 405 384 406 385 407 == Configure Shibboleth SP == 386 408 387 11. Download Federation Metadata Signing Certificate:409 Now we need to download Federation Metadata Signing Certificate: 388 410 {{{ 389 411 cd /etc/shibboleth/ … … 391 413 }}} 392 414 393 12. Edit shibboleth2.xml opportunely: 415 Edit shibboleth2.xml opportunely. Make sure to change fields entityID, discoveryURL 394 416 395 417 {{{ … … 397 419 }}} 398 420 399 {{{ 400 ... 401 <ApplicationDefaults entityID="https://lms.YOUR-DOMAIN/shibboleth" 421 Do the modifications as described below. 422 423 Change the ApplicationDefaults tag to your domain name. 424 {{{ 425 <!-- The ApplicationDefaults element is where most of Shibboleth's SAML bits are defined. --> 426 <ApplicationDefaults entityID="https://lms.YOUR-DOMAIN/shibboleth" 402 427 REMOTE_USER="eppn subject-id pairwise-id persistent-id" 403 428 cipherSuites="DEFAULT:!EXP:!LOW:!aNULL:!eNULL:!DES:!IDEA:!SEED:!RC4:!3DES:!kRSA:!SSLv2:!SSLv3:!TLSv1:!TLSv1.1"> 404 ... 405 <Sessions lifetime="28800" timeout="3600" relayState="ss:mem" checkAddress="false" handlerSSL="true" cookieProps="https"> 406 ... 407 <SSO discoveryProtocol="SAMLDS" discoveryURL="https://fds.ac.lk"> 408 SAML2 409 </SSO> 410 ... 411 <MetadataProvider type="XML" url="https://fr.ac.lk/signedmetadata/metadata.xml" legacyOrgName="true" backingFilePath="test-metadata.xml" maxRefreshDelay="7200"> 412 413 <MetadataFilter type="Signature" certificate="federation-cert.pem" verifyBackup="false"/> 414 415 <MetadataFilter type="RequireValidUntil" maxValidityInterval="864000" /> 416 </MetadataProvider> 417 <!-- Simple file-based resolvers for separate signing/encryption keys. --> 418 <CredentialResolver type="File" use="signing" 419 key="sp-signing-key.pem" certificate="sp-signing-cert.pem"/> 420 <CredentialResolver type="File" use="encryption" 421 key="sp-encrypt-key.pem" certificate="sp-encrypt-cert.pem"/> 422 }}} 423 424 13. Create SP metadata credentials for both sites: 429 }}} 430 431 Modify the SSO tag as below. 432 {{{ 433 <SSO discoveryProtocol="SAMLDS" discoveryURL="https://fds.ac.lk"> 434 SAML2 435 </SSO> 436 }}} 437 438 Change the MetadataProvider section as well. 439 {{{ 440 <MetadataProvider type="XML" url="https://fr.ac.lk/signedmetadata/metadata.xml" legacyOrgName="true" backingFilePath="test-metadata.xml" maxRefreshDelay> 441 442 <MetadataFilter type="Signature" certificate="federation-cert.pem" verifyBackup="false"/> 443 444 <MetadataFilter type="RequireValidUntil" maxValidityInterval="864000" /> 445 </MetadataProvider> 446 }}} 447 448 Change the key and certificate fields as given. We will later generate these keys and certificates. 449 {{{ 450 <!-- Simple file-based resolvers for separate signing/encryption keys. --> 451 <CredentialResolver type="File" use="signing" 452 key="lms-signing-key.pem" certificate="lms-signing-cert.pem"/> 453 <CredentialResolver type="File" use="encryption" 454 key="lms-encrypt-key.pem" certificate="lms-encrypt-cert.pem"/> 455 }}} 456 457 Add below section just before the </ApplicationDefaults> tag. 458 {{{ 459 <ApplicationOverride id="wp" entityID="https://wp.YOUR-DOMAIN/shibboleth"> 460 <CredentialResolver type="File" use="signing" 461 key="wp-signing-key.pem" certificate="wp-signing-cert.pem"/> 462 <CredentialResolver type="File" use="encryption" 463 key="wp-encrypt-key.pem" certificate="wp-encrypt-cert.pem"/> 464 </ApplicationOverride> 465 }}} 466 467 468 Create SP metadata credentials for both sites: 425 469 {{{ 426 470 … … 431 475 /usr/sbin/shib-keygen -n wp-encrypt -e https://wp.YOUR-DOMAIN/shibboleth 432 476 433 shibd -t /etc/shibboleth/shibboleth2.xml (Check Shibboleth configuration) 434 477 }}} 478 479 Now check the shibboleth configuration, 480 {{{ 481 shibd -t /etc/shibboleth/shibboleth2.xml 435 482 }}} 436 483 437 484 === Enable Shibboleth on apache virtual hosts === 438 485 486 Now to enable shibboleth login of our install applications we need to modify the relevant configurations files as below. 487 488 First for the Moodle application. 489 {{{ 490 cd /etc/apache2/sites-available 491 nano lms.YOUR-DOMAIN-ssl.conf 492 }}} 493 494 {{{ 439 495 <IfModule mod_ssl.c> 440 496 <VirtualHost *:443> … … 463 519 </VirtualHost> 464 520 </IfModule> 465 521 }}} 522 523 Then change the Wordpress configuration file. 524 525 {{{ 466 526 nano wp.YOUR-DOMAIN-ssl.conf 467 527 }}} 528 529 {{{ 468 530 <IfModule mod_ssl.c> 469 531 <VirtualHost *:443> … … 488 550 </VirtualHost> 489 551 </IfModule> 490 491 14. Enable Shibboleth Apache2 configuration: 492 {{{ 493 552 }}} 553 554 Then enable Shibboleth Apache2 configuration: 555 {{{ 494 556 a2enmod shib 495 557 systemctl reload apache2.service 496 558 }}} 497 559 498 15. We have now set up shibboleth SP for two different entities. They have to be registered with LIAF before using the Federation discovery Service to point different IDP's. 560 == Register both services with LIAF == 561 562 We have now set up shibboleth SP for two different entities. They have to be registered with LIAF before using the Federation discovery Service to point different IDP's. 499 563 500 564 Download the metadata from both applications by going to the following URL's. … … 506 570 Now register them with LIAF separately. 507 571 508 16. Register your SP on LEARN test federation:509 510 572 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. 511 573 512 574 You may have to answer several questions describing your service to the federation provider. 575 576 Once you registered successfully you have enable the Shibboleth support in the application itself. For that Moodle and Wordpress has pluggins to be enabled and configured. 577 578 579 == Enabling Moodle Plugin == 580 581 As Moodle admin, go to the '''Site administration''' >>> '''Plugins''' >>> '''Authentication''' and click on the '''Shibboleth''' enable '''eye'''. Next go to its settings. 582 583 584 Fill in the fields of the form. 585 586 The fields 'Username', 'First name', 'Surname', etc. should contain the name of the environment variables of the Shibboleth attributes that you want to map onto the corresponding Moodle variable. Especially the 'Username' field is of great importance because this attribute is used for the Moodle authentication of Shibboleth users. 587 588 Username: eppn 589 590 Moodle WAYF service: No 591 592 Shibboleth Service Provider logout handler URL: /Shibboleth.sso/Logout 593 594 Data mapping (First name): givenName 595 596 Data mapping (Surname): surname 597 598 Data mapping (Email address): mail 599 600 Update local (Email address): On Creation 601 602 Lock value (Email address): Locked 603 604 605 Click Save. 513 606 514 607 == Enabling Wordpress plugin == … … 544 637 545 638 546 547 639 Click Save. 548 640 549 641 550 == Enabling Moodle Plugin == 551 552 As Moodle admin, go to the '''Site administration''' >>> '''Plugins''' >>> '''Authentication''' and click on the '''Shibboleth''' enable '''eye'''. Next go to its settings. 553 554 555 Fill in the fields of the form. 556 557 The fields 'Username', 'First name', 'Surname', etc. should contain the name of the environment variables of the Shibboleth attributes that you want to map onto the corresponding Moodle variable. Especially the 'Username' field is of great importance because this attribute is used for the Moodle authentication of Shibboleth users. 558 559 Username: eppn 560 561 Moodle WAYF service: No 562 563 Shibboleth Service Provider logout handler URL: /Shibboleth.sso/Logout 564 565 Data mapping (First name): givenName 566 567 Data mapping (Surname): surname 568 569 Data mapping (Email address): mail 570 571 Update local (Email address): On Creation 572 573 Lock value (Email address): Locked 574 575 576 Click Save. 577 578 579 Now using a private browser, try to log in to both systems using your IDP test user. 580 581 582 17. Create the Apache2 configuration for Moodle: 583 584 {{{ 585 nano /etc/apache2/sites-available/moodle.conf 586 }}} 587 588 {{{ 589 <Location /moodle> 590 #ShibRequestSetting applicationId mdl 591 </Location> 592 593 <Directory /var/www/html/moodle/auth/shibboleth/index.php> 594 AuthType shibboleth 595 #ShibRequestSetting applicationId mdl 596 ShibRequireSession On 597 require valid-user 598 </Directory> 599 }}} 600 601 18. Then enable the site and restart the apache and shibboleth daemon to make changes to effect. 602 603 {{{ 604 a2ensite mooodle 605 606 systemctl restart shibd 607 608 systemctl restart apache2 609 }}} 610 611 Now you may browse to https://sp.YOUR-DOMAIN/moodle and select your IDP to log in. 642 Now you may browse to https://sp.YOUR-DOMAIN/ and select your preferred IDP to log in.