How does one migrate a Moodle site together with Shibboleth?

How does one migrate a Moodle site together with Shibboleth?

by Visvanath Ratnaweera -
Number of replies: 4
Picture of Particularly helpful Moodlers Picture of Translators
I am slowly getting convinced that Shibboleth is world-class security, from the difficulties I am having trying to migrate a Moodle site together with its Shibboleth authentication.
sad

History:
- The old site ran perfectly with Shibboleth authentication provided by SWITCHaai https://www.switch.ch/en/services/aai/.

- The new site runs under the same URL, in a different server (different IP). Both sites are HTTPS, with two different SSL certificates from two different vendors - issued for the identical FQDN.

Migration:
- A Moodle site-backup from the old server was restored in the new one, following https://docs.moodle.org/27/en/Moodle_migration.

- /etc/shibboleth/sp-key.pem, sp-cert.pm and attribute-map.xml was copied over from the old to the new site (and server rebooted).

From my understanding of the documentation that should be enough. (I haven't manually edited the attribute-map.xml, for example.)

Their permissions:
-rw------- 1 _shibd _shibd 1679 Nov 26 16:39 sp-key.pem
-rw-r--r-- 1 _shibd _shibd 1172 Nov 26 16:39 sp-cert.pem
-rw------- 1 _shibd _shibd 14891 Dec 3 14:52 attribute-map.xml

Present behavior:
- From Login, choose an affiliated organization, enter the credentials.

- Get a confirmation screen like (annonymized)
The Institution that runs the Moodle
Name of the Moodle site
Requests data
Nachname [user's name]
Vorname [user's first name]
E-Mail [user's e-mail]

- > Accept gives the error:
Shibboleth authentication doesn't seem to be set up correctly because no Shibboleth environment variables are present for this page. Please consult the README for further instructions on how to set up Shibboleth authentication or contact the webmaster of this Moodle installation.

More information about this error
Debug info:
Error code: shib_not_set_up_error
Stack trace:
line 463 of /lib/setuplib.php: moodle_exception thrown
line 93 of /auth/shibboleth/index.php: call to print_error()

- Now I visit https://example.com/Shibboleth.sso/Session and get
Miscellaneous
Session Expiration (barring inactivity): 476 minute(s)
Client Address: [my.ip]
SSO Protocol: urn:oasis:names:tc:SAML:2.0:protocol
Identity Provider: https://eduid.ch/idp/shibboleth
Authentication Time: 2015-12-06T20:04:53.308Z
Authentication Context Class: urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
Authentication Context Decl: (none)

Attributes
givenName: 1 value(s)
mail: 1 value(s)
surname: 1 value(s)

Diagnosis by the experts at SWITCHaai:
- The SAML session with the Shibboleth SP is successful and the SP has redirected the login to the Moodle plug-in, which _should_ initiate a Moodle session but went wrong. Apparantly the Moodle plug-in does not find the necessary environment variables. Apparently an error from the Moodle side, possibly a configuration change I need to do. (I don't understand everything, just reporting.)

Can somebody tell me what I need to do in addition to what I've already done?

Moodle version is 2.7. Both servers Debian 7 updated to the latest packages from the official repos.
Average of ratings: -
In reply to Visvanath Ratnaweera

Re: How does one migrate a Moodle site together with Shibboleth?

by Ken Task -
Picture of Particularly helpful Moodlers

First, as you know ... don't run debian but ... it's a linux and shib is available on all.   Also don't run shib!  But, do know that running https requires .key, .pem, and .crt files, etc.  that are generated for the server itself ... and from the server that will be using them.  Not sure that having the same FQDN is the only requirement ... would think the .key files generated and used in creation of .pem are to be unique to the hardware as well.

/etc/shibboleth/sp-key.pem, sp-cert.pm and attribute-map.xml was copied over might be biting ya!

http://manpages.ubuntu.com/manpages/raring/man8/shib-keygen.8.html

'spirit of sharing', Ken


In reply to Visvanath Ratnaweera

Re: How does one migrate a Moodle site together with Shibboleth?

by Ken Task -
Picture of Particularly helpful Moodlers

Sorry, my last feeble attempt was no help at all ... was it! :\

Been looking at the readme to which the error suggested ... in /moodlecode/auth/shibboleth/

You've not mentioned this ...

Moodle Configuration with Dual login
-------------------------------------------------------------------------------
1. Protect the directory moodle/auth/shibboleth/index.php with Shibboleth.
   The page index.php in that directory actually logs in a Shibboleth user.
   For Apache you have to define a rule like the following in the Apache config:

--
<Directory  /path/to/moodle/auth/shibboleth/index.php>
        AuthType shibboleth
        ShibRequireSession On
        require valid-user
</Directory>
--

   To restrict access to Moodle, replace the access rule 'require valid-user'
   with something that fits your needs, e.g. 'require affiliation student'.

   For IIS you have protect the auth/shibboleth directory directly in the
   RequestMap of the Shibboleth configuration file (shibboleth.xml or
   shibboleth2.xml).

--
<Path name="moodle" requireSession="false" >
   <Path name="auth/shibboleth/index.php" requireSession="true" >
      <AccessControl>
          ...
      </AccessControl>
   </Path>
</Path>
--

   Also see:
   https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPRequestMapper and
   https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPAccessControl

and don't know this will help or not ... but it might ...

https://moodle.org/mod/forum/discuss.php?d=218016

'spirit of sharing', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: How does one migrate a Moodle site together with Shibboleth?

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Ken, you are meticulous! It was exactly the missing section in Apache config:
--
<Directory /path/to/moodle/auth/shibboleth/index.php>
AuthType shibboleth
ShibRequireSession On
require valid-user
</Directory>
--

I saw it in the README. But the line 'Protect the directory moodle/auth/shibboleth/index.php with Shibboleth" confused me. For one there is also a Unix user called _shibd and then the above is path in not a directory!

Whatever, it is working now. Many thanks!
In reply to Visvanath Ratnaweera

Re: How does one migrate a Moodle site together with Shibboleth?

by Ken Task -
Picture of Particularly helpful Moodlers

Welcome!  Really a 'lucky guess'! smile

'spirit of sharing', Ken