Skip to content

Commit 5743474

Browse files
committed
FIX login loop due to unsecured cookie
I think the login loop was due to the browser not being happy with the cookie. Toggling the secure cookie flag seems to fix this. I also forced samesite to none at the time, but I'm not sure if that's necessary. This patch doesn't force samesite to none, cause I'm hoping the automatic samesite none code works fine without us having to do anything. So I added code that'll set the secure cookie flag to true if we're using a SIMPLESAMLPHP_BASEURL that starts with https. Note that SIMPLESAMLPHP_BASEURL config is needed because SimpleSAMLphp errors out if the application baseURL isn't https. Since we have an ingress load balancer in front of the pods handling https, SimpleSAMLphp itself doesn't know we're actually using https without this setting. Sent SimpleSAMLphp logs to stderr so they show up in the kubectl logs. Easiest way for us to see those logs.
1 parent 520d974 commit 5743474

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ Required SP environment variables:
155155
* SIMPLESAMLPHP_ADMIN_PASSWORD - Password for the default admin user.
156156
* SIMPLESAMLPHP_MEMCACHED_SERVER - SimpleSAMLphp's SP cannot use the cookie cache as the wiki side SimpleSAMLphp extension will conflict with it. So we need to use a separate cache. For this purpose, we can just use the same Memcached server that the wiki uses.
157157
* SIMPLESAMLPHP_TRUSTED_DOMAIN - Enter the wiki's domain here so that the SP knows it is safe.
158-
* SIMPLESAMLPHP_BASEURL - Base URL for the SP. The SP needs to share the same domain as the wiki (or you run into cookie domain issues), so the base URL should be a path under the wiki domain.
158+
* SIMPLESAMLPHP_BASEURL - Base URL for the SP (no path). The SP needs to share the same domain as the wiki (or you run into cookie domain issues), so the base URL should just be the wiki domain with an http:// or https:// prefix. This config lets SimpleSAMLphp knows it's running externally on https even if internally the backend server is plain http, such as when behind a load balancer/reverse proxy.
159+
* SIMPLESAMLPHP_BASEURLPATH - Base URL plus the path for the SP.
159160
* SIMPLESAMLPHP_SP_ENTITY_ID - The identifier that the SP uses to identify itself
160161
* SIMPLESAMLPHP_IDP_ENTITY_ID - The target IDP's identifier.
161162
* SIMPLESAMLPHP_IDP_METADATA_URL - URL where we can get the IDP's metadata.

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ services:
4343
SIMPLESAMLPHP_DEV: 1
4444
SIMPLESAMLPHP_MEMCACHED_SERVER: memcached
4545
SIMPLESAMLPHP_TRUSTED_DOMAIN: wiki.docker:8080
46-
SIMPLESAMLPHP_BASEURL: '_saml2/'
46+
SIMPLESAMLPHP_BASEURL: 'http://wiki.docker:8080'
47+
SIMPLESAMLPHP_BASEURLPATH: 'http://wiki.docker:8080/_saml2'
4748
SIMPLESAMLPHP_SP_ENTITY_ID: 'http://wiki.docker:8080/_saml2'
4849
SIMPLESAMLPHP_IDP_ENTITY_ID: 'http://idp.docker:8190'
4950
SIMPLESAMLPHP_IDP_METADATA_URL: 'http://idp.docker:8190/simplesaml/module.php/saml/idp/metadata'

docker/simplesamlphp/sp/config/config.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
exit("Set env var SIMPLESAMLPHP_TRUSTED_DOMAIN to the wiki's domain so SimpleSAMLphp knows it's safe.");
1919
}
2020
if (!isset($_ENV['SIMPLESAMLPHP_BASEURL'])) {
21-
exit("Set env var SIMPLESAMLPHP_BASEURL to the SP's expected base url, e.g.: https://wiki.ubc.ca/_saml2/");
21+
exit("Set env var SIMPLESAMLPHP_BASEURL to the SP's expected base url, e.g.: https://wiki.ubc.ca");
22+
}
23+
if (!isset($_ENV['SIMPLESAMLPHP_BASEURLPATH'])) {
24+
exit("Set env var SIMPLESAMLPHP_BASEURLPATH to the SP's expected path, e.g.: https://wiki.ubc.ca/_saml2/");
2225
}
2326
if (!is_dir('/var/www/simplesamlphp/cert')) {
2427
exit("Missing cert directory, generate key+cert and mount them into /var/www/simplesamlphp/cert");
@@ -55,7 +58,7 @@
5558
* external url, no matter where you come from (direct access or via the
5659
* reverse proxy).
5760
*/
58-
'baseurlpath' => $_ENV['SIMPLESAMLPHP_BASEURL'],
61+
'baseurlpath' => $_ENV['SIMPLESAMLPHP_BASEURLPATH'],
5962

6063
/*
6164
* The 'application' configuration array groups a set configuration options
@@ -76,7 +79,7 @@
7679
* need to compute the right URLs yourself and pass them dynamically
7780
* to SimpleSAMLphp's API.
7881
*/
79-
//'baseURL' => 'https://example.com',
82+
'baseURL' => $_ENV['SIMPLESAMLPHP_BASEURL'],
8083
],
8184

8285
/*
@@ -389,8 +392,8 @@
389392
* must exist and be writable for SimpleSAMLphp. If set to something else, set
390393
* loggingdir above to 'null'.
391394
*/
392-
'logging.level' => SimpleSAML\Logger::NOTICE,
393-
'logging.handler' => 'syslog',
395+
'logging.level' => SimpleSAML\Logger::INFO,
396+
'logging.handler' => 'stderr',
394397

395398
/*
396399
* Specify the format of the logs. Its use varies depending on the log handler used (for instance, you cannot
@@ -656,7 +659,7 @@
656659
*
657660
* If unset, SimpleSAMLphp will try to automatically determine the right value
658661
*/
659-
//'session.cookie.secure' => true,
662+
'session.cookie.secure' => str_starts_with($_ENV['SIMPLESAMLPHP_BASEURL'], 'https') ? true : false,
660663

661664
/*
662665
* Set the SameSite attribute in the cookie.

0 commit comments

Comments
 (0)