catalyst / moodle-auth_saml2

SAML done 100% in Moodle, fast, simple, secure
https://moodle.org/plugins/auth_saml2
71 stars 134 forks source link

We need to set up SSO for our website with this plugin, we tried to remove port from URL and failed with several tries #518

Closed Shanshan-Qu closed 3 years ago

Shanshan-Qu commented 3 years ago

Please provide as many of the following as applies:

What you expected:

The returned URL don't have port 8080.

What we did:

  1. we use this line below to emport port in Dockerfile, but we still got port 8080.

RUN sed -i "s/$port = self::getServerPort();/$port = '8068';/g" /opt/bitnami/moodle/auth/saml2/.extlib/simplesamlphp/lib/SimpleSAML/Utils/HTTP.php

  1. We refered to https://github.com/catalyst/moodle-auth_saml2/issues/298 and do the following change, but it still returns 8080.

/auth/saml2/extlib/simplesamlphp/lib/SimpleSAML/Utils/HTTP.php Line 797 $appurl = ($appcfg instanceof \SimpleSAML_Configuration) ? $appcfg->getString('baseurlpath', '') : ''; instead of $appurl = ($appcfg instanceof \SimpleSAML_Configuration) ? $appcfg->getString('baseURL', '') : '';

Line 807 global $CFG; $hostname = parse_url($CFG->wwwroot, PHP_URL_HOST); $port = ''; Instead of //$hostname = self::getServerHost(); //$port = self::getServerPort();

  1. We add "$CFG->auth_saml2_disco_url = '';" in config.php file, but still got port 8080.

  2. We comment out almost everything related to port in https://github.com/chanakanissanka/moodle-auth_saml2.git, we still got port 8080.

So we want to ask, any idea how to remove port from the URL, otherwise we can't set up SSO.

mbelge commented 3 years ago

Please check my comment in #298

Shanshan-Qu commented 3 years ago

Please check my comment in #298

Hi I have did the change as you mentioned in @298 in my repo https://github.com/Shanshan-Qu/moodle-auth_saml2/blob/master/config/config.php. But it didn't work for us. We still got the port 8080 with URL.

image

Any other suggestion would be appreciate

This is my Dockerfile:

FROM docker.io/bitnami/moodle:3-debian-10

RUN apt update && \
    apt install --no-install-recommends -qqy git && \
    apt -qqy autoremove --purge && \
    apt -qqy clean && \
    rm -rf /var/lib/apt/lists/*

RUN install_packages vim

RUN git clone https://github.com/trampgeek/moodle-qtype_coderunner.git /opt/bitnami/moodle/question/type/coderunner \
    && chown -R daemon /opt/bitnami/moodle/question/type/coderunner

RUN git clone https://github.com/trampgeek/moodle-qbehaviour_adaptive_adapted_for_coderunner.git /opt/bitnami/moodle/question/behaviour/adaptive_adapted_for_coderunner \
    && chown -R daemon /opt/bitnami/moodle/question/behaviour/adaptive_adapted_for_coderunner

RUN git clone https://github.com/Shanshan-Qu/moodle-auth_saml2.git /opt/bitnami/moodle/auth/saml2 \
    && chown -R daemon /opt/bitnami/moodle/auth/saml2

RUN sed -i "s/$port = self::getServerPort();/$port = '';/g"  /opt/bitnami/moodle/auth/saml2/.extlib/simplesamlphp/lib/SimpleSAML/Utils/HTTP.php
mbelge commented 3 years ago

Try to add these lines at the end of the Dockerfile as mention in Bitnami's Moodle container documentation:

ENV APACHE_HTTP_PORT_NUMBER=80
ENV APACHE_HTTPS_PORT_NUMBER=443
EXPOSE 80 443

You should remove the RUN sed line too.

You can add APACHE_*env vars in your Fargate settings too...

danmarsden commented 3 years ago

I see bitnami referenced in there.... make sure you have the real cfg->wwwroot set in your config.php file - bitnami does some dodgy attempt at "guessing" the correct url which isn't supported by Moodle and can cause all sorts of url related problems...

Shanshan-Qu commented 3 years ago

Try to add these lines at the end of the Dockerfile as mention in Bitnami's Moodle container documentation:

ENV APACHE_HTTP_PORT_NUMBER=80
ENV APACHE_HTTPS_PORT_NUMBER=443
EXPOSE 80 443

You should remove the RUN sed line too.

You can add APACHE_*env vars in your Fargate settings too...

Hi, we still have no luck. We still got the port number 8080 behind the URL after we modified Dockerfile.

`FROM docker.io/bitnami/moodle:3-debian-10 ENV http_proxy http://130.216.156.173:3128 ENV https_proxy https://130.216.156.173:3128

RUN apt update && \ apt install --no-install-recommends -qqy git && \ apt -qqy autoremove --purge && \ apt -qqy clean && \ rm -rf /var/lib/apt/lists/*

RUN install_packages vim

RUN git config --global http.proxy http://squid.auckland.ac.nz:3128 RUN git clone https://github.com/trampgeek/moodle-qtype_coderunner.git /opt/bitnami/moodle/question/type/coderunner \ && chown -R daemon /opt/bitnami/moodle/question/type/coderunner

RUN git clone https://github.com/trampgeek/moodle-qbehaviour_adaptive_adapted_for_coderunner.git /opt/bitnami/moodle/question/behaviour/adaptive_adapted_for_coderunner \ && chown -R daemon /opt/bitnami/moodle/question/behaviour/adaptive_adapted_for_coderunner

RUN git clone https://github.com/catalyst/moodle-auth_saml2.git /opt/bitnami/moodle/auth/saml2 \

RUN git clone https://github.com/Shanshan-Qu/moodle-auth_saml2.git /opt/bitnami/moodle/auth/saml2 \

RUN git clone https://github.com/chanakanissanka/moodle-auth_saml2.git /opt/bitnami/moodle/auth/saml2 \

&& chown -R daemon /opt/bitnami/moodle/auth/saml2

ENV APACHE_HTTP_PORT_NUMBER=8080 ENV APACHE_HTTPS_PORT_NUMBER=8443 EXPOSE 8080 8443`

Really don't know what's wrong.

danmarsden commented 3 years ago

@Shanshan-Qu - what is $CFG->wwwroot set to in moodles config.php file? - not the saml2 one.

make sure it's not trying to "guess" the url based on SERVER_HOST like bitnami likes to do. it needs to be the real url eg:

$CFG->wwwroot = 'https://mymoodlesite.com';

not something based on $_SERVER['HTTP_HOST']

Shanshan-Qu commented 3 years ago

@Shanshan-Qu - what is $CFG->wwwroot set to in moodles config.php file? - not the saml2 one.

make sure it's not trying to "guess" the url based on SERVER_HOST like bitnami likes to do. it needs to be the real url eg:

$CFG->wwwroot = 'https://mymoodlesite.com';

not something based on $_SERVER['HTTP_HOST']

Hi,

Thanks for your help. I tried to find config.php under /opt/bitnami/moodle in my container. Can you help me find what is the config.php for moodle.

root@54d70c8c3705:/opt/bitnami/moodle# find . -name config.php* ./mod/quiz/accessrule/seb/config.php ./mod/chat/gui_ajax/theme/course_theme/config.php ./mod/chat/gui_ajax/theme/compact/config.php ./mod/chat/gui_ajax/theme/bubble/config.php ./cache/classes/config.php ./auth/saml2/.extlib/simplesamlphp/config/config.php ./auth/saml2/.extlib/simplesamlphp/config-templates/config.php ./auth/saml2/config/config.php ./theme/boost/config.php ./theme/classic/config.php ./lib/editor/tinymce/plugins/spellchecker/config.php root@54d70c8c3705:/opt/bitnami/moodle# pwd /opt/bitnami/moodle

Thanks shanshan

mbelge commented 3 years ago

Bitnami is supposed to generate the config.php file in /bitnami/moodle directory at first install and indeed will use $_SERVER['HTTP_HOST'], anyway it is quiet strange that you don't have it and that it doesn't complain about it...

Shanshan-Qu commented 3 years ago

Bitnami is supposed to generate the config.php file in /bitnami/moodle directory at first install and indeed will use $_SERVER['HTTP_HOST'], anyway it is quiet strange that you don't have it and that it doesn't complain about it...

yes, there is no config.php under /bitnami/moodle and the folder is empty. So weird, should I create one? Any sample?

root@54d70c8c3705:/bitnami/moodle# ls -la total 8 drwxrwxr-x. 2 daemon root 4096 Jan 19 13:22 . drwxr-xr-x. 4 root root 4096 Jan 19 13:22 ..

Thanks shanshan

chanakanissanka commented 3 years ago

Can we also get confirmation on the moodle image we should be using for this?

danmarsden commented 3 years ago

This is really the wrong place for asking for help installing moodle. but here: https://docs.moodle.org/en/Configuration_file

and: https://docs.moodle.org/en/Installing_Moodle

further help is available in the community forums on moodle.org.

You definitely need to make sure your config.php file is setup correctly and not using an auto discovery of the wwwroot as this causes all sorts of problems and is known to be problematic with authentication plugins and with moodle's scheduled task processes.

Moodle does not recommend the use of pre-packaged Moodle environments like Bitnami - they often make incorrect assumptions about setup, do not follow good practice and also make it hard for you to diagnose stuff like this.

As this appears to be related to a setup/install issue I'd expect we'll need to close this off and refer you to the community forums for further support.