Skip to content

Commit 4d290bc

Browse files
committed
Add EntraID mock IdP
1 parent a87c74b commit 4d290bc

6 files changed

Lines changed: 229 additions & 2 deletions

File tree

‎docker/conf/000-default.conf‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ ServerName ssp.dev.openconext.local
77
CustomLog ${APACHE_LOG_DIR}/access.log combined
88
DirectoryIndex disabled
99
DirectoryIndex index.php index.html
10+
# The standard devssp IdP
1011
Alias /simplesaml /var/www/simplesaml/public/
12+
# The EntraID mock IdP
13+
Alias /entra-mock /var/www/simplesaml/public/
1114
<Directory /var/www/simplesaml/public>
1215
Require all granted
1316
</Directory>

‎docker/html/index.html‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ <h2>Documentation index</h2>
1212
<li><a href="#simplesamlphp">SimpleSAMLphp</a></li>
1313
<li><a href="#test-accounts">Test accounts</a></li>
1414
<li><a href="#attibute-authority">Attibute Authority</a></li>
15+
<li><a href="#entra-mock-idp">EntraID mock IdP</a></li>
1516
<li><a href="#tools">Tools</a></li>
1617
</ul>
1718

@@ -27,6 +28,7 @@ <h2 id="saml-metadata">SAML Metadata</h2>
2728
<li>SAML 2.0 SP Metadata - second-sp: <a href="https://ssp.dev.openconext.local/simplesaml/module.php/saml/sp/metadata.php/second-sp"><code>https://ssp.dev.openconext.local/simplesaml/module.php/saml/sp/metadata.php/second-sp</code></a></li>
2829
<li>SAML 2.0 SP Metadata - third-sp: <a href="https://ssp.dev.openconext.local/simplesaml/module.php/saml/sp/metadata.php/third-sp"><code>https://ssp.dev.openconext.local/simplesaml/module.php/saml/sp/metadata.php/third-sp</code></a></li>
2930
<li>SAML 2.0 SP Metadata - fourth-sp: <a href="https://ssp.dev.openconext.local/simplesaml/module.php/saml/sp/metadata.php/fourth-sp"><code>https://ssp.dev.openconext.local/simplesaml/module.php/saml/sp/metadata.php/fourth-sp</code></a></li>
31+
<li>SAML 2.0 IdP Metadata - EntraID mock: <a href="https://ssp.dev.openconext.local/entra-mock/saml2/idp/metadata.php"><code>https://ssp.dev.openconext.local/entra-mock/saml2/idp/metadata.php</code></a> (see <a href="#entra-mock-idp">EntraID mock IdP</a>)</li>
3032
</ul>
3133

3234
<h2 id="simplesamlphp">SimpleSAMLphp</h2>
@@ -152,6 +154,15 @@ <h2 id="attibute-authority">Attibute Authority</h2>
152154
The attributes that you configure in the AA are persisted on disk in /var/www/simplesaml/data/aa.json in the container.
153155
</p>
154156

157+
<h2 id="entra-mock-idp">EntraID mock IdP</h2>
158+
<p>
159+
A second IdP, intended for testing Stepup-AzureMFA GSSP. Authenticate with the same username and password as the main IdP.
160+
Emulate cancelling an authentication by authentication with username <code>cancel</code> and password <code>cancel</code>.
161+
</p>
162+
<ul>
163+
<li>EntityID / IdP metadata: <a href="https://ssp.dev.openconext.local/entra-mock/saml2/idp/metadata.php"><code>https://ssp.dev.openconext.local/entra-mock/saml2/idp/metadata.php</code></a></li>
164+
<li>SingleSignOnService endpoint: <code>https://ssp.dev.openconext.local/entra-mock/module.php/saml/idp/singleSignOnService</code></li>
165+
</ul>
155166

156167
<h2 id="tools">Tools</h2>
157168

‎docker/sspconf/authsources.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,29 @@
192192
account_gen($config, "{$user}-e", $email, 'Institution-e.example.com', $slugs);
193193
account_gen($config, "{$user}-f", $email, 'Institution-f.example.com', $slugs);
194194
}
195+
196+
////////////////////////////////////////////////////////////////////////////////
197+
// Authentication source for the EntraID mock IdP (see saml20-idp-hosted.php).
198+
//
199+
// It uses the same accounts as 'example-userpass' (generated above), so a test account
200+
// like "jane-a1" can also authenticate at the mock IdP with the same username, using the
201+
// email address that was generated for that account.
202+
//
203+
// The authsource has its own id ('entra-mock-userpass'), so a session at the main IdP
204+
// ('example-userpass') is never reused at the mock IdP: no SSO between the two IdPs.
205+
//
206+
// The special account "cancel" simulates a user cancelling the authentication at the
207+
// (mock) EntraID: the authproc of the mock IdP returns a SAML error response
208+
// (Responder / AuthnFailed) to the SP for it.
209+
210+
// Copy the accounts, but remove the 'exampleauth:UserPass' class entry (numeric key 0)
211+
$entra_mock_accounts = $config['example-userpass'];
212+
unset($entra_mock_accounts[0]);
213+
$entra_mock_accounts['cancel:cancel'] = array(
214+
'NameID' => 'urn:collab:person:entra-mock.dev.openconext.local:cancel',
215+
'uid' => array('cancel'),
216+
'mail' => 'cancel@dev.openconext.local',
217+
'eduPersonPrincipalName' => 'cancel@dev.openconext.local',
218+
'schacHomeOrganization' => 'dev.openconext.local',
219+
);
220+
$config['entra-mock-userpass'] = array_merge(array('exampleauth:UserPass'), $entra_mock_accounts);

‎docker/sspconf/config.php‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66

77
$httpUtils = new \SimpleSAML\Utils\HTTP();
88

9+
/*
10+
* The EntraID mock IdP (see metadata/saml20-idp-hosted.php) is served under a second
11+
* base path (/entra-mock/) on the same host (see the Alias in conf/000-default.conf).
12+
* Select the base URL path based on the requested URL, so that SimpleSAMLphp generates
13+
* correct URLs for both base paths. SimpleSAMLphp picks the hosted IdP for a request
14+
* based on this host/path combination (the 'host' key in saml20-idp-hosted.php).
15+
*/
16+
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
17+
if ($requestUri === '/entra-mock' || str_starts_with($requestUri, '/entra-mock/')) {
18+
$baseurlpath = 'https://ssp.dev.openconext.local/entra-mock/';
19+
} else {
20+
$baseurlpath = 'https://ssp.dev.openconext.local/simplesaml/';
21+
}
22+
923
$config = [
1024

1125
/*******************************
@@ -32,7 +46,9 @@
3246
* reverse proxy).
3347
*/
3448
//'baseurlpath' => 'simplesaml/',
35-
'baseurlpath' => 'https://ssp.dev.openconext.local/simplesaml/',
49+
// See the $baseurlpath computation above: /entra-mock/ for the EntraID mock IdP,
50+
// /simplesaml/ for everything else.
51+
'baseurlpath' => $baseurlpath,
3652

3753
/*
3854
* The 'application' configuration array groups a set configuration options

‎docker/sspconf/metadata/saml20-idp-hosted.php‎

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,145 @@
227227

228228
);
229229

230+
231+
////////////////////////////////////////////////////////////////////////////////
232+
// The "EntraID mock" IdP.
233+
//
234+
// This second hosted IdP emulates an EntraID (AzureAD) IdP for the Stepup-AzureMFA GSSP
235+
// It is served under a second base path (/entra-mock/) under the same hostname.
236+
//
237+
// Properties:
238+
// - No SSO: the IdP uses its own authsource ('entra-mock-userpass', see authsources.php),
239+
// and the AzureMFA SP is configured with ForceAuthn in saml20-sp-remote.php, so every
240+
// AuthnRequest at this IdP results in its login page.
241+
// - No Subject handling is required: EntraID-style AuthnRequests (institutions with
242+
// is_azure_ad: true) carry no Subject at all and SimpleSAMLphp does not need one.
243+
// ADFS-style AuthnRequests that do carry a Subject are simply ignored.
244+
// - AuthnRequests from the AzureMFA SP are signed; a valid signature is required and is
245+
// validated against the certificate configured for that SP in saml20-sp-remote.php.
246+
// - Assertions are signed with entra-mock-idp.key; AzureMFA validates them against
247+
// entra-mock-idp.crt. These key/cert files are not part of this repository, they are
248+
// provided in the cert dir (mounted from OpenConext-devconf/stepup/ssp in devconf).
249+
//
250+
// The institutions.yaml of the AzureMFA service in OpenConext-devconf should point to:
251+
// entity_id: https://ssp.dev.openconext.local/entra-mock/saml2/idp/metadata.php
252+
// sso_location: https://ssp.dev.openconext.local/entra-mock/module.php/saml/idp/singleSignOnService
253+
// certificates: [ entra-mock-idp.crt ]
254+
// is_azure_ad: true
255+
256+
$entra_mock_authproc = array(
257+
258+
// Generate an unspecified NameID for use by this IdP, using the value of the "NameID"
259+
// attribute from the authsource as the NameID in the Subject of the SAML Assertion
260+
1 => array(
261+
'class' => 'saml:AttributeNameID',
262+
'attribute' => 'NameID',
263+
'identifyingAttribute' => 'NameID',
264+
'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
265+
266+
// Don't add NameQualifier and SPNameQualifier attributes to the generated NameID
267+
'NameQualifier' => FALSE,
268+
'SPNameQualifier' => FALSE,
269+
),
270+
271+
// Simulate a user cancelling the authentication at the (mock) EntraID (the "cancel"
272+
// account): send a SAML error response (Responder / AuthnFailed) to the SP (AzureMFA),
273+
// using the same responder SimpleSAMLphp uses for authentication errors. (A plain
274+
// "throw" would not work here: with ForceAuthn the authproc runs after the login
275+
// completed, where an exception would only result in an error page, not a SAML response.)
276+
2 => array(
277+
'class' => 'core:PHP',
278+
'code' => '
279+
if (isset($attributes["uid"][0]) && $attributes["uid"][0] === "cancel") {
280+
\SimpleSAML\Module\saml\IdP\SAML2::handleAuthError(
281+
new \SimpleSAML\Module\saml\Error(
282+
\SAML2\Constants::STATUS_RESPONDER,
283+
\SAML2\Constants::STATUS_AUTHN_FAILED,
284+
"Authentication cancelled by user"
285+
),
286+
$state
287+
);
288+
}
289+
',
290+
),
291+
292+
// Remove the NameID attribute from the attributes, so that it is not released as an
293+
// attribute (it would be renamed to internal-collabPersonId by the AttributeMap below)
294+
5 => array(
295+
'class' => 'core:AttributeAlter',
296+
'subject' => 'NameID',
297+
'pattern' => '/.*/',
298+
'%remove',
299+
),
300+
301+
// AzureMFA validates that the mail attribute in the response contains the email
302+
// address the user registered with. Use the email address generated for the account
303+
// (eduPersonPrincipalName, i.e. uid@schacHomeOrganization), e.g. jane-a1@institution-a.example.com
304+
7 => array(
305+
'class' => 'core:PHP',
306+
'code' => '
307+
if (isset($attributes["eduPersonPrincipalName"][0])) {
308+
$attributes["mail"] = array($attributes["eduPersonPrincipalName"][0]);
309+
}
310+
',
311+
),
312+
313+
// Convert "short" attribute names (uid, mail, ...) to their long urn:mace... equivalent.
314+
// The map is defined in sspattributemap/Openconext_short_to_urn.php
315+
10 => array(
316+
'class' => 'core:AttributeMap',
317+
'Openconext_short_to_urn'
318+
),
319+
320+
// EntraID marks an MFA authentication with this attribute; AzureMFA requires it in the
321+
// response for institutions with is_azure_ad: true
322+
20 => array(
323+
'class' => 'core:AttributeAdd',
324+
'http://schemas.microsoft.com/claims/authnmethodsreferences' => array('http://schemas.microsoft.com/claims/multipleauthn'),
325+
),
326+
);
327+
328+
$metadata['https://ssp.dev.openconext.local/entra-mock/saml2/idp/metadata.php'] = array(
329+
// Select this IdP for requests under the /entra-mock/ base path (host + path)
330+
'host' => 'ssp.dev.openconext.local/entra-mock',
331+
332+
// Set the endpoints explicitly: 'host' contains a path, so the auto-generated
333+
// endpoints would end up with the path twice
334+
'SingleSignOnService' => 'https://ssp.dev.openconext.local/entra-mock/module.php/saml/idp/singleSignOnService',
335+
'SingleSignOnServiceBinding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
336+
'SingleLogoutService' => 'https://ssp.dev.openconext.local/entra-mock/module.php/saml/idp/singleLogout',
337+
'SingleLogoutServiceBinding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
338+
339+
'signature.algorithm' => 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
340+
341+
/* X.509 key and certificate of the mock IdP. Relative to the cert directory.
342+
* These files are not part of this repository; they are provided in the cert dir
343+
* (mounted from OpenConext-devconf/stepup/ssp in the devconf setup).
344+
*/
345+
'privatekey' => 'entra-mock-idp.key',
346+
'certificate' => 'entra-mock-idp.crt',
347+
348+
// Dedicated authsource: no SSO with the main IdP (see authsources.php)
349+
'auth' => 'entra-mock-userpass',
350+
351+
// The AzureMFA SP signs its AuthnRequests; require and validate the signature
352+
'redirect.validate' => TRUE,
353+
'validate.authnrequest' => TRUE,
354+
355+
// Sign the assertion (AzureMFA validates the assertion signature), not the response
356+
'saml20.sign.response' => FALSE,
357+
'saml20.sign.assertion' => TRUE,
358+
359+
// No artifact binding support
360+
'saml20.sendartifact' => FALSE,
361+
362+
'attributes.NameFormat' => 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri',
363+
364+
// Use an unspecified NameID. The NameID is generated in the authproc above.
365+
// This is the NameID that will be put in the Subject of the SAML Assertion
366+
'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
367+
368+
'authproc' => array_merge($entra_mock_authproc, $attribute_authority_authproc),
369+
370+
);
371+

‎docker/sspconf/metadata/saml20-sp-remote.php‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,34 @@
5858
'index' => 0,
5959
),
6060
),
61-
'certificate' => 'gateway_sp.crt'
61+
'certificate' => 'gateway_sp.crt'
62+
);
63+
64+
65+
///////////////////////////////////////////////////////////////////////////////////
66+
// The Stepup-AzureMFA service in its SP role towards the EntraID mock IdP hosted by
67+
// this instance (https://ssp.dev.openconext.local/entra-mock/..., see saml20-idp-hosted.php).
68+
// This allows the (production image of the) AzureMFA GSSP to authenticate users at the
69+
// mock EntraID IdP.
70+
//
71+
// - The AuthnRequests sent by AzureMFA are signed with its SP key; the signature is
72+
// required at the mock IdP (validate.authnrequest) and validated against this certificate.
73+
// The certificate file is not part of this repository; it is provided in the cert dir
74+
// (mounted from OpenConext-devconf/stepup/azuremfa in the devconf setup).
75+
// - ForceAuthn is set so that no SSO session is ever reused for AuthnRequests from
76+
// AzureMFA at the mock IdP: every AuthnRequest results in the login page of the mock IdP.
77+
78+
$metadata['https://azuremfa.dev.openconext.local/saml/metadata'] = array(
79+
'entityid' => 'https://azuremfa.dev.openconext.local/saml/metadata',
80+
'AssertionConsumerService' =>
81+
array (
82+
0 =>
83+
array (
84+
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
85+
'Location' => 'https://azuremfa.dev.openconext.local/saml/acs',
86+
'index' => 0,
87+
),
88+
),
89+
'certificate' => 'azuremfa_idp.crt',
90+
'ForceAuthn' => TRUE,
6291
);

0 commit comments

Comments
 (0)