-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for saving kerberos sso ticket in session for later reuse
Signed-off-by: Robin Appelman <robin@icewind.nl>
- Loading branch information
1 parent
94c6465
commit 58f9bda
Showing
15 changed files
with
253 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apps/files_external/lib/Lib/Auth/SMB/KerberosSsoSession.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl> | ||
* | ||
* @author Robin Appelman <robin@icewind.nl> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Files_External\Lib\Auth\SMB; | ||
|
||
use Icewind\SMB\KerberosTicket; | ||
use OCA\Files_External\Lib\Auth\AuthMechanism; | ||
use OCA\Files_External\Lib\DefinitionParameter; | ||
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; | ||
use OCP\IL10N; | ||
use OCP\ISession; | ||
|
||
class KerberosSsoSession extends AuthMechanism { | ||
private ISession $session; | ||
|
||
public function __construct(IL10N $l, ISession $session) { | ||
$realm = new DefinitionParameter('default_realm', 'Default realm'); | ||
$realm | ||
->setType(DefinitionParameter::VALUE_TEXT) | ||
->setFlag(DefinitionParameter::FLAG_OPTIONAL) | ||
->setTooltip($l->t('Kerberos default realm, defaults to "WORKGROUP"')); | ||
$this | ||
->setIdentifier('smb::kerberos_sso_session') | ||
->setScheme(self::SCHEME_SMB) | ||
->setText($l->t('Kerberos ticket SSO, save in session')) | ||
->addParameter($realm); | ||
$this->session = $session; | ||
} | ||
|
||
public function getTicket(): KerberosTicket { | ||
try { | ||
$envTicket = KerberosTicket::fromEnv(); | ||
} catch (\Exception $e) { | ||
$envTicket = null; | ||
} | ||
if ($envTicket) { | ||
$this->session->set('kerberos_ticket', base64_encode($envTicket->save())); | ||
return $envTicket; | ||
} | ||
|
||
$savedTicket = $this->session->get('kerberos_ticket'); | ||
if (!$savedTicket) { | ||
throw new InsufficientDataForMeaningfulAnswerException('No kerberos ticket saved'); | ||
} | ||
return KerberosTicket::load(base64_decode($savedTicket)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2023 Robin Appelman <robin@icewind.nl> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Files_External\Lib; | ||
|
||
use Icewind\SMB\KerberosTicket; | ||
use OCP\AppFramework\Http\Response; | ||
use OCP\AppFramework\Middleware; | ||
use OCP\ISession; | ||
|
||
class TicketSaveMiddleware extends Middleware { | ||
private ISession $session; | ||
|
||
public function __construct(ISession $session) { | ||
$this->session = $session; | ||
} | ||
|
||
public function afterController($controller, $methodName, Response $response) { | ||
$ticket = KerberosTicket::fromEnv(); | ||
if ($ticket && $ticket->isValid()) { | ||
$this->session->set('kerberos_ticket', base64_encode($ticket->save())); | ||
} | ||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<VirtualHost *:80> | ||
ServerAdmin webmaster@localhost | ||
DocumentRoot /var/www/html | ||
|
||
<Location /index.php/apps/user_saml/saml/login> | ||
AuthType Kerberos | ||
AuthName "Kerberos authenticated intranet" | ||
KrbAuthRealms DOMAIN.TEST | ||
KrbServiceName HTTP/httpd.domain.test | ||
Krb5Keytab /shared/httpd.keytab | ||
KrbMethodNegotiate On | ||
KrbMethodK5Passwd On | ||
KrbSaveCredentials On | ||
require valid-user | ||
</Location> | ||
|
||
ErrorLog /shared/apache-error.log | ||
CustomLog /shared/apache-access.log combined | ||
</VirtualHost> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
SCRIPT_DIR="${0%/*}" | ||
|
||
DC_IP=$(apps/files_external/tests/sso-setup/start-dc.sh) | ||
apps/files_external/tests/sso-setup/start-apache.sh "$DC_IP" "$PWD" -v "$PWD/$SCRIPT_DIR"/apache-session.conf:/etc/apache2/sites-enabled/000-default.conf | ||
apps/files_external/tests/sso-setup/setup-sso-nc.sh smb::kerberos_sso_session | ||
|
||
apps/files_external/tests/sso-setup/test-sso-smb-session.sh "$DC_IP" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
apps/files_external/tests/sso-setup/test-sso-smb-session.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
DC_IP="$1" | ||
SCRIPT_DIR="${0%/*}" | ||
|
||
echo -n "Checking that we can authenticate using kerberos: " | ||
LOGIN_CONTENT=$("$SCRIPT_DIR/client-cmd.sh" "$DC_IP" curl -i -s -c /shared/cookie -i -s --negotiate -u testuser@DOMAIN.TEST: --delegation always 'http://httpd.domain.test/index.php/apps/user_saml/saml/login?originalUrl=success&XDEBUG_SESSION_START=1') | ||
if [[ "$LOGIN_CONTENT" =~ "Location: success" ]]; then | ||
echo "✔️" | ||
else | ||
echo "❌" | ||
exit 1 | ||
fi | ||
|
||
echo -n "Getting test with session file: " | ||
CONTENT=$("$SCRIPT_DIR/client-cmd.sh" "$DC_IP" curl -s -b /shared/cookie 'http://httpd.domain.test/remote.php/webdav/smb/test.txt?XDEBUG_SESSION_START=1') | ||
CONTENT=$(echo "$CONTENT" | head -n 1 | tr -d '[:space:]') | ||
|
||
if [[ $CONTENT == "testfile" ]]; then | ||
echo "✔️" | ||
else | ||
echo "❌" | ||
exit 1 | ||
fi |
Oops, something went wrong.